-
Notifications
You must be signed in to change notification settings - Fork 211
Decide how to deal with parameterised calendars in AnyCalendar
#6397
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
Comments
AnyCalendar
We've discussed this before, Ethiopian calendars being mixable was intentional, but low importance. Hijri calendars should not be mixed and we should error in that case, probably via extra variants |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Why is this issue closed? What we have now is inconsistent and I've never liked it. It is weird that we collapse some things but not others. Can someone explain why we split Dangi and Chinese into separate structs but not Ethiopian and Ethioaa? We are in some weird middle ground. I'm fine if we can explain this, but I thought we were moving in the direction of having one struct per calendar, with Ethiopian being an exception to the rule, but now we seem to be moving in the opposite direction. |
That's largely an implementation detail IMO. Collapsing the calendar types where possible reduces API surface rather cleanly; I have always disliked having so much boilerplate for islamic. The main place this is noticeably exposed is AnyCalendar's enum, which is rarely directly accessed. (There is an argument to be made for making it opaque, I'm not sure I wish to make that argument, but one could). I'm not opposed to merging Chinese and Dangi into the same type. It would greatly simplify the code, we have an additional layer of internal traits and boilerplate there. |
I think I want to toss this issue into 2.0-stretch, if someone wants to take the time to clean up the AnyCalendar type split. |
Conclusion from brief discussion with @Manishearth @robertbastian @sffc:
|
I was going through the current code and I remembered why we had separate types for a lot of these. One thing is formatting: we should not have the same type for two calendars that cannot share formatters. So Chinese and Dangi should continue to have separate types, unless they use a type parameter. By this metric HijriTabular can still be one type. The other concern is date arithmetic: we wish to eventually support subtracting dates from each other, and that is supposed to be in the same calendar. By merging the HijriTabular types, we are forcing ourselves to make that functionality fallible. Are we okay with that? There's a ladder of strictness we can follow:
Historically we were on level 3, and we kept Japanese to be two types to have better data loading. With HijriTabular we are moving to Level 2. Chinese/Dangi take us to Level 1, which we should not do. Making it generic is acceptable. Level 2 is fine as long as the eventual arithmetic APIs cover this. They're private right now so it's tweakable. |
I think merging the types is not a problem in But it might get problematic in |
Can we create newtypes for every calendar and |
The status quo is we have a single set of formatting data, and both ethiopic calendar types can be used interchangeably with the formatter, and will produce correct results. The formatter will see Amete Alem X or Amete Mihret Y and format those accordingly. Level 2 and 3 are not problematic in formatters, and if anything they make it easier to share formatters and reduce data loading if dealing with Fixed. You don't actually need to have different Fixed instances for different calendars.
This wouldn't do anything, that doesn't carry trait impls over. ArithmeticDate is, essentially, this type already. Deref also isn't supposed to be used like that (one of the reasons is precisely that it doesn't forward traits, but if you use it this way you rapidly find yourself wanting that behavior). Deref coercions only apply in specific situations, which work great for pointery types but not well for the general goal of having a coercing conversion. |
I observe that we're turning the needs of If we are, then (2) seems like a principled approach. |
That's part of the question. Historically, when we were on Level 3, we were constrained by a non-mandatory need of With I think in the absence of these arithmetic APIs, So yeah, 2 seems fine. |
oh I see what you mean about the date arithmetic APIs You want to prevent code like let d1 = HijriTabular::new_type_ii_thursday(...)
let d2 = HijriTabular::new_type_ii_friday(...)
let difference = d1.until(d2) |
Proposal:
(This is status quo, but proposes a future route for arithmetic) Agreed: @Manishearth @sffc @robertbastian |
Currently we have
AnyCalendar::Ethiopian
,AnyDateInner::Ethiopian
,AnyCalendarKind::Ethiopian
,AnyCalendarKind::EthiopianAmeteAlem
HijriTabular
i.e. we collapse parametric calendars in
AnyCalendar
andAnyDateInner
, but not inAnyCalendarKind
. However, when we matchAnyCalendar
againstAnyDateInner
, we don't verify that the calendar parameters match. Should we? Or should we have separateAnyCalendar
variants for different instantiations of a calendar? Or just separateAnyCalendarDateInner
variants?The text was updated successfully, but these errors were encountered: