-
Notifications
You must be signed in to change notification settings - Fork 50
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
Issue #185: Convert calendars if possible wrt Julian-Gregorian gap #215
Conversation
97d5885
to
cf1c8e2
Compare
Ready for review -- with cftime 1.5.2 all test pass. But this I leave to you. |
Thanks for this @larsbarring, it looks like it should be useful new functionality. However I think it may be necessary and sufficient to check the reference date in the unit, rather than checking the value dates themselves. For example, if we have two units with references after the "gap" and inspect some date values before the gap, we have: import cf_units
modern_standard = cf_units.Unit("days since 1582-10-20", calendar="standard")
modern_proleptic_gregorian = cf_units.Unit("days since 1582-10-20", calendar="proleptic_gregorian")
print("standard:", modern_standard.num2date(-20))
print("proleptic_gregorian:", modern_proleptic_gregorian.num2date(-20))
So the standard/julian date is 10 days before the proleptic gregorian one, but these two dates represent the same actual day, so the conversion seems valid. Conversely if our reference dates are before the "gap" but our values are after: ancient_standard = cf_units.Unit("days since 1582-10-01", calendar="standard")
ancient_proleptic_gregorian = cf_units.Unit("days since 1582-10-01", calendar="proleptic_gregorian")
print("standard:", ancient_standard.num2date(20))
print("proleptic_gregorian:", ancient_proleptic_gregorian.num2date(20)) we actually get two different dates:
What do you think? |
Thanks for this @rcomer ! -- I hadn't thought along these lines, which of course are much simpler. One possible snag would be that the Julian and proleptic Gregorian calendars have different methods for defining leap years (the 400 year difference). But when in each calendar this difference kicks in I am not sure. |
@rcomer Having now mulled over your idea a bit more I think that you are right! And that it is even more general than what I was considering. In the real world continuum of time a day is just a convenient and useful unit. And the real world calendars ( Is this a fair interpretation of what you suggest? |
@larsbarring, yes that's what I'm thinking - the calendars are different labels for the same actual sequence of days. I have to admit I hadn't begun to consider what happens at or before 1-1-1 though! |
@rcomer, from your first comment I take it that you might already have a PR on its way? Anyway, I will close this PR because because following this approach will result in rather different code. |
@larsbarring no I haven't made a branch for this. I only got as far as playing with the units in a terminal to produce the output I showed. |
OK, I will give it a try. |
🚀 Pull Request
Description
Test and possible proof-of-concept
Takes care of issue #185, and also allows conversion between
julian
andstandard
calendars if all datetimes are before 1582-10-5 0:0:0