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

The Date_ConvTZ function from Date::Manip is not working correctly on version 6.52 which is working fine with version 5.42

#!/usr/local/bin/perl use strict; use warnings; use POSIX; use Date::Manip; use Data::Dumper; my $now = ParseDate( "now" ); print "NOW: $now\n"; my $today = ParseDate( "-1 hour" ); print "today:$today\n"; my $npadate = UnixDate( $today, "%Y%m%d" ); #my $npahour = UnixDate( $today, "%H" ); #they want file date/time in central time............ print "TODAY II: $today\n"; my $fd = Date_ConvTZ( $today, "EST", "CST" ); print "FD: $fd\n"; my $yest = DateCalc( $fd, "-1 day" ); $yest = UnixDate( $yest, "%Y%m%d" ); print "yest:$yest\n"; my $filedate = UnixDate( $fd, "%Y%m%d" ); my $filehour = UnixDate( $fd, "%H" ); print "filedate:$filedate, filehour:$filehour\n";

output:- NOW: 2017050112:32:01 today:2017050111:32:01 TODAY II: 2017050111:32:01 FD: 2017050200:32:01 yest:20170501 filedate:20170502, filehour:00

  • Comment on The funtion - Date_ConvTZ is not working correctly when converting from EST to CST
  • Download Code

Replies are listed 'Best First'.
Re: The funtion - Date_ConvTZ is not working correctly when converting from EST to CST
by 1nickt (Canon) on May 01, 2017 at 16:43 UTC

    From the doc to Date::Manip:

    VERSION 5 AND VERSION 6

    Date::Manip version 6.00 was a complete rewrite of the module (for more information, please refer to the Date::Manip::Changes5to6 document).

    The document linked to in that Readme contains all you need to know about the changes to TimeZone handling in Date::Manip, including at http://search.cpan.org/~sbeck/Date-Manip-6.58/lib/Date/Manip/Changes5to6.pod#TIME_ZONE_SUPPORT.

    Personally I use DateTime for all date ... er, manipulation. (Note that you should let it handle Daylight Savings Time automatically for you, i.e. don't specify CST but rather "America/Chicago" or similar.)

    $ perl -MDateTime -E ' my $dt = DateTime->now; say join " ", $dt, $dt->time_zone_short_name; $dt->set_time_zone("America/Chicago"); say join " ", $dt, $dt->time_zone_short_name; '
    Output:
    2017-05-01T16:53:29 UTC 2017-05-01T11:53:29 CDT

    Hope this helps!

    Update: added DT example


    The way forward always starts with a minimal test.
      Thanks for the info as well as the new suggestion code, I will try that.