in reply to Re: setting TZ causes Date::Manip to report incorrect time
in thread setting TZ causes Date::Manip to report incorrect time

Does this mean that Date::Manip has problems with timezones, as BigLug suggests? i think the docs, rather than the code, are the problem. it would be interesting to see a proper comparison of DateTime functionality with Date::Manip; i would be surprised if Date::Manip came off worst:

Well, as someone who's used every datetime module under the sun, and then got sick of them and wrote DateTime, I wouldn't be surprised if Date::Manip came off worse, because I know that it will.

Specifically, try doing this with Date::Manip:

my $dt1 = DateTime->new( year => 2003, month => 5, day => 2, hour => 7, minute => 53, time_zone => 'Asia/Tokyo' ); my $dt2 = DateTime->new( year => 2003, month => 5, day => 2, hour => 5, minute => 53, time_zone => 'Asia/Calcutta' ); if ( $dt1 > $dt2 ) { ... } else { ... } $dt1->set_time_zone( 'Asia/Calcutta' ); print $dt1->datetime, "\n"; print $dt2->datetime, "\n";

If that sort of thing is even possible with Date::Manip, it'd be much, much, much more code.

Date::Manip can alter the number of seconds in the day via "WorkDayBeg" and "WorkDayEnd" in Date_init() (see above), so it, at least, does not suffer from making the assumption that there are 24*60*60 seconds in a day.

What BigLug was referring to when he mentioned this was the existence of leap seconds, not the idea of "business hours". Some days last longer than 24*60*60 seconds on the clock, according to the UTC system. However, this only happens to one day every couple years or so. You can't simply change the length of the day and leave it at that. That would be quite broken.

Replies are listed 'Best First'.
Re^3: setting TZ causes Date::Manip to report incorrect time
by Anonymous Monk on Mar 11, 2022 at 06:57 UTC
    So I'll take your challenge and say .. I think its working, if you dig into how its intended to work. Using your exact example dataset, I reformatted it for Date::Manip. Some may have other opinions on how to set the date, but this is compact and for me easy to follow:
    use strict; use warnings; use Date::Manip; my $dt1 = Date::Manip::Date->new(); my $dt2 = Date::Manip::Date->new(); $dt1->config("setdate","zone,Asia/Tokyo"); $dt2->config("setdate","zone,Asia/Calcutta"); $dt1->parse("20030502T07:53"); $dt2->parse("20030502T05:53"); if ( $dt1->cmp($dt2) ) { print "dt1 ftw!\n"; } else { print "dt2 ftw!\n"; } print $dt1->printf("dt1 %c %Z\n"); $dt1->convert("Asia/Calcutta"); print $dt1->printf("dt1 %c %Z\n"); print $dt2->printf("dt2 %c %Z\n");
    Output is:
    $ perl ./testdate dt1 ftw! dt1 Fri May 2 07:53:00 2003 JST dt1 Fri May 2 04:23:00 2003 IST dt2 Fri May 2 05:53:00 2003 IST
Re: Re: Re: setting TZ causes Date::Manip to report incorrect time
by wufnik (Friar) on Sep 10, 2003 at 22:16 UTC
    autarch, those seem eminently reasonable points.

    the two modules evidently occupy similar niches. while your example above is persuasive, it would be surprising if Date::Manip did not have strengths it would be too tedious to mention.

    i think what would be very helpful to the general monk population is a pithy comparison table, outlining the various points that would be useful, and whether datetime or date::manip holds the higher ground. BigLug suggested as much.

    what better way to convince us of your assertion:

    i know that it will. ?

    best wishes, ...wufnik

    -- in the world of the mules there are no rules --