def test_num2num_noleap(): times = numpy.array([datetime.datetime(1849, 12, 15, 12, 30, 30), datetime.datetime(1850, 1, 1, 0, 0, 0), datetime.datetime(1850, 2, 1, 15, 12, 0)]) units = "days since " + str(datetime.datetime(1830, 6, 6, 12, 0, 0)) calender = "noleap" ref = datetime.datetime(1850, 1, 1, 0, 0, 0) nums = netCDF4.date2num(times, units, calender) new_times, new_units = num2num(nums, ref, units, calender) eq_(new_times[1], 0.) eq_(new_units, "days since " + str(ref))
def test_num2num_proleptic_gregorian(): times = numpy.array([datetime.datetime(1849, 12, 15, 12, 30, 30), datetime.datetime(1850, 1, 1, 0, 0, 0), datetime.datetime(1850, 2, 1, 15, 12, 0)]) units = "hours since " + str(datetime.datetime(1830, 6, 6, 12, 0, 0)) calender = "gregorian" ref = datetime.datetime(1850, 1, 1, 0, 0, 0) nums = netCDF4.date2num(times, units, calender) new_times, new_units = num2num(nums, ref, units, calender) eq_(new_times[1], 0.) eq_(new_units, "hours since " + str(ref))
def test_num2num_gregorian(): times = numpy.array([ datetime.datetime(1849, 12, 15, 12, 30, 30), datetime.datetime(1850, 1, 1, 0, 0, 0), datetime.datetime(1850, 2, 1, 15, 12, 0) ]) units = "days since " + str(datetime.datetime(1830, 6, 6, 12, 0, 0)) calender = "gregorian" ref = datetime.datetime(1850, 1, 1, 0, 0, 0) nums = netCDF4.date2num(times, units, calender) new_times, new_units = num2num(nums, ref, units, calender) assert new_times[1] == 0. assert new_units == "days since " + str(ref)
def test_noleap_timeshift(): times = numpy.array([ datetime.datetime(1849, 12, 15, 12, 30, 30), datetime.datetime(1850, 1, 1, 0, 0, 0), datetime.datetime(1850, 2, 1, 15, 12, 0), datetime.datetime(1850, 4, 1, 0, 0, 0) ]) units = "days since " + str(datetime.datetime(1830, 6, 6, 12, 0, 0)) calender = "noleap" ref = datetime.datetime(1850, 1, 1, 0, 0, 0) shift = datetime.timedelta(days=30) nums = netCDF4.date2num(times, units, calender) new_times, new_units = num2num(nums, ref, units, calender, shift) assert new_times[3] == 60 assert new_units == "days since " + str(ref)