Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_date_tz(self):
"Test timezone parsing in _parse_date"
# these should succeed and are ISO8601 compliant
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 60.0)
for datestr in ("2017-05-01 00:00+01:00", "2017-05-01 00:00+0100", "2017-05-01 00:00+01"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# some more tests with non-zero minutes, should all be ISO compliant and work
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 85.0)
for datestr in ("2017-05-01 00:00+01:25", "2017-05-01 00:00+0125"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# these are NOT ISO8601 compliant and should not even be parseable but will be parsed with timezone anyway
# because, due to support of other legacy time formats, they are difficult to reject
# ATTENTION: only the hours part of this will be parsed, single-digit minutes will be ignored!
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 60.0)
for datestr in ("2017-05-01 00:00+01:0", "2017-05-01 00:00+01:", "2017-05-01 00:00+01:5"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# these should not even be parseable as datestrings but are parseable anyway with ignored timezone
# this is because the module also supports some legacy, non-standard time strings
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 0.0)
for datestr in ("2017-05-01 00:00+1",):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
d = cftime.num2date(1261440000.015625,units)
# on windows only 100 ms precision
assert(str(d)[0:24] == '2009-12-22 00:00:00.0156')
# issue #152 add isoformat()
assert(d.isoformat()[0:24] == '2009-12-22T00:00:00.0156')
assert(d.isoformat(sep=' ')[0:24] == '2009-12-22 00:00:00.0156')
assert(d.isoformat(sep=' ',timespec='milliseconds') == '2009-12-22 00:00:00.015')
assert(d.isoformat(sep=' ',timespec='seconds') == '2009-12-22 00:00:00')
assert(d.isoformat(sep=' ',timespec='minutes') == '2009-12-22 00:00')
assert(d.isoformat(sep=' ',timespec='hours') == '2009-12-22 00')
# 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')
# issue #175: masked values not treated properly in num2date
times = np.ma.masked_array([-3956.7499999995343,-999999999999],mask=[False,True])
units='days since 1858-11-17 00:00:00'
dates = num2date(times, units=units, calendar='standard',\
only_use_cftime_datetimes=False, only_use_python_datetimes=True)
test = dates == np.ma.masked_array([datetime(1848, 1, 17, 6, 0, 0, 40), None],mask=[0,1])
assert(test.all())
dates = num2date(times, units=units, calendar='standard')
assert(str(dates)=='[cftime.DatetimeGregorian(1848, 1, 17, 6, 0, 0, 40) --]')
# check that time range of 200,000 + years can be represented accurately
calendar='standard'
_MAX_INT64 = np.iinfo("int64").max
refdate = DatetimeGregorian(292277,10,24,0,0,1)
for unit in ['microseconds','milliseconds','seconds']:
units = '%s since 01-01-01' % unit
def test_parse_date_tz(self):
"Test timezone parsing in _parse_date"
# these should succeed and are ISO8601 compliant
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 0, 60.0)
for datestr in ("2017-05-01 00:00+01:00", "2017-05-01 00:00+0100", "2017-05-01 00:00+01"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# some more tests with non-zero minutes, should all be ISO compliant and work
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 0, 85.0)
for datestr in ("2017-05-01 00:00+01:25", "2017-05-01 00:00+0125"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# these are NOT ISO8601 compliant and should not even be parseable but will be parsed with timezone anyway
# because, due to support of other legacy time formats, they are difficult to reject
# ATTENTION: only the hours part of this will be parsed, single-digit minutes will be ignored!
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 0, 60.0)
for datestr in ("2017-05-01 00:00+01:0", "2017-05-01 00:00+01:", "2017-05-01 00:00+01:5"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# these should not even be parseable as datestrings but are parseable anyway with ignored timezone
# this is because the module also supports some legacy, non-standard time strings
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 0, 0.0)
for datestr in ("2017-05-01 00:00+1",):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
def test_parse_date_tz(self):
"Test timezone parsing in _parse_date"
# these should succeed and are ISO8601 compliant
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 60.0)
for datestr in ("2017-05-01 00:00+01:00", "2017-05-01 00:00+0100", "2017-05-01 00:00+01"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# some more tests with non-zero minutes, should all be ISO compliant and work
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 85.0)
for datestr in ("2017-05-01 00:00+01:25", "2017-05-01 00:00+0125"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# these are NOT ISO8601 compliant and should not even be parseable but will be parsed with timezone anyway
# because, due to support of other legacy time formats, they are difficult to reject
# ATTENTION: only the hours part of this will be parsed, single-digit minutes will be ignored!
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 60.0)
for datestr in ("2017-05-01 00:00+01:0", "2017-05-01 00:00+01:", "2017-05-01 00:00+01:5"):
d = _parse_date(datestr)
assert_equal(d, expected_parsed_date)
# these should not even be parseable as datestrings but are parseable anyway with ignored timezone
# this is because the module also supports some legacy, non-standard time strings
expected_parsed_date = (2017, 5, 1, 0, 0, 0, 0.0)