Re: Daylight savings time timezone conversion automatically?

[email protected] (Ewald Beekman)
Newsgroups perl.datetime
Message-ID <20080326183433.GF18125@vortex>
Is there a way to see if DST is in effect on a
returned time zone object ?
For instance, i have got a loop like this:

my @list = DateTime::TimeZone->all_names;
foreach $zone (@list) {
        next unless ($zone =~ /\//);                    # skip timezone links in the list
        $dt = DateTime->now();                          # current computer time
        $tz = DateTime::TimeZone->new( name => $zone ); # timezone

        $offset = $tz->offset_for_datetime($dt);        # offset from UTC for this timezone
        $TZ = $tz->short_name_for_datetime($dt);        # timezone name (e.g. CET)
        $dt->add(seconds =>  $offset);                  # convert computer time to time in timezone
        $hoffset = $offset / 3600;                      # offset in hours

        printf "%40s\t%s\tGMT diff = %g\t%4s\t",$zone,$TZ, $hoffset,$DST;
        printf "%d/%02d/%02d %02d:%02d\n",$dt->year,$dt->month,$dt->day,$dt->hour,$dt->minute;
        }

How can i see for each zone displayed if it is in DST?
The only way i could think of is add an offset of half a year
to the timezone and compare the time's, but that seems a bit overdone
since the info is there somewhere allready.

thanks for your help.
Ewald...

On Wed, Mar 12, 2008 at 04:54:07PM -0500, Dave Rolsky wrote:
> On Thu, 13 Mar 2008, Rick Measham wrote:
> 
> >William Heath wrote:
> >>I think I figured it out, what is important to understand is that you
> >>can't choose EST, you must choose a country/city for the function to
> >>adjust for DST automatically.  My question was probably too simple for
> >>you to give me this solution but I did figure it out.  Does that make
> >>sense to you?
> >
> >Absolutely. The time zones supported by DateTime are designed to be 
> >robust, not only for today but back to 1970.
> 
> Actually, most of the them go back quite a bit further, to the 1910s or 
> so, or whenever the country in question started using time zones, which 
> obviously varies from place to place.
> 
> It even tries to go back earlier by defining a LMT (local mean time, I 
> believe) rule that applies for all times before the first real time zone. 
> This isn't so useful, though because the LMT for America/Chicago is really 
> for Chicago only (and anything along the same longitude line), and doesn't 
> apply to other cities in the same time zone (like Minneapolis).
> 
> 
> -dave
> 
> /*==========================
> VegGuide.Org
> Your guide to all that's veg
> ==========================*/

-- 
http://www.oiepoie.nl
## Your mind-mint is:
The distinction between Freedom and Liberty is not accurately known;
naturalists have been unable to find a living specimen of either.
		-- Ambrose Bierce
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.