Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Difficult on use time

by kennethk (Abbot)
on Apr 07, 2012 at 14:26 UTC ( #963920=note: print w/replies, xml ) Need Help??

in reply to Difficult on use time

In general, when I need to do any sort of interaction with dates and times, and especially if I need to do math, I use the DateTime module. It handles all this in a clean, consistent way.

If you are disinclined to go outside built-ins, I would suggest using GMT for all your times rather than mixing. You can then either log in GMT, or do the conversion on output. Playing games with differing internal representations just creates unnecessary headaches in my experience. In this case, just consistently calling gmtime will "force Perl to PERMANENTLY consider I am working in GMT+0 location", rather than creating a strange hack that will confuse you next time you have to work with this module and may possibly cause messy action at a distance.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Difficult on use time
by exilepanda (Pilgrim) on Apr 07, 2012 at 17:05 UTC
    That's right, if I all use gmtime or localtime, I can have a constant base, ( but believe this is not same as working a system in a GMT+0 TZ ). And for me, both has its drawback. If all gmtime, I might not reflecting to the real time to my local system; if I hard code the conversion, I lost the portability if the system moves to other time zone. And if all localtime, it sometimes surprised me like if I use Date_to_Time in Date::Calc (this returns me a gmt+0 seconds)...

    DateTime is pretty good enough for conditions, however it complexity increased the interpret time and maintenance effort. Though I really use them them in some real difficult calculation. But for something just like :

    doSomething() if ( time == $triggerSecond );
    I really don't want to call a module

    However, thank you for your reminder! I think I should consider to use DateTime for now, which could be a nice tools I've forgotten when I am dealing with this package.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963920]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-05-20 20:37 GMT
Find Nodes?
    Voting Booth?