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

handling of year 0 changed in python cftime #17

Closed
Alexander-Barth opened this issue Apr 21, 2022 · 2 comments
Closed

handling of year 0 changed in python cftime #17

Alexander-Barth opened this issue Apr 21, 2022 · 2 comments

Comments

@Alexander-Barth
Copy link
Member

Describe the bug

The handling of year 0 changed in python cftime:

10/1/2021: Version 1.5.1 released. Changed default behavior of proleptic_gregorian to has_year_zero=T 
(since it is allowed in ISO-8601 and CF does not specify the year zero convention for this calendar). 
Raise warning message when trying to create a calendar that is not supported by CF version 1.9 
(no years < 1 allowed for 'standard'/'gregorian' or 'julian' calendars). 

To Reproduce

using CFTime, Dates
DateTimeProlepticGregorian(1,1,1) - Day(1)
# output: DateTimeProlepticGregorian(-001-12-31T00:00:00)

All calendars are affected expect DateTimeStandard and DateTimeJulian

Expected behavior

output should be DateTimeProlepticGregorian(0,12,31) as in python:

In [3]: cftime.DatetimeProlepticGregorian(1, 1, 1) + timedelta(days=-1)
Out[3]: cftime.DatetimeProlepticGregorian(0, 12, 31, 0, 0, 0, 0, has_year_zero=True)

Environment

Full output

No additional output. All reference values from python and cftime 1.6.0:

In [3]: cftime.DatetimeProlepticGregorian(1, 1, 1) + timedelta(days=-1)
Out[3]: cftime.DatetimeProlepticGregorian(0, 12, 31, 0, 0, 0, 0, has_year_zero=True)

In [4]: cftime.DatetimeJulian(1, 1, 1) + timedelta(days=-1)
<ipython-input-4-e85e1427bb46>:1: CFWarning: this date/calendar/year zero convention is not supported by CF
  cftime.DatetimeJulian(1, 1, 1) + timedelta(days=-1)
Out[4]: cftime.DatetimeJulian(-1, 12, 31, 0, 0, 0, 0, has_year_zero=False)

In [5]: cftime.DatetimeGregorian(1, 1, 1) + timedelta(days=-1)
<ipython-input-5-d72578c40af5>:1: CFWarning: this date/calendar/year zero convention is not supported by CF
  cftime.DatetimeGregorian(1, 1, 1) + timedelta(days=-1)
Out[5]: cftime.DatetimeGregorian(-1, 12, 31, 0, 0, 0, 0, has_year_zero=False)

In [6]: cftime.DatetimeAllLeap(1, 1, 1) + timedelta(days=-1)
Out[6]: cftime.DatetimeAllLeap(0, 12, 31, 0, 0, 0, 0, has_year_zero=True)

In [7]: cftime.DatetimeNoLeap(1, 1, 1) + timedelta(days=-1)
Out[7]: cftime.DatetimeNoLeap(0, 12, 31, 0, 0, 0, 0, has_year_zero=True)

In [8]: cftime.Datetime360Day(1, 1, 1) + timedelta(days=-1)
Out[8]: cftime.Datetime360Day(0, 12, 30, 0, 0, 0, 0, has_year_zero=True)
@Alexander-Barth
Copy link
Member Author

https://web.archive.org/web/20240304171516/https://unidata.github.io/cftime/api.html

has_year_zero: if set to True, astronomical year numbering is used and the year zero exists. If set to False for real-world calendars, then historical year numbering is used and the year 1 is preceded by year -1 and no year zero exists. The defaults are set to conform with CF version 1.9 conventions (False for ‘julian’, ‘gregorian’/’standard’, True for ‘proleptic_gregorian’ (ISO 8601) and True for the idealized calendars ‘noleap’/’365_day’, ‘360_day’, 366_day’/’all_leap’) The defaults can only be over-ridden for the real-world calendars, for the the idealized calendars the year zero always exists and the has_year_zero kwarg is ignored. This kwarg is not needed to define calendar systems allowed by CF (the calendar-specific defaults do this).

@Alexander-Barth
Copy link
Member Author

The default python-cftime is now implemented:

@inline _hasyear0(::Type{T}) where T <: Union{DateTimeJulian,DateTimeStandard} = false
@inline _hasyear0(::Type{T}) where T <: AbstractCFDateTime = true

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

No branches or pull requests

1 participant