date_Construct8601 (was numberformat)

David Bovill david at openpartnership.net
Wed Aug 27 10:02:59 EDT 2008


Yeah - thanks Sarah - I've just been learning "format" and you beat me to it
:) There are a few other versions as some implementations don't use the full
standard - so I'll add those then post the handler. Its going to be much
easier to add them now just by using different format strings. I've stuck to
using standard Rev commands for decoding - as I just cant get binarydecode
to work :)

2008/8/27 Andre Garzia <andre at andregarzia.com>

> Sarah and David,
>
> thank you very much, I was in need of that! :-D
>
> damn wordpress likes iso8601....
>
> Cheers
> andre
>
> On Tue, Aug 26, 2008 at 9:16 PM, Sarah Reichelt
> <sarah.reichelt at gmail.com> wrote:
> > Hi David,
> >
> > Here is my re-working of your function:
> >
> > function date_Construct8601 someDate, someTime, extended, isUTC
> >    if someTime is empty then
> >        -- returning date only
> >        convert someDate to dateItems
> >        put item 1 of someDate into y
> >        put item 2 of someDate into mons
> >        put item 3 of someDate into d
> >
> >        convert someDate to internet date
> >        if extended is true then
> >            -- 1981-04-05
> >            put "%4d-%02d-%02d" into baseString
> >        else
> >            -- 19810405
> >            put "%4d%02d%02d" into baseString
> >        end if
> >
> >        put format(baseString, y, mons, d) into fDate
> >        return fDate
> >
> >    else
> >        -- returning date & time as either local or UTC
> >        convert (someDate && someTime) to internet date
> >        put it into someDate
> >
> >        put word -1 of someDate into utcOffset
> >
> >        convert someDate to dateItems
> >        put item 1 of someDate into y
> >        put item 2 of someDate into mons
> >        put 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 isUTC is true then
> >            -- UTC specific code
> >            put char 2 to 3 of utcOffset into extraHours
> >            put char 4 to 5 of utcOffset into extraMin
> >
> >            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
> >
> >            if extended is true then
> >                -- 1981-04-05T14:30:30-05:00
> >                put "%4d-%02d-%02dT%02d:%02d:%02dZ" into baseString
> >            else
> >                -- 19810405T14:30:30-05 00
> >                put "%4d%02d%02dT%02d:%02d:%02dZ" into baseString
> >            end if
> >            put format(baseString, y, mons, d, h, mins, s) into fDate
> >            return fDate
> >
> >        else
> >            -- Local specific code
> >            if extended is true then
> >                -- 1981-04-05T14:30:30-05:00
> >                put "%4d-%02d-%02dT%02d:%02d:%02d %04s" into baseString
> >            else
> >                -- 19810405T14:30:30-05 00
> >                put "%4d%02d%02dT%02d:%02d:%02d%04s" into baseString
> >            end if
> >
> >            put format(baseString, y, mons, d, h, mins, s, utcOffset) into
> fDate
> >            return fDate
> >        end if
> >    end if
> > end date_Construct8601
> >
> >
> > - instead of using your padding function and numberFormat, I just used
> > format to supply the leading zeroes as required.
> > - your UTC calculation was going the wrong way. I am in +1000 time
> > zone, and to get to UTC, I have to subtract 10 from the local hours,
> > not add.
> > - there was some code duplication between the UTC and local date/time
> > sections, so I re-organised the structure of the if-else-end if"s to
> > avoid this.
> >
> > Thanks for providing an interesting challenge :-)
> >
> > Cheers,
> > Sarah
> > _______________________________________________
> > use-revolution mailing list
> > use-revolution at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-revolution
> >
>
>
>
> --
> http://www.andregarzia.com All We Do Is Code.
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list