Working with seconds, what am I missing?

Kay C Lan lan.kc.macmail at gmail.com
Mon Apr 23 20:39:09 EDT 2012


On Mon, Apr 23, 2012 at 5:05 PM, Andrew Henshaw <henshaw at me.com> wrote:

>
> Its odd as I had expected  livecode to convert the seconds to and from a
> date in the same way as all the online tools that convert unix time based
> on seconds since the epoch,  but apparently it does depend on which format
> you convert to as to what time it is.
>
> I think you may have just needed to do a little more checking.

I went to this website:

http://www.epochconverter.com/

and input your number: 1335049200

and it came up with, as you say: 21 Apr 2012 23:00:00 GMT, BUT it also came
up with 22 Apr 2012 07 19:00:00 which is the time corrected for the time
zone I'm currently in.

I then test in Terminal on OS X with:

$ date -r 1335049200

and the it came back: Sun 22 Apr 2012 19:00:00 EDT - a local time, NOT a
GMT time.

I then tested using the -u option:

$ date -ur 1335049200

and it came back: Sat 21 Apr 2012 23:00:00 UTC - as per your online
converters.

All you are seeing when you use an online converter is that they've
probably set the -u option so the output is UTC (GMT) rather than the
default time zone, which would have been where ever the server is located.

What you don't appreciate is that this is because they haven't gone to the
trouble, as www.epochconverter.com obviously did, to write the extra code
to search your computer to find what time zone you're in to output the
conversion into something more usable to you. The helpful people at RunRev
have done that for you with LiveCode.

Terminal and LiveCode (which I'm guessing is simply using OS X underlying
Unix for the answer) base all their 'seconds' on the same Epoch as the
online Unix converters you have used. The only difference is, Terminal and
LiveCode KNOW what time zone your computer is in so give you the answer
relative to your time zone. This is actually what you want for ALL date and
time manipulation presented to a user.

Where dates and time become tricky is when you are trying to compare them
between different users located around the world.

My general rule of thumb is:

If you are only interested in avoiding confusion surround date formats (is
2/4/12 2nd Apr or Feb 4th) then use dateItems.
If time is involved, the start with internet date (as it includes the UTC
(GMT) offset) and then convert to dateItems and apply appropriate UTC
conversions.

If you haven't gathered, I love LiveCode and dateItems. It makes it so easy
to figure out what date and time it was 83 days 98 hours 76 min ago in
India, which has an offset of UTC + 5hrs 30 min. Actually it's not that
hard with seconds, but dateItems just gel with my simple mind.

HTH



More information about the use-livecode mailing list