The change forward is not a problem, it's moving back that creates the ambiguity. As I see it you need to delay applying the UTC timezone until the second sequence of 01:00 to 01:59 times on the change day. I suggest using the is_DST method to detect the change, and a hash to remember when the time repeats. For example :

#!perl use DateTime; use DateTime::TimeZone; use strict; my %seen=(); my $tz = 'UTC'; my $last; while (<DATA>){ chomp; next unless ($_); my ($y,$m,$d,$hr,$min) = split /\D/,$_; print "$_ : "; my $dt = DateTime->new ( year => $y, month => $m, day => $d, hour => $hr, minute => $min, time_zone => 'Europe/London', ); print $dt->is_dst," : "; if ($m==10 && $hr==1){ if ($dt->is_dst() ne $last){ $tz = '-1:00'; } $tz = 'UTC' if ++$seen{$min} > 1; } else { %seen=(); } $last = $dt->is_dst(); $dt->set_time_zone($tz); print $dt->strftime("%Y-%m-%d %H:%M")," $tz \n"; } __DATA__ 2014-03-30 00:59 2014-03-30 02:00 2014-03-30 02:01 2014-03-30 02:30 2014-03-30 02:59 2014-03-30 03:00 2014-03-30 03:01 2014-03-30 03:30 2014-03-30 03:59 2014-03-30 04:00 2014-03-30 04:01 2014-03-30 04:02 2014-10-26 00:59 2014-10-26 01:00 2014-10-26 01:01 2014-10-26 01:30 2014-10-26 01:59 2014-10-26 01:00 2014-10-26 01:01 2014-10-26 01:30 2014-10-26 01:59 2014-10-26 02:00 2014-10-26 02:01 2014-10-26 02:02

In reply to Re^8: Converting local time to utc time by poj
in thread Converting local time to utc time by ureco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.