Beispiel #1
0
    def setUp(self):
        self.date = Date('1955/05/21')

        self.obs = obs = Observer()
        obs.lat, obs.lon, obs.elev = '33:45:10', '-84:23:37', 320.0
        obs.date = '1997/2/15'

        # Avoid seeing the deprecation warning for old attributes.
        warnings.filterwarnings('ignore', '.', DeprecationWarning)
Beispiel #2
0
 def test_date_parser_error_message(self):
     with self.assertRaises(ValueError) as e:
         Date('bad string')
     self.assertEqual(
         str(e.exception),
         "your date string 'bad string' does"
         " not look like a year/month/day optionally"
         " followed by hours:minutes:seconds",
     )
Beispiel #3
0
 def test_EarthSatellite(self):
     self.build(bodytype=EarthSatellite,
                dbentry=('HST                     ',
                         '1 20580U 90037B   04296.45910607  .00000912 '
                         ' 00000-0  59688-4 0  1902',
                         '2 20580  28.4694  17.3953 0004117 265.2946  '
                         '94.7172 14.99359833594524'),
                attributes={
                    'name': 'Hubble Telescope',
                    '_epoch': Date('2004') + 296.45910607 - 1,
                    '_decay': .00000912,
                    '_drag': .59688e-4,
                    '_inc': 28.4694,
                    '_raan': 17.3953,
                    '_e': 4117e-7,
                    '_ap': 265.2946,
                    '_M': 94.7172,
                    '_n': 14.99359833,
                    '_orbit': 59452,
                })
Beispiel #4
0
 def __new__(cls, *args): return Date.__new__(cls, *args)
 
 def __sub__(self, other): return TimeDelta(super(DateTime, self).__sub__(other))
Beispiel #5
0
class DateTests(unittest.TestCase):
    def setUp(self):
        self.date = Date('2004/09/04 00:17:15.8')

    def test_date_constructor(self):
        def construct_and_compare(args1, args2):
            d1, d2 = Date(args1), Date(args2)
            self.assertTrue(
                abs(d1 - d2) < millisecond,
                'dates not equal:\n %r = date%r\n %r = date%r' %
                (d1.tuple(), args1, d2.tuple(), args2))

        std = '2004/09/04 00:17:15.8'
        pairs = [
            [std, '2004.67489614324023472'],
            [std, '   2004.67489614324023472 '],
            [std, '2004/9/4.0119884259259257'],
            [std, ' 2004/9/4.0119884259259257  '],
            [std, '2004/9/4 0.28772222222222221'],
            [std, ' 2004/9/4 0.28772222222222221 '],
            [std, '2004/9/4 0:17.263333333333332'],
            [std, '    2004/9/4 0:17.263333333333332  '],
            [std, '2004/9/4 0:17:15.8'],
            [std, '  2004/9/4 0:17:15.8 '],
            [std, '  2004-9-4 0:17:15.8 '],
            ['2004', (2004, )],
            ['  2004 ', (2004, )],
            ['2004/09', (2004, 9)],
            [' 2004/09  ', (2004, 9)],
            [std, (2004, 9, 4.0119884259259257)],
            [std, (2004, 9, 4, 0.28772222222222221)],
            [std, (2004, 9, 4, 0, 17.263333333333332)],
            [std, (2004, 9, 4, 0, 17, 15.8)],
            [std, (datetime(2004, 9, 4, 0, 17, 15, 800000))],
        ]
        for arg1, arg2 in pairs:
            construct_and_compare(arg1, arg2)
            if type(arg2) is str:
                construct_and_compare(arg1, '  %s  ' % arg2)

    def test_date_parser_error_message(self):
        with self.assertRaises(ValueError) as e:
            Date('bad string')
        self.assertEqual(
            str(e.exception),
            "your date string 'bad string' does"
            " not look like a year/month/day optionally"
            " followed by hours:minutes:seconds",
        )

    def test_year_zero(self):
        # I would have thought the year would be 0, but it looks like
        # libastro considers 1 BC to be the year -1?
        self.assertEqual(str(Date('0')), '-1/1/1 00:00:00')

    def test_date_string_value(self):
        self.assertEqual(str(self.date), '2004/9/4 00:17:16')

    def test_date_triple_value(self):
        self.assertEqual(self.date.triple(), (2004, 9, 4.0119884259256651))

    def test_date_tuple_value(self):
        self.assertEqual(self.date.tuple(), (2004, 9, 4, 0, 17, 15.8))

    def test_another_tuple_value(self):
        #d = Date((1994, 7, 16, 20, 15, 0))
        d = Date(34530.34375)
        self.assertEqual(d.tuple(), (1994, 7, 16, 20, 15, 0))

    def test_tuple_that_rounded_to_negative_seconds(self):  # Github issue 223
        d = Date(44417.49999991596)
        self.assertEqual(d.tuple(), (2021, 8, 10, 23, 59, 59.992739))

    def test_localtime_modern(self):
        if time.timezone == 18000:  # test only works in Eastern time zone
            self.assertEqual(localtime(Date('2009/6/23 8:47')),
                             datetime(2009, 6, 23, 4, 47, 0))

    def test_timezone_aware_utc(self):
        timezoned_date = to_timezone(self.date, UTC)
        self.assertEqual(timezoned_date.tzinfo, UTC)
        self.assertEqual(timezoned_date.hour, 0)
        self.assertEqual(timezoned_date.minute, 17)
        self.assertEqual(timezoned_date.second, 15)
        self.assertEqual(timezoned_date.day, 4)
        self.assertEqual(timezoned_date.month, 9)
        self.assertEqual(timezoned_date.year, 2004)

    def test_timezone_aware_cet(self):
        cet = CET()
        timezoned_date = to_timezone(self.date, cet)
        self.assertEqual(timezoned_date.tzinfo, cet)
        self.assertEqual(timezoned_date.hour, 1)
        self.assertEqual(timezoned_date.minute, 17)
        self.assertEqual(timezoned_date.second, 15)
        self.assertEqual(timezoned_date.day, 4)
        self.assertEqual(timezoned_date.month, 9)
        self.assertEqual(timezoned_date.year, 2004)

    # I am commenting this out for now because I am not sure that I can
    # fix it without either writing an entirely new time module for
    # PyEphem, or making PyEphem depend on another Python module - which
    # would be its first-ever external dependency.

    def OFF_test_localtime_premodern(self):
        if time.timezone == 18000:  # test only works in Eastern time zone
            self.assertEqual(localtime(Date('1531/8/24 2:49')),
                             datetime(1957, 10, 4, 15, 28, 34, 4))
Beispiel #6
0
 def test_localtime_modern(self):
     if time.timezone == 18000:  # test only works in Eastern time zone
         self.assertEqual(localtime(Date('2009/6/23 8:47')),
                          datetime(2009, 6, 23, 4, 47, 0))
Beispiel #7
0
 def setUp(self):
     self.date = Date('2004/09/04 00:17:15.8')
Beispiel #8
0
 def construct_and_compare(args1, args2):
     d1, d2 = Date(*args1), Date(*args2)
     self.assert_(
         -1e-15 < (d1 / d2 - 1) < 1e-15,
         'dates not equal:\n %r = date%r\n %r = date%r' %
         (d1.tuple(), args1, d2.tuple(), args2))
Beispiel #9
0
 def construct_and_compare(args1, args2):
     d1, d2 = Date(*args1), Date(*args2)
     self.assert_(-1e-15 < (d1 / d2 - 1) < 1e-15,
                  'dates not equal:\n %r = date%r\n %r = date%r'
                  % (d1.tuple(), args1, d2.tuple(), args2))
Beispiel #10
0
    def test_new_moon_list(self):
        startDate = Date('1983/12/1')
        endDate = Date('1984/12/23')

        newmoons = find_new_moon_between(startDate, endDate)
Beispiel #11
0
 def test_when_sun_is_at_degree(self):
     startDate = Date('1983/12/1')
     print(when_is_sun_at_degrees_longitude(startDate, 0))
Beispiel #12
0
 def test_find_solar_terms_between(self):
     startDate = Date("1983/12/1")
     endDate = Date('1984/12/23')
     terms = find_solar_terms_between(startDate, endDate)
     for x in terms:
         print(Date(x))
Beispiel #13
0
 def test_tuple_that_rounded_to_negative_seconds(self):  # Github issue 223
     d = Date(44417.49999991596)
     self.assertEqual(d.tuple(), (2021, 8, 10, 23, 59, 59.992739))
Beispiel #14
0
 def test_another_tuple_value(self):
     #d = Date((1994, 7, 16, 20, 15, 0))
     d = Date(34530.34375)
     self.assertEqual(d.tuple(), (1994, 7, 16, 20, 15, 0))
Beispiel #15
0
class DateTests(unittest.TestCase):
    def setUp(self):
        self.date = Date('2004/09/04 00:17:15.8')

    def test_date_constructor(self):
        def construct_and_compare(args1, args2):
            d1, d2 = Date(args1), Date(args2)
            self.assertTrue(
                abs(d1 - d2) < millisecond,
                'dates not equal:\n %r = date%r\n %r = date%r' %
                (d1.tuple(), args1, d2.tuple(), args2))

        std = '2004/09/04 00:17:15.8'
        pairs = [
            [std, '2004.67489614324023472'],
            [std, '   2004.67489614324023472 '],
            [std, '2004/9/4.0119884259259257'],
            [std, ' 2004/9/4.0119884259259257  '],
            [std, '2004/9/4 0.28772222222222221'],
            [std, ' 2004/9/4 0.28772222222222221 '],
            [std, '2004/9/4 0:17.263333333333332'],
            [std, '    2004/9/4 0:17.263333333333332  '],
            [std, '2004/9/4 0:17:15.8'],
            [std, '  2004/9/4 0:17:15.8 '],
            [std, '  2004-9-4 0:17:15.8 '],
            ['2004', (2004, )],
            ['  2004 ', (2004, )],
            ['2004/09', (2004, 9)],
            [' 2004/09  ', (2004, 9)],
            [std, (2004, 9, 4.0119884259259257)],
            [std, (2004, 9, 4, 0.28772222222222221)],
            [std, (2004, 9, 4, 0, 17.263333333333332)],
            [std, (2004, 9, 4, 0, 17, 15.8)],
            [std, (datetime(2004, 9, 4, 0, 17, 15, 800000))],
        ]
        for arg1, arg2 in pairs:
            construct_and_compare(arg1, arg2)
            if type(arg2) is str:
                construct_and_compare(arg1, '  %s  ' % arg2)

    def test_year_zero(self):
        # I would have thought the year would be 0, but it looks like
        # libastro considers 1 BC to be the year -1?
        self.assertEqual(str(Date('0')), '-1/1/1 00:00:00')

    def test_date_string_value(self):
        self.assertEqual(str(self.date), '2004/9/4 00:17:16')

    def test_date_triple_value(self):
        self.assertEqual(self.date.triple(), (2004, 9, 4.0119884259256651))

    def test_date_tuple_value(self):
        self.assertEqual(self.date.tuple(),
                         (2004, 9, 4, 0, 17, 15.799999977461994))

    def test_localtime_modern(self):
        if time.timezone == 18000:  # test only works in Eastern time zone
            self.assertEqual(localtime(Date('2009/6/23 8:47')),
                             datetime(2009, 6, 23, 4, 47, 0))

    def test_timezone_aware_utc(self):
        timezoned_date = to_timezone(self.date, UTC)
        self.assertEqual(timezoned_date.tzinfo, UTC)
        self.assertEqual(timezoned_date.hour, 0)
        self.assertEqual(timezoned_date.minute, 17)
        self.assertEqual(timezoned_date.second, 15)
        self.assertEqual(timezoned_date.day, 4)
        self.assertEqual(timezoned_date.month, 9)
        self.assertEqual(timezoned_date.year, 2004)

    def test_timezone_aware_cet(self):
        cet = CET()
        timezoned_date = to_timezone(self.date, cet)
        self.assertEqual(timezoned_date.tzinfo, cet)
        self.assertEqual(timezoned_date.hour, 1)
        self.assertEqual(timezoned_date.minute, 17)
        self.assertEqual(timezoned_date.second, 15)
        self.assertEqual(timezoned_date.day, 4)
        self.assertEqual(timezoned_date.month, 9)
        self.assertEqual(timezoned_date.year, 2004)

    # I am commenting this out for now because I am not sure that I can
    # fix it without either writing an entirely new time module for
    # PyEphem, or making PyEphem depend on another Python module - which
    # would be its first-ever external dependency.

    def OFF_test_localtime_premodern(self):
        if time.timezone == 18000:  # test only works in Eastern time zone
            self.assertEqual(localtime(Date('1531/8/24 2:49')),
                             datetime(1957, 10, 4, 15, 28, 34, 4))
Beispiel #16
0
 def test_year_zero(self):
     # I would have thought the year would be 0, but it looks like
     # libastro considers 1 BC to be the year -1?
     self.assertEqual(str(Date('0')), '-1/1/1 00:00:00')
Beispiel #17
0
class DateTests(unittest.TestCase):
    def setUp(self):
        self.date = Date('2004/09/04 00:17:15.8')

    def test_date_constructor(self):

        def construct_and_compare(args1, args2):
            d1, d2 = Date(args1), Date(args2)
            self.assertTrue(abs(d1 - d2) < millisecond,
                            'dates not equal:\n %r = date%r\n %r = date%r'
                            % (d1.tuple(), args1, d2.tuple(), args2))

        std = '2004/09/04 00:17:15.8'
        pairs = [
            [std, '2004.67489614324023472'],
            [std, '   2004.67489614324023472 '],
            [std, '2004/9/4.0119884259259257'],
            [std, ' 2004/9/4.0119884259259257  '],
            [std, '2004/9/4 0.28772222222222221'],
            [std, ' 2004/9/4 0.28772222222222221 '],
            [std, '2004/9/4 0:17.263333333333332'],
            [std, '    2004/9/4 0:17.263333333333332  '],
            [std, '2004/9/4 0:17:15.8'],
            [std, '  2004/9/4 0:17:15.8 '],
            [std, '  2004-9-4 0:17:15.8 '],
            ['2004', (2004,)],
            ['  2004 ', (2004,)],
            ['2004/09', (2004, 9)],
            [' 2004/09  ', (2004, 9)],
            [std, (2004, 9, 4.0119884259259257)],
            [std, (2004, 9, 4, 0.28772222222222221)],
            [std, (2004, 9, 4, 0, 17.263333333333332)],
            [std, (2004, 9, 4, 0, 17, 15.8)],
            [std, (datetime(2004, 9, 4, 0, 17, 15, 800000))],
            ]
        for arg1, arg2 in pairs:
            construct_and_compare(arg1, arg2)
            if type(arg2) is str:
                construct_and_compare(arg1, '  %s  ' % arg2)

    def test_date_string_value(self):
        self.assertEqual(str(self.date), '2004/9/4 00:17:16')

    def test_date_triple_value(self):
        self.assertEqual(self.date.triple(), (2004, 9, 4.0119884259256651))

    def test_date_tuple_value(self):
        self.assertEqual(self.date.tuple(),
                         (2004, 9, 4, 0, 17, 15.799999977461994))

    def test_localtime_modern(self):
        if time.timezone == 18000: # test only works in Eastern time zone
            self.assertEqual(localtime(Date('2009/6/23 8:47')),
                             datetime(2009, 6, 23, 4, 47, 0, 1))

    # I am commenting this out for now because I am not sure that I can
    # fix it without either writing an entirely new time module for
    # PyEphem, or making PyEphem depend on another Python module - which
    # would be its first-ever external dependency.

    def OFF_test_localtime_premodern(self):
        if time.timezone == 18000: # test only works in Eastern time zone
            self.assertEqual(localtime(Date('1531/8/24 2:49')),
                             datetime(1957, 10, 4, 15, 28, 34, 4))
Beispiel #18
0
class DateTests(unittest.TestCase):
    def setUp(self):
        self.date = Date('2004/09/04 00:17:15.8')

    def test_date_constructor(self):
        def construct_and_compare(args1, args2):
            d1, d2 = Date(args1), Date(args2)
            self.assertTrue(
                abs(d1 - d2) < millisecond,
                'dates not equal:\n %r = date%r\n %r = date%r' %
                (d1.tuple(), args1, d2.tuple(), args2))

        std = '2004/09/04 00:17:15.8'
        pairs = [
            [std, '2004.67489614324023472'],
            [std, '   2004.67489614324023472 '],
            [std, '2004/9/4.0119884259259257'],
            [std, ' 2004/9/4.0119884259259257  '],
            [std, '2004/9/4 0.28772222222222221'],
            [std, ' 2004/9/4 0.28772222222222221 '],
            [std, '2004/9/4 0:17.263333333333332'],
            [std, '    2004/9/4 0:17.263333333333332  '],
            [std, '2004/9/4 0:17:15.8'],
            [std, '  2004/9/4 0:17:15.8 '],
            [std, '  2004-9-4 0:17:15.8 '],
            ['2004', (2004, )],
            ['  2004 ', (2004, )],
            ['2004/09', (2004, 9)],
            [' 2004/09  ', (2004, 9)],
            [std, (2004, 9, 4.0119884259259257)],
            [std, (2004, 9, 4, 0.28772222222222221)],
            [std, (2004, 9, 4, 0, 17.263333333333332)],
            [std, (2004, 9, 4, 0, 17, 15.8)],
            [std, (datetime(2004, 9, 4, 0, 17, 15, 800000))],
        ]
        for arg1, arg2 in pairs:
            construct_and_compare(arg1, arg2)
            if type(arg2) is str:
                construct_and_compare(arg1, '  %s  ' % arg2)

    def test_date_string_value(self):
        self.assertEqual(str(self.date), '2004/9/4 00:17:16')

    def test_date_triple_value(self):
        self.assertEqual(self.date.triple(), (2004, 9, 4.0119884259256651))

    def test_date_tuple_value(self):
        self.assertEqual(self.date.tuple(),
                         (2004, 9, 4, 0, 17, 15.799999977461994))

    def test_localtime_modern(self):
        if time.timezone == 18000:  # test only works in Eastern time zone
            self.assertEqual(localtime(Date('2009/6/23 8:47')),
                             datetime(2009, 6, 23, 4, 47, 0))

    # I am commenting this out for now because I am not sure that I can
    # fix it without either writing an entirely new time module for
    # PyEphem, or making PyEphem depend on another Python module - which
    # would be its first-ever external dependency.

    def OFF_test_localtime_premodern(self):
        if time.timezone == 18000:  # test only works in Eastern time zone
            self.assertEqual(localtime(Date('1531/8/24 2:49')),
                             datetime(1957, 10, 4, 15, 28, 34, 4))
Beispiel #19
0
 def setUp(self):
     self.date = Date('2004/09/04 00:17:15.8')
Beispiel #20
0
 def construct_and_compare(args1, args2):
     d1, d2 = Date(args1), Date(args2)
     self.assertTrue(
         abs(d1 - d2) < millisecond,
         'dates not equal:\n %r = date%r\n %r = date%r' %
         (d1.tuple(), args1, d2.tuple(), args2))
Beispiel #21
0
 def construct_and_compare(args1, args2):
     d1, d2 = Date(args1), Date(args2)
     self.assertTrue(abs(d1 - d2) < millisecond,
                     'dates not equal:\n %r = date%r\n %r = date%r'
                     % (d1.tuple(), args1, d2.tuple(), args2))
Beispiel #22
0
 def OFF_test_localtime_premodern(self):
     if time.timezone == 18000:  # test only works in Eastern time zone
         self.assertEqual(localtime(Date('1531/8/24 2:49')),
                          datetime(1957, 10, 4, 15, 28, 34, 4))
Beispiel #23
0
class DateTests(unittest.TestCase):

    def setUp(self):
        self.date = Date('2004/09/04 00:17:15.8')

    def test_date_constructor(self):

        def construct_and_compare(args1, args2):
            d1, d2 = Date(args1), Date(args2)
            self.assertTrue(abs(d1 - d2) < millisecond,
                            'dates not equal:\n %r = date%r\n %r = date%r'
                            % (d1.tuple(), args1, d2.tuple(), args2))

        std = '2004/09/04 00:17:15.8'
        pairs = [
            [std, '2004.67489614324023472'],
            [std, '   2004.67489614324023472 '],
            [std, '2004/9/4.0119884259259257'],
            [std, ' 2004/9/4.0119884259259257  '],
            [std, '2004/9/4 0.28772222222222221'],
            [std, ' 2004/9/4 0.28772222222222221 '],
            [std, '2004/9/4 0:17.263333333333332'],
            [std, '    2004/9/4 0:17.263333333333332  '],
            [std, '2004/9/4 0:17:15.8'],
            [std, '  2004/9/4 0:17:15.8 '],
            [std, '  2004-9-4 0:17:15.8 '],
            ['2004', (2004,)],
            ['  2004 ', (2004,)],
            ['2004/09', (2004, 9)],
            [' 2004/09  ', (2004, 9)],
            [std, (2004, 9, 4.0119884259259257)],
            [std, (2004, 9, 4, 0.28772222222222221)],
            [std, (2004, 9, 4, 0, 17.263333333333332)],
            [std, (2004, 9, 4, 0, 17, 15.8)],
            [std, (datetime(2004, 9, 4, 0, 17, 15, 800000))],
            ]
        for arg1, arg2 in pairs:
            construct_and_compare(arg1, arg2)
            if type(arg2) is str:
                construct_and_compare(arg1, '  %s  ' % arg2)

    def test_year_zero(self):
        # I would have thought the year would be 0, but it looks like
        # libastro considers 1 BC to be the year -1?
        self.assertEqual(str(Date('0')), '-1/1/1 00:00:00')

    def test_date_string_value(self):
        self.assertEqual(str(self.date), '2004/9/4 00:17:16')

    def test_date_triple_value(self):
        self.assertEqual(self.date.triple(), (2004, 9, 4.0119884259256651))

    def test_date_tuple_value(self):
        self.assertEqual(self.date.tuple(),
                         (2004, 9, 4, 0, 17, 15.799999977461994))

    def test_localtime_modern(self):
        if time.timezone == 18000: # test only works in Eastern time zone
            self.assertEqual(localtime(Date('2009/6/23 8:47')),
                             datetime(2009, 6, 23, 4, 47, 0))

    def test_timezone_aware_utc(self):
        timezoned_date = to_timezone(self.date, UTC)
        self.assertEqual(timezoned_date.tzinfo, UTC)
        self.assertEqual(timezoned_date.hour, 0)
        self.assertEqual(timezoned_date.minute, 17)
        self.assertEqual(timezoned_date.second, 15)
        self.assertEqual(timezoned_date.day, 4)
        self.assertEqual(timezoned_date.month, 9)
        self.assertEqual(timezoned_date.year, 2004)

    def test_timezone_aware_cet(self):
        cet = CET()
        timezoned_date = to_timezone(self.date, cet)
        self.assertEqual(timezoned_date.tzinfo, cet)
        self.assertEqual(timezoned_date.hour, 1)
        self.assertEqual(timezoned_date.minute, 17)
        self.assertEqual(timezoned_date.second, 15)
        self.assertEqual(timezoned_date.day, 4)
        self.assertEqual(timezoned_date.month, 9)
        self.assertEqual(timezoned_date.year, 2004)

    # I am commenting this out for now because I am not sure that I can
    # fix it without either writing an entirely new time module for
    # PyEphem, or making PyEphem depend on another Python module - which
    # would be its first-ever external dependency.

    def OFF_test_localtime_premodern(self):
        if time.timezone == 18000: # test only works in Eastern time zone
            self.assertEqual(localtime(Date('1531/8/24 2:49')),
                             datetime(1957, 10, 4, 15, 28, 34, 4))