Skip to content

Commit

Permalink
Merge pull request #170 from Unidata/issue169
Browse files Browse the repository at this point in the history
fix for issue #169
  • Loading branch information
jswhit committed May 7, 2020
2 parents 9adea4b + c32b374 commit b1a64bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Changelog
@@ -1,6 +1,8 @@
since version 1.1.2 release
===========================
* add isoformat method for compatibility with python datetime(issue #152).
version 1.1.3 (release tag v1.1.3rel)
=====================================
* add isoformat method for compatibility with python datetime (issue #152).
* make 'proleptic_gregorian' default calendar for cftime.datetime
so that dayofwk,dayofyr methods don't fail (issue #169).

version 1.1.2 (release tag v1.1.2rel)
=====================================
Expand Down
8 changes: 4 additions & 4 deletions cftime/_cftime.pyx
Expand Up @@ -52,7 +52,7 @@ cdef int32_t* days_per_month_array = [
_rop_lookup = {Py_LT: '__gt__', Py_LE: '__ge__', Py_EQ: '__eq__',
Py_GT: '__lt__', Py_GE: '__le__', Py_NE: '__ne__'}

__version__ = '1.1.2'
__version__ = '1.1.3'

# Adapted from http://delete.me.uk/2005/03/iso8601.html
# Note: This regex ensures that all ISO8601 timezone formats are accepted - but, due to legacy support for other timestrings, not all incorrect formats can be rejected.
Expand Down Expand Up @@ -161,7 +161,7 @@ cdef _parse_date_and_units(timestr,calendar='standard'):
# parse the date string.
year, month, day, hour, minute, second, microsecond, utc_offset = _parse_date(
isostring.strip())
return units, utc_offset, datetime(year, month, day, hour, minute, second)
return units, utc_offset, datetime(year, month, day, hour, minute, second, calendar=calendar)


def date2num(dates,units,calendar='standard'):
Expand Down Expand Up @@ -1254,7 +1254,7 @@ Gregorial calendar.

def __init__(self, int year, int month, int day, int hour=0, int minute=0,
int second=0, int microsecond=0, int dayofwk=-1,
int dayofyr = -1):
int dayofyr = -1, calendar='standard'):

self.year = year
self.month = month
Expand All @@ -1263,7 +1263,7 @@ Gregorial calendar.
self.minute = minute
self.second = second
self.microsecond = microsecond
self.calendar = ""
self.calendar = calendar
self.datetime_compatible = True
self._dayofwk = dayofwk
self._dayofyr = dayofyr
Expand Down
4 changes: 4 additions & 0 deletions test/test_cftime.py
Expand Up @@ -754,6 +754,10 @@ def test_tz_naive(self):
# issue #165: make sure python datetime returned
d=num2date(0,units="seconds since 2000-01-01 00:00:00",only_use_cftime_datetimes=False)
assert isinstance(d, datetime)
# issue #169: cftime.datetime has no calendar attribute, causing dayofwk,dayofyr methods
# to fail.
c = cftime.datetime(*cftime._parse_date('7480-01-01 00:00:00'))
assert(c.strftime() == '7480-01-01 00:00:00')

class TestDate2index(unittest.TestCase):

Expand Down

0 comments on commit b1a64bf

Please sign in to comment.