-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Update Calendar.day_of_week callback and Date.day_of_week/2 docs #14176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b91dfbc
Update callback and Date.day_of_week/2 docs
kipcole9 4e38396
Update lib/elixir/lib/calendar.ex
kipcole9 36feb9e
Merge branch 'elixir-lang:main' into day_of_week_docs
kipcole9 3e5bd1a
Update date.ex
josevalim f22e6d9
Update lib/elixir/lib/calendar/date.ex
josevalim d22e9c0
Update date.ex
josevalim 47d50c0
Update lib/elixir/lib/calendar/date.ex
josevalim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muy concerns are two:
starting_on
other than:default
and:monday
, the return is also an ordinal number for the default calendar.Those two reasons are why I wrote the language in the PR. To try to unify expectations for any calendar, and to then point out the specific outcome for the very specific (and yeah, very very common) case of the default calendar with the default
starts_on
I don't think I have anything else to contribute to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the root of our disagreement. The behaviour is to give calendars the flexibility to assign different meaning to numbers, given some restrictions. It seems
day_of_week
muddies the water for us, so we can try "teleporting" these questions to other functions, such asyear_of_era
. In that function, we can only make assumptions about what the Calendar.ISO return. Any other assumption or equivalence about what the numbers mean could potentially be wrong for entries such as the Japanese calendar.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except for the
:default
atom, you are not required to support any other atom. For example, a Japanese calendar may want to support:月曜日
(Monday according to Google), and that would be specific to them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually referring to the use of anything other than
:default
or:monday
inCalendar.ISO
returns an ordinal number, does it not? For example:Which I think is something worth mentioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! They all return ordinal numbers except when they accidentally align to be cardinal. In any case, I added a new comment that makes it clearer, does that help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. I think it's more than when you defined the Calendar behaviour you did something incredibly positive by providing a framework people can build on to represent alternative calendars in use. I don't think any other language provides such a solid foundation.
Many of those alternative calendars are still proleptic Gregorian based. The differences come from which month they start on, whether they are month- or week-based, when day upon which the week starts and the definition of what the first week of the year is.
That results in Fiscal Year calendars for different countries, industry specific calendars like that for the National Retail Federation, and calendars for countries which start their weeks on a different day. Even corporation specific calendars in the US where they can define their own financial year with some quite complex rules.
They are, basically, all the same base calendar. The only practical difference between these calendars is (1) week or month based, (2) starting month of year and (3) starting day of week.
is out of scope for Elixir per your earlier (years ago) comments. I have implemented the Calendar behaviour for week-based calendars in
ex_cldr_calendars
so they can still play nicely alongside month-based calendars - because they are still based upon the proleptic Gregorian calendar. And I have week-based capabilities in theCldr.Calendar
behaviour for month-based calendars.months are always ordinal in Calendar. Just as day-of-month is ordinal. It would be nice (in my opinion) to also have
Date.iso_month_of_year/2
but I would never suggest that unless we had agreement onDate.iso_day_of_week/2
. I really think these are the only two that would be relevant to a standard library. And as discussed these aren't happening.we've done to death, nothing more I have to say.
Hopefully this helps at least explain a little bit about why I try very hard to harmonise outputs from calendars I build with those from Calendar.ISO and have the same semantics - because basically for this very large category or calendars they are indeed the same semantics.
BTW, even for
Date.era_of_year/1
, which is used inex_cldr_dates_times
to format dates and times in a localised way, the code that deals with era formatting doesn't have to distinguish between Calendar.ISO and Cldr.Calendar.Japanese. The results are different but how to interpret them is not. (I spent weeks researching the Japanese imperial history to validate the eras - but that's for a beer conversation).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added some code comments to the examples. Let me know if it helps. However, I'd like to avoid introducing the word cardinal in the docs:
We don't talk about it anywhere else, so we would need to fully introduce it as a concept, which we wouldn't use ourselves
The majority of Elixir users likely have English as a second language, so introducing words like ordinal/cardinal come also with a language barrier cost :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very fair point José