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

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?

Replies are listed 'Best First'.
Re^4: Baffled by DateTime
by haukex (Archbishop) on Mar 31, 2023 at 15:35 UTC
    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.

Re^4: Baffled by DateTime
by hippo (Archbishop) on Mar 31, 2023 at 15:35 UTC
    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.
        DateTime is at 1.59 since 2022-10-23. Because you have cpan set to use strawberryperl's mirror, even though CPAN mirrors aren't recommended since the central server handles loadbalancing now, you are relying on strawberryperl being up-to-date; given that they haven't released a new version of perl since 2021, expecting their cpan-mirror to be more up-to-date than their perl version is a bit optimistic. I always use cpanm client from strawberryperl, without overriding to any mirrors, and it has no problem deciding it's time to update DateTime.

        But even in v1.54's documentation, the local_day_of_week documentation matches hippo's quote. You are quoting from the SYNOPSIS, and are quoting an example of day_of_week() even though your original code used local_day_of_week(), which is a different function with different return values.