Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

larsbarring
Copy link
Contributor

🚀 Pull Request

Description

Test and possible proof-of-concept
Takes care of issue #185, and also allows conversion between julian and standard calendars if all datetimes are before 1582-10-5 0:0:0

@larsbarring
Copy link
Contributor Author

Ready for review -- with cftime 1.5.2 all test pass. But this I leave to you.

@larsbarring larsbarring changed the title WIP: Issue #185: Convert calendars if possible wrt Julian-Gregorian gap Issue #185: Convert calendars if possible wrt Julian-Gregorian gap Feb 17, 2022
@rcomer
Copy link
Member

rcomer commented Feb 17, 2022

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))
standard: 1582-09-20 00:00:00
proleptic_gregorian: 1582-09-30 00:00:00

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:

standard: 1582-10-31 00:00:00
proleptic_gregorian: 1582-10-21 00:00:00

What do you think?

@larsbarring
Copy link
Contributor Author

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.

@larsbarring
Copy link
Contributor Author

@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 (standard, julian and proleptic_gregorian) are just three alternative methods for labelling these days; sometimes the labels overlap and sometimes not. As the calendars, i.e. the "labelling methods", are well-known is should be possible to convert between them (at least for dates onwards from 1-1-1).

Is this a fair interpretation of what you suggest?

@rcomer
Copy link
Member

rcomer commented Feb 22, 2022

@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!

@larsbarring
Copy link
Contributor Author

@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.

@rcomer
Copy link
Member

rcomer commented Feb 22, 2022

@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.

@larsbarring
Copy link
Contributor Author

OK, I will give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For modern data allow unit conversion between standard and proleptic_gregorian calendars
2 participants