Example #1
0
def test_dmy_julian_day(feb3_noon):
    dmy_struct = ffi.new("dmy_struct *")
    expected = feb3_noon
    for cal in ['julian', 'standard', 'gregorian', 'proleptic_gregorian']:
        expected_jd = JulianDayFromDate(expected, calendar=cal)
        vic_lib.dmy_julian_day(expected_jd, calendars[cal], dmy_struct)
        actual = dmy_to_datetime(dmy_struct)
        # assert that the difference is less than one second
        assert abs(expected - actual) < datetime.timedelta(seconds=1)
Example #2
0
def test_dmy_julian_day(feb3_noon):
    dmy_struct = ffi.new("dmy_struct *")
    expected = feb3_noon
    for cal in ['julian', 'standard', 'gregorian', 'proleptic_gregorian']:
        expected_jd = JulianDayFromDate(expected, calendar=cal)
        vic_lib.dmy_julian_day(expected_jd, calendars[cal], dmy_struct)
        actual = dmy_to_datetime(dmy_struct)
        # assert that the difference is less than one second
        assert abs(expected - actual) < datetime.timedelta(seconds=1)
Example #3
0
def test_dmy_julian_day_timeseries():
    # Regression test for GH298, updated to handle all standard calendars
    dmy_struct = ffi.new("dmy_struct *")

    for cal in ['standard', 'gregorian', 'proleptic_gregorian']:
        dates = pd.date_range('1970-01-01', '1975-12-31', freq='6H').to_pydatetime()
        for expected in dates:
            expected_jday = JulianDayFromDate(expected)
            vic_lib.dmy_julian_day(expected_jday, calendars[cal], dmy_struct)
            actual = dmy_to_datetime(dmy_struct)
            print(cal, expected_jday, expected, actual)
            # assert that the difference is less than one second
            assert abs(expected - actual) < datetime.timedelta(seconds=1)
Example #4
0
def test_dmy_julian_day_timeseries():
    # Regression test for GH298, updated to handle all standard calendars
    dmy_struct = ffi.new("dmy_struct *")

    for cal in ['standard', 'gregorian', 'proleptic_gregorian']:
        dates = pd.date_range('1970-01-01', '1975-12-31', freq='6H').to_pydatetime()
        for expected in dates:
            expected_jday = JulianDayFromDate(expected)
            vic_lib.dmy_julian_day(expected_jday, calendars[cal], dmy_struct)
            actual = dmy_to_datetime(dmy_struct)
            print(cal, expected_jday, expected, actual)
            # assert that the difference is less than one second
            assert abs(expected - actual) < datetime.timedelta(seconds=1)