in reply to Re: Baffled by DateTime
in thread Baffled by DateTime

A big DUH. Thanks for telling me the obvious. it is now perfectly well behaved
use DateTime; my $dt = DateTime->now(time_zone => "EST5EDT") ; say $dt->hour ; 9
which is the right time {it's now 9:32}. Thanks!

Replies are listed 'Best First'.
Re^3: Baffled by DateTime
by BernieC (Pilgrim) on Mar 31, 2023 at 15:06 UTC
    A small followon. With:
    perl -E "use DateTime ;my $now = DateTime->now(time_zone => \"EST5EDT\ +") ; my $day = $now->local_day_of_week ; say \"day of the week: $day\ +" ; " --------------------- day of the week: 6
    The docs say: "Returns the day of the week as a number, from 1..7, with 1 being Monday and 7 being Sunday." But today is Friday...looks like it is "with 1 being Sunday" This is not a big deal, but am I missing something?
      The docs say: "Returns the day of the week as a number, from 1..7, with 1 being Monday and 7 being Sunday."

      That's what the docs for ->day_of_week say. The docs for ->local_day_of_week say "The day corresponding to 1 will vary based on the locale." I suspect you want to call ->day_of_week instead, which will return 5 for the current date as expected.

      The docs say: "Returns the day of the week as a number, from 1..7, with 1 being Monday and 7 being Sunday."

      Actually, they don't. They say:

      Returns the day of the week as a number, from 1..7. The day corresponding to 1 will vary based on the locale. See the "Locales" section for more details.

      Unless you are using an old version, in which case surely you would have mentioned this. ;-)


      🦛

        I have v. 1.54, installed 12/04/20. And its docs say
        $day = $dt->day; # 1-31 $dow = $dt->day_of_week; # 1-7 (Monday is 1) $hour = $dt->hour; # 0-23 $minute = $dt->minute; # 0-59
        and I checked about an old version and cpan tells me
        cpan: upgrade all Fetching with LWP: http://cpan.strawberryperl.com/authors/01mailrc.txt.gz Fetching with LWP: http://cpan.strawberryperl.com/modules/02packages.details.txt.gz Fetching with LWP: http://cpan.strawberryperl.com/modules/03modlist.data.gz Database was generated on Thu, 30 Mar 2023 14:21:05 GMT Updating database file ... Done! All modules are up to date for all
        so I don't know why my version is different than yours.