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

DateTime Daylight savings question

by jsilva_im (Novice)
on Sep 19, 2008 at 18:33 UTC ( [id://712577]=perlquestion: print w/replies, xml ) Need Help??

jsilva_im has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently having issues with DateTime timezones on a win2k box. Even though I select my current timezone, it does not seem to take into account DST. Shouldn't DateTime::TimeZone take this into account? I have 0.80, so I think it is uptodate (with Olson db).
use DateTime; use DateTime::TimeZone; $dt = DateTime->now; # same as ( epoch => time() ) $dt->set_time_zone( 'America/New_York' ); print $dt->hms;

Replies are listed 'Best First'.
Re: DateTime Daylight savings question
by ikegami (Patriarch) on Sep 19, 2008 at 21:11 UTC
    use DateTime; use DateTime::TimeZone; my $dt = DateTime->now; # same as ( epoch => time() ) print( $dt->hms, "\n" ); $dt->set_time_zone( 'America/New_York' ); print( $dt->hms, "\n" ); $dt->set_time_zone( 'EST' ); print( $dt->hms, "\n" );
    21:10:32 17:10:32 16:10:32

    Works for me. WinXP, ActivePerl 5.8.8, DateTime 0.36, DateTime::TimeZone 0.63

      Interesting...Here are my results that I ran at: 15:22 PM EDT
      22:22:34 18:22:34 17:22:34
      Seems to work for me. My question might be because of a misunderstanding with TimeZone, but why is 'EST' and America/New_York any different? Isn't 'EST' incorrect anyway since we are currently still in DST? Thanks for all of your suggestions everyone! Specially on a Friday!

        Here are my results that I ran at: 15:22 PM EDT

        Since you replied at 17:19 PM EDT,
        I think you meant to say 17:22 PM EDT, and
        I think the time was really 17:18 PM EDT or earlier.

        Seems to work for me.

        Uh no, all three times are off by one hour (and four minutes).
        Your system's clock is wrong,
        your system's time settings are wrong, or
        your system's time zone info is wrong.

        why is 'EST' and America/New_York any different?

        America/New_York is currently equivalent to EDT.
        In a couple of months, America/New_York will be equivalent to EST.

        Isn't 'EST' incorrect anyway since we are currently still in DST?

        Not incorrect. It's simply a different time zone. There would be problem if America/New_York and EST returned the same time for the current value of now.

Re: DateTime Daylight savings question
by bart (Canon) on Sep 19, 2008 at 21:59 UTC
    I just finished a debug session, single stepping through your code. I can see no system dependencies, time zone calculations all happen on the Perl level, based on a thing called the Olson Database. So the result cannot be system dependent.

    The only thing I can imagine is happening, is that your initial $dt = DateTime->now value is not the same as it is for us, it appears to me (though I'm not absolutely sure) its value can depend on time zone information in the Registry, or in the TZ environment variable. Perhaps you'd better print it out, too, before you set the time zone.

    Likely ikegami is right, and your computer's system clock isn't set correctly.

      ikegami and you are both right! It came to be a rather simple fix, but interesting still.

      Here's what happened. When the last DST patch came along from Windows they did not have one for Win2k (non-paying that is). There was a 3rd party fix, that for whatever reason did not work, after I installed some security updates. I manually disabled the DST setting in my Windows Time, and simply dropped the time down an hour. Hence, the "is Daylight Savings" flag being zero.
      When I turned on the "Daylight Savings" mode checkbox, my system jumps ahead an hour.
      use DateTime; use DateTime::TimeZone; my $dt = DateTime->now; # same as ( epoch => time() ) print( $dt->hms, "\n" ); $dt->set_time_zone( 'America/New_York' ); print( $dt->hms, "\n" ); $dt->set_time_zone( 'EST' ); print( $dt->hms, "\n" ); #Results (With the DST enabled AND disabled..Doesnt matter). 01:10:49 21:10:49 20:10:49
      This is more of a system issue at this point and not a Perl problem, but if anyone has any advice I would be appreciative.
        Download these three files and double-click the .cmd file. That's the patch we used at the office to fix Win2k systems.
        (I was not logged in, I apologize for that last comment" broomduster's code for the timezone was interesting
        When the DST checkbox in Windows was checked it yielded a "1". Don't know if that helps or not.
Re: DateTime Daylight savings question
by broomduster (Priest) on Sep 19, 2008 at 19:45 UTC
    Works fine here on Mac OS X 10.4, NetBSD 3.1 and 4.0, and FreeBSD 6.2. The only thing I can think of is that the date is wrong, so maybe check that the date returned by DateTime->now is correct (print $dt->ymd, "\n";).
      I get the proper date with that, but the time is still off.
      $dt = DateTime->now; # same as ( epoch => time() ) $dt->set_time_zone( 'America/New_York' ); print "\n Now:".$dt->hms; print "\n YMD: ".$dt->ymd; #returns: # Now:17:15:48 # YMD: 2008-09-19
        Curious... That time isn't even Standard Time for America/New_York at the moment. I have PM display times in my local time zone (currently EDT, same as America/New_York at the moment). That tells me that your reply was posted at 2008-09-19 16:10:07 EDT, which would be 15:10:07 EST, yet you show 17:15:48 from DateTime->now. That's about an hour off, but it's in the wrong direction.

        What does Windows think your time is (and might as well check it's notion of the time zone, too)? I'm stretching here; I don't have a Windows system that I can use to check this.

        Update:One other thing that might be worth checking:

        my $isdst = ( localtime(time) )[-1]; print "$isdst\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://712577]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found