Skip to content

Commit

Permalink
Merge 2fdf3be into 4d5c48e
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Jul 25, 2020
2 parents 4d5c48e + 2fdf3be commit cd166fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
since version 1.2.1 release
===========================
* add tooridinal() to cftime.datetime, expose to_calendar_specific_datetime.

version 1.2.1 (release tag v1.2.1rel)
=====================================
* num2date uses 'proleptic_gregorian' scheme when basedate is post-Gregorian but date is pre-Gregorian
Expand Down
17 changes: 17 additions & 0 deletions cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ DATE_TYPES = {
}


@cython.embedsignature(True)
def to_calendar_specific_datetime(datetime, calendar, use_python_datetime):
"""
convert from one calendar-specific datetime instance to another.
If use_python_datetime=True, convert to python datetime (and ignore
calendar kwarg).
"""
if use_python_datetime:
date_type = real_datetime
else:
Expand Down Expand Up @@ -1113,6 +1119,17 @@ datetime object."""
else:
return NotImplemented

def toordinal(self):
"""
returns integer days since 1-1-1, like python's datetime toordinal.
"""
if self.calendar == '':
raise ValueError('calendar must be specified to compute ordinal')
else:
epoch = _IntJulianDayFromDate(1,1,1,self.calendar)
jd = _IntJulianDayFromDate(self.year,self.month,self.day,self.calendar)
return jd - epoch + 1

@cython.embedsignature(True)
cdef class DatetimeNoLeap(datetime):
"""
Expand Down

0 comments on commit cd166fc

Please sign in to comment.