Managed to write code to get around this problem - at least for my specific requirements. Might not be the most elegant code but it works.

For each local time I could obtain from the DateTime module whether it was DST or not ('0' / '1') indicator. By storing the previous value I could determine whether the dates being processed where changing from DST to GMT/UTC - value of "10" when combining the previous and current values.

When this occurred I set up a counter to subtract 1 hour from the UTC time for the next hour. This correctly ensured that the UTC time continue without jumping forward and missing the 00:00 - 00:59 period.

When I ran March data (GMT/UTC to DST) I discovered I did not have a problem during this calculation because the local time move forward an hour it never contains data that will cause the Date Time module to return an error due to an invalid date time - i.e. a time in the missing hour.

Code below, (part off as a bit long after I added all my weather parameters) as I said probably not the most efficient or well written Perl code (still new to Perl) but it does what I need it to do... Thanks for all your guidance and pointers, much appreciated.
my $prev_dst = ""; my $curr_dst = ""; my $dst_code = ""; my $dst_flag = "N"; my $dst_counter = 1; foreach (@extended_records) { my @ext_lines = split /\n/, $_; foreach my $line_ext (@ext_lines) { my @ext_fields = split ",", $line_ext; # Get the fields from the Extended File. my $obs_day = $ext_fields[0]; my $obs_month = $ext_fields[1]; my $obs_year = $ext_fields[2]; my $obs_hour = $ext_fields[3]; my $obs_minute = $ext_fields[4]; my $obs_seconds = 0; my $temp_c = $ext_fields[5]; my $humidity_rh = $ext_fields[6]; my $dewpoint_c = $ext_fields[7]; my $wind_dir_degrees = $ext_fields[12]; my $wind_speed_mph = $ext_fields[10]; my $wind_gust_mph = $ext_fields[11]; my $pressure_hpa = $ext_fields[9]; my $rain_last_minute = 0; my $rain_today = $ext_fields[13]; my $heat_index = $ext_fields[8]; my $rain_rate = $ext_fields[14]; my $soil_temp = $ext_fields[15]; my $weather_conditions = $ext_fields[16]; my $heat_word = $ext_fields[17]; my $ground_temp = $ext_fields[18]; my $solar = $ext_fields[19]; my $uv_index = $ext_fields[20]; my $solar_percentage = $ext_fields[21]; my $solar_description = $ext_fields[22]; my $et = $ext_fields[23]; my $burntime = $ext_fields[26]; my $sunshine = $ext_fields[27]; my $soil_moisture = $ext_fields[28]; my $leaf_wetness = $ext_fields[29]; my $cloud_height_metres = $ext_fields[32]; my $indoor_temp_c = $ext_fields[35]; my $indoor_humidity_rh = $ext_fields[36]; my $apparent_temp = $ext_fields[37]; my $apparent_solar_temp = $ext_fields[38]; my $humidex = $ext_fields[40]; my $air_density = $ext_fields[44]; # Format the collected data $temp_c =~ s/°C//; $dewpoint_c =~ s/°C//; $wind_dir_degrees =~ s/ °//; $wind_speed_mph =~ s/ mph//; $wind_gust_mph =~ s/ mph//; $pressure_hpa =~ s/ mb//; $rain_today =~ s/ mm//; $heat_index =~ s/°C//; $soil_temp =~ s/°C//; $solar_percentage =~ s/ %//; $humidex =~ s/°C//; # Get the Observation Date Time and keep in Local Format. my $obs_datetime_local = DateTime->new ( year => $obs_year, month => $obs_month, day => $obs_day, hour => $obs_hour, minute => $obs_minute, time_zone => 'Europe/London', ); # Get the Observation Date Time and Convert to UTC. my $obs_datetime_utc = DateTime->new ( year => $obs_year, month => $obs_month, day => $obs_day, hour => $obs_hour, minute => $obs_minute, time_zone => 'Europe/London', ); $obs_datetime_utc->set_time_zone( 'UTC' ); my $dst = $obs_datetime_local->is_dst(); # Combine the Current and Previous IsDST values to determine i +f the DST to GMT/UTC change has occured. $curr_dst = $dst; $dst_code = $prev_dst . $curr_dst; # If the Previous DST is set (1) and the Current DST is not se +t (0) then set the DST Flag. if ($dst_code eq "10") { $dst_flag = "Y"; } # If the DST Flag has been set then a change from DST to GMT/U +TC has occurred. if ($dst_flag eq "Y") { # Subtract 1 from the Observation Hour to get the correct +UTC Date/Time - construct the formated UTC Date & Time. my $dst_hour = $obs_hour - 1; my $dst_datetime_utc = DateTime->new ( year => $obs_year, month => $obs_month, day => $obs_day, hour => $dst_hour, minute => $obs_minute, ); $obs_datetime_utc = $dst_datetime_utc; # Reset the DST Flag and Counter after the hour requiring +the change to UTC has been processed. if ($dst_counter == 59) { $dst_flag = "N"; $dst_counter = 1; } $dst_counter = $dst_counter + 1; } # Use the UTC Date/Time for the unformatted Observation Date & + Time. my $rep_year = substr $obs_datetime_utc,0,4; my $rep_month = substr $obs_datetime_utc,5,2; my $rep_day = substr $obs_datetime_utc,8,2; my $rep_hour = substr $obs_datetime_utc,11,2; my $rep_minute = substr $obs_datetime_utc,14,2; my $rep_second = substr $obs_datetime_utc,17,2; # Output Record Line to a CSV File my $record_line = $rep_year . $rep_month . $rep_day . $rep_hou +r . $rep_minute . $rep_second . "," . $obs_datetime_utc . "," . $obs_ +datetime_local . "," . $temp_c . "," . $dewpoint_c . ",". $humidity_r +h . "," . $wind_dir_degrees . "," . $wind_speed_mph . "," . $wind_gus +t_mph . "," . $pressure_hpa . "," . $rain_last_minute . "," . $rain_t +oday . "," . $heat_index . "," . $rain_rate . "," . $soil_temp . "," +. $weather_conditions . "," . $heat_word . "," . $ground_temp . "," . + $solar . "," . $uv_index . "," . $solar_percentage . "," . $solar_de +scription . "," . $et . "," . $burntime . "," . $sunshine . "," . $so +il_moisture . "," . $leaf_wetness . "," . $cloud_height_metres . "," +. $indoor_temp_c . "," . $indoor_humidity_rh . "," . $apparent_temp . + "," . $apparent_solar_temp . "," . $humidex . "," . $air_density . " +\n"; print $record_line; my $file = "C:\\WEATHER_DATA_COLLECTOR\\BATHGATE\\" . $rep_yea +r . $rep_month . "_BATHGATE.CSV"; open (TXT, ">>", $file); print TXT $record_line; close (TXT); $prev_dst = $curr_dst; } }

In reply to Re^4: Converting local time to utc time by ureco
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.