-
Notifications
You must be signed in to change notification settings - Fork 159
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
Add getISOCalendarFields() method to calendar-dependent types #624
Conversation
Codecov Report
@@ Coverage Diff @@
## main #624 +/- ##
==========================================
+ Coverage 97.80% 97.82% +0.02%
==========================================
Files 16 16
Lines 3691 3727 +36
Branches 633 637 +4
==========================================
+ Hits 3610 3646 +36
Misses 79 79
Partials 2 2
Continue to review full report at Codecov.
|
Why the new name? I assume it's because Bikeshed of alternative names:
|
The idea for the new name happened at the bottom of #622, and I thought I'd see if anyone didn't like it 😄 Any of those alternatives except getSlots() seem fine with me, on the grounds that they are "scary" enough that they wouldn't be called by accident. All else being equal I think getISOCalendarFields() is probably still the most descriptive though. @justingrant ? |
To me, the main purpose of this method is to get at the internal data model, the same one used in the constructor. That's where names like "getRawFields()" and "getSlots()" came from. The fact that the fields are encoded in the ISO calendar is a coincidence. "getISOCalendarFields()" sounds like this method has to do with calling into the calendar API, when in reality, the exact opposite is true! |
Do you have any other comments besides the name? If there's no other obvious candidate for the name, I'm happy to just go back to getISOFields() and talk about renaming it down the line, but I don't want the discussion about the name to block landing this. |
Will this method also be used to convert from a non-ISO calendar to ISO values? If not, what API will be used to do that?
My main concern with naming is avoiding the word "ISO" to avoid confusing users who think that "ISO" means the ISO 8601 string formats. If this API is only for internal/advanced use, then how about |
I haven't reviewed the PR yet besides the name, but I'll do that next.
The "main" API to do that is intended to be withCalendar(): // Input: hebrewDate is a Temporal.Date that exposes Hebrew fields (year/month/day)
const isoDate = hebrewDate.withCalendar("iso"); // or "iso8601"?
// isoDate is a Temporal.Date that exposes ISO fields instead of Hebrew fields |
Another idea/suggestion: how about if we make the schema use the slot names: // Temporal.Date
{
isoYear: 2020,
isoMonth: 5,
isoDay: 27,
calendar: ***,
}
// Temporal.DateTime
{
isoYear: 2020,
isoMonth: 5,
isoDay: 27,
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
microsecond: 0,
nanosecond: 0,
calendar: ***,
}
// Temporal.MonthDay
{
isoMonth: 5,
isoDay: 27,
refYear: 1972,
calendar: ***,
} And then the method can be called one of:
|
@sffc, I think it'd be a good idea (as you're proposing) to make the internal field names different from the regular field names, so that users won't accidentally think that they're interchangeable. Also, could we add
|
|
Sounds like a feature, not a bug. ;-) Seriously, having a name that discourages most people from touching this method is probably a good thing. Developers who build custom calendars will be advanced experts and will read the docs carefully, so whatever the method is named it won't scare them. A higher priority, IMHO, is scaring the other 99.9% of developers who won't be creating custom calendars. If using "Internal" is not OK, then I think either "Raw" option would be an OK second choice. |
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.
Patch overall LGTM. I was thinking this would be getISOFields
along the lines of getFields
but I have no strong preferences apart from the strong preferences to get this merged ASAP 😄
I propose going with |
I think me @sffc and @justingrant have different opinions regarding the naming, so I would propose that we move ahead with the current name and bikeshed the name before Stage 3 on a separate issue. @sffc would you like to review this still, or should I merge it in? |
e2ba828
to
831b7a1
Compare
Approved with the understanding that the names of things is still an open question. Can you open an issue to track that? |
Was opening #630 as we speak! |
This is in order to be able to get the underlying fields from the data model, which are stored in the ISO 8601 calendar. It's not expected to be used in normal Temporal usage, it really exists only for calendar implementors. Closes: #354
831b7a1
to
3e6f496
Compare
The test failure was a rebase collision with the removal of Temporal.MonthDay.compare. |
This is in order to be able to get the underlying fields from the data
model, which are stored in the ISO 8601 calendar.
It's not expected to be used in normal Temporal usage, it really exists
only for calendar implementors.
Closes: #354