Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dt.replace(day=dt.day + 1, hour=dt.hour + 1))
# test the Julian/Gregorian transition
self.assertEqual(self.date4_gregorian + self.delta,
DatetimeGregorian(1582, 10, 15, 1))
# The Julian calendar has no invalid dates
self.assertEqual(self.date8_julian + self.delta,
DatetimeJulian(1582, 10, 5, 1))
# Test going over the year boundary.
self.assertEqual(DatetimeGregorian(2000, 11, 1) + timedelta(days=30 + 31),
DatetimeGregorian(2001, 1, 1))
# Year 2000 is a leap year.
self.assertEqual(DatetimeGregorian(2000, 1, 1) + timedelta(days=31 + 29),
DatetimeGregorian(2000, 3, 1))
# Test the 366_day calendar.
self.assertEqual(DatetimeAllLeap(1, 1, 1) + timedelta(days=366 * 10 + 31),
DatetimeAllLeap(11, 2, 1))
# The Gregorian calendar has no year zero.
self.assertEqual(DatetimeGregorian(-1, 12, 31) + self.delta,
DatetimeGregorian(1, 1, 1, 1))
def invalid_add_1():
self.date1_365_day + 1
def invalid_add_2():
1 + self.date1_365_day
assert (d.year == -100)
assert (d.month == 3)
assert (d.day == 2)
assert (d.hour == 0)
assert (d.minute == 0)
assert (d.second == 0)
# test dayofwk, dayofyr attribute setting (cftime issue #13)
d1 = DatetimeGregorian(2020,2,29)
d2 = real_datetime(2020,2,29)
assert (d1.dayofwk == d2.dayofwk == 5)
assert (d1.dayofyr == d2.dayofyr == 60)
d1 = DatetimeGregorian(2020,2,29,23,59,59)
d2 = real_datetime(2020,2,29,23,59,59)
assert (d1.dayofwk == d2.dayofwk == 5)
assert (d1.dayofyr == d2.dayofyr == 60)
d1 = DatetimeGregorian(2020,2,28,23,59,59)
d2 = real_datetime(2020,2,28,23,59,59)
assert (d1.dayofwk == d2.dayofwk == 4)
assert (d1.dayofyr == d2.dayofyr == 59)
d1 = DatetimeGregorian(1700,1,1)
d2 = real_datetime(1700,1,1)
assert (d1.dayofwk == d2.dayofwk == 4)
assert (d1.dayofyr == d2.dayofyr == 1)
# last day of Julian Calendar (Thursday)
d1 = DatetimeJulian(1582, 10, 4, 12)
d2 = DatetimeGregorian(1582, 10, 4, 12)
assert (d1.dayofwk == d2.dayofwk == 3)
assert (d1.dayofyr == d2.dayofyr == 277)
# Monday in proleptic gregorian calendar
d1 = DatetimeProlepticGregorian(1582, 10, 4, 12)
d2 = real_datetime(1582,10,4,12)
assert (d1.dayofwk == d2.dayofwk == 0)
def invalid_day():
DatetimeGregorian(1, 1, 32) + self.delta
# subtracting datetime.datetime from cftime.datetime
delta = self.date3_gregorian - self.datetime_date1
# real_date2 and real_date1 are exactly one day apart
self.assertEqual(total_seconds(delta), -86400)
# Test the Julian/Gregorian transition.
self.assertEqual(self.date5_gregorian - self.delta,
DatetimeGregorian(1582, 10, 3, 23))
# The proleptic Gregorian calendar does not have invalid dates.
self.assertEqual(self.date6_proleptic_gregorian - self.delta,
DatetimeProlepticGregorian(1582, 10, 13, 23))
# The Gregorian calendar has no year zero.
self.assertEqual(DatetimeGregorian(1, 1, 1) - self.delta,
DatetimeGregorian(-1, 12, 30, 23))
# The 360_day calendar has year zero.
self.assertEqual(self.date7_360_day - timedelta(days=2000 * 360),
Datetime360Day(0, 1, 1))
# Test going over the year boundary.
self.assertEqual(DatetimeGregorian(2000, 3, 1) - timedelta(days=29 + 31 + 31),
DatetimeGregorian(1999, 12, 1))
# Year 2000 is a leap year.
self.assertEqual(DatetimeGregorian(2000, 3, 1) - self.delta,
DatetimeGregorian(2000, 2, 28, 23))
def invalid_sub_1():
self.date1_365_day - 1
# Test going over the year boundary.
self.assertEqual(DatetimeGregorian(2000, 11, 1) + timedelta(days=30 + 31),
DatetimeGregorian(2001, 1, 1))
# Year 2000 is a leap year.
self.assertEqual(DatetimeGregorian(2000, 1, 1) + timedelta(days=31 + 29),
DatetimeGregorian(2000, 3, 1))
# Test the 366_day calendar.
self.assertEqual(DatetimeAllLeap(1, 1, 1) + timedelta(days=366 * 10 + 31),
DatetimeAllLeap(11, 2, 1))
# The Gregorian calendar has no year zero.
self.assertEqual(DatetimeGregorian(-1, 12, 31) + self.delta,
DatetimeGregorian(1, 1, 1, 1))
def invalid_add_1():
self.date1_365_day + 1
def invalid_add_2():
1 + self.date1_365_day
for func in [invalid_add_1, invalid_add_2]:
self.assertRaises(TypeError, func)
assert (d.minute == 0)
assert (d.second == 0)
# test dayofwk, dayofyr attribute setting (cftime issue #13)
d1 = DatetimeGregorian(2020,2,29)
d2 = real_datetime(2020,2,29)
assert (d1.dayofwk == d2.dayofwk == 5)
assert (d1.dayofyr == d2.dayofyr == 60)
d1 = DatetimeGregorian(2020,2,29,23,59,59)
d2 = real_datetime(2020,2,29,23,59,59)
assert (d1.dayofwk == d2.dayofwk == 5)
assert (d1.dayofyr == d2.dayofyr == 60)
d1 = DatetimeGregorian(2020,2,28,23,59,59)
d2 = real_datetime(2020,2,28,23,59,59)
assert (d1.dayofwk == d2.dayofwk == 4)
assert (d1.dayofyr == d2.dayofyr == 59)
d1 = DatetimeGregorian(1700,1,1)
d2 = real_datetime(1700,1,1)
assert (d1.dayofwk == d2.dayofwk == 4)
assert (d1.dayofyr == d2.dayofyr == 1)
# last day of Julian Calendar (Thursday)
d1 = DatetimeJulian(1582, 10, 4, 12)
d2 = DatetimeGregorian(1582, 10, 4, 12)
assert (d1.dayofwk == d2.dayofwk == 3)
assert (d1.dayofyr == d2.dayofyr == 277)
# Monday in proleptic gregorian calendar
d1 = DatetimeProlepticGregorian(1582, 10, 4, 12)
d2 = real_datetime(1582,10,4,12)
assert (d1.dayofwk == d2.dayofwk == 0)
assert (d1.dayofyr == d2.dayofyr == 277)
# issue 71: negative reference years
# https://coastwatch.pfeg.noaa.gov/erddap/convert/time.html
# gives 2446433 (365 days more - is it counting year 0?)
def invalid_year():
DatetimeGregorian(0, 1, 1) + self.delta
assert (d1.dayofyr == d2.dayofyr == 60)
d1 = DatetimeGregorian(2020,2,29,23,59,59)
d2 = real_datetime(2020,2,29,23,59,59)
assert (d1.dayofwk == d2.dayofwk == 5)
assert (d1.dayofyr == d2.dayofyr == 60)
d1 = DatetimeGregorian(2020,2,28,23,59,59)
d2 = real_datetime(2020,2,28,23,59,59)
assert (d1.dayofwk == d2.dayofwk == 4)
assert (d1.dayofyr == d2.dayofyr == 59)
d1 = DatetimeGregorian(1700,1,1)
d2 = real_datetime(1700,1,1)
assert (d1.dayofwk == d2.dayofwk == 4)
assert (d1.dayofyr == d2.dayofyr == 1)
# last day of Julian Calendar (Thursday)
d1 = DatetimeJulian(1582, 10, 4, 12)
d2 = DatetimeGregorian(1582, 10, 4, 12)
assert (d1.dayofwk == d2.dayofwk == 3)
assert (d1.dayofyr == d2.dayofyr == 277)
# Monday in proleptic gregorian calendar
d1 = DatetimeProlepticGregorian(1582, 10, 4, 12)
d2 = real_datetime(1582,10,4,12)
assert (d1.dayofwk == d2.dayofwk == 0)
assert (d1.dayofyr == d2.dayofyr == 277)
# issue 71: negative reference years
# https://coastwatch.pfeg.noaa.gov/erddap/convert/time.html
# gives 2446433 (365 days more - is it counting year 0?)
# however http://aa.usno.navy.mil/data/docs/JulianDate.php gives
# 2446068, which agrees with us
units = "days since -4713-01-01T00:00:00Z"
t = date2num(datetime(1985,1,2), units, calendar="standard")
assert_almost_equal(t, 2446068)
def invalid_gregorian_date():
DatetimeGregorian(1582, 10, 5) + self.delta
# The proleptic Gregorian calendar does not have invalid dates.
self.assertEqual(self.date6_proleptic_gregorian - self.delta,
DatetimeProlepticGregorian(1582, 10, 13, 23))
# The Gregorian calendar has no year zero.
self.assertEqual(DatetimeGregorian(1, 1, 1) - self.delta,
DatetimeGregorian(-1, 12, 30, 23))
# The 360_day calendar has year zero.
self.assertEqual(self.date7_360_day - timedelta(days=2000 * 360),
Datetime360Day(0, 1, 1))
# Test going over the year boundary.
self.assertEqual(DatetimeGregorian(2000, 3, 1) - timedelta(days=29 + 31 + 31),
DatetimeGregorian(1999, 12, 1))
# Year 2000 is a leap year.
self.assertEqual(DatetimeGregorian(2000, 3, 1) - self.delta,
DatetimeGregorian(2000, 2, 28, 23))
def invalid_sub_1():
self.date1_365_day - 1
def invalid_sub_2():
1 - self.date1_365_day
def invalid_sub_3():
self.date1_365_day - self.datetime_date1
def invalid_sub_4():