date_Construct8601 (was numberformat)
David Bovill
david at openpartnership.net
Tue Aug 26 16:40:04 EDT 2008
FYI- her is the function so far:
function date_Construct8601 someDate, someTime, extended, isUTC
if someTime is empty then
convert someDate to dateItems
put item 1 of someDate into y
put date_PadTwoZeros(item 2 of someDate) into mons
put date_PadTwoZeros(item 3 of someDate) into d
convert someDate to internet date
if extended is true then
-- 1981-04-05
put "%4s-%2s-%2s" into baseString
else
-- 19810405
put "%4s%2s%2s" into baseString
end if
set the numberformat to "00.######"
put format(baseString, y, mons, d) into fDate
set the numberformat to "0.######"
return fDate
else if isUTC is true then
convert (someDate && someTime) to internet date
put it into someDate
put word -1 of someDate into utcOffset
put char 2 to 3 of utcOffset into extraHours
put char 4 to 5 of utcOffset into extraMin
convert someDate to dateItems
put item 1 of someDate into y
put date_PadTwoZeros(item 2 of someDate) into mons
put date_PadTwoZeros(item 3 of someDate) into d
put item 4 of someDate into h
put item 5 of someDate into mins
put item 6 of someDate into s
if char 1 of utcOffset is "+" then
add extraHours to h
add extraMin to m
else
subtract extraHours from h
subtract extraMin from m
end if
put date_PadTwoZeros(h) into h
put date_PadTwoZeros(mins) into mins
put date_PadTwoZeros(s) into s
if extended is true then
-- 1981-04-05T14:30:30-05:00
put "%4s-%2s-%2sT%2s:%2s:%2sZ" into baseString
else
-- 19810405T14:30:30-05 00
put "%4s%2s%2sT%2s:%2s:%2sZ" into baseString
end if
put format(baseString, y, mons, d, h, mins, s) into fDate
return fDate
else
convert (someDate && someTime) to internet date
put it into someDate
put word -1 of someDate into z
convert someDate to dateItems
put item 1 of someDate into y
put date_PadTwoZeros(item 2 of someDate) into mons
put date_PadTwoZeros(item 3 of someDate) into d
put date_PadTwoZeros(item 4 of someDate) into h
put date_PadTwoZeros(item 5 of someDate) into mins
put date_PadTwoZeros(item 6 of someDate) into s
if extended is true then
-- 1981-04-05T14:30:30-05:00
put "%4s-%2s-%2sT%2s:%2s:%2s %4s" into baseString
else
-- 19810405T14:30:30-05 00
put "%4s%2s%2sT%2s:%2s:%2s%4s" into baseString
end if
set the numberformat to "00.######"
put format(baseString, y, mons, d, h, mins, s, z) into fDate
set the numberformat to "0.######"
return fDate
end if
end date_Construct8601
More information about the use-livecode
mailing list