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

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. ;-)


🦛

Replies are listed 'Best First'.
Re^5: Baffled by DateTime
by BernieC (Pilgrim) on Mar 31, 2023 at 17:53 UTC
    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.