Ejemplo n.º 1
0
    def test_timezone(self):
        # Verify that the time zone of `start` determines the time zone of generated times.
        tz_ny = moment.tzinfo("America/New_York")
        self.assertEqual([
            d.isoformat(' ') for d in schedule.SCHEDULE(
                "daily: 9am",
                count=4,
                start=datetime(2018, 2, 14, tzinfo=tz_ny))
        ], [
            '2018-02-14 09:00:00-05:00', '2018-02-15 09:00:00-05:00',
            '2018-02-16 09:00:00-05:00', '2018-02-17 09:00:00-05:00'
        ])

        tz_la = moment.tzinfo("America/Los_Angeles")
        self.assertEqual([
            d.isoformat(' ') for d in schedule.SCHEDULE(
                "daily: 9am, 4:30pm",
                count=4,
                start=datetime(2018, 2, 14, 9, 0, tzinfo=tz_la))
        ], [
            '2018-02-14 09:00:00-08:00', '2018-02-14 16:30:00-08:00',
            '2018-02-15 09:00:00-08:00', '2018-02-15 16:30:00-08:00'
        ])

        tz_utc = moment.tzinfo("UTC")
        self.assertEqual([
            d.isoformat(' ') for d in schedule.SCHEDULE(
                "daily: 9am, 4:30pm",
                count=4,
                start=datetime(2018, 2, 14, 17, 0, tzinfo=tz_utc))
        ], [
            '2018-02-15 09:00:00+00:00', '2018-02-15 16:30:00+00:00',
            '2018-02-16 09:00:00+00:00', '2018-02-16 16:30:00+00:00'
        ])
Ejemplo n.º 2
0
    def test_round_down_to_unit_tz(self):
        RDU = schedule._round_down_to_unit
        dt = datetime(2018,
                      1,
                      1,
                      0,
                      0,
                      0,
                      tzinfo=moment.tzinfo("America/New_York"))
        self.assertDateIso(RDU(dt, "years"), "2018-01-01 00:00:00-05:00")
        self.assertDateIso(RDU(dt - TICK, "years"),
                           "2017-01-01 00:00:00-05:00")

        self.assertDateIso(RDU(dt, "months"), "2018-01-01 00:00:00-05:00")
        self.assertDateIso(RDU(dt - TICK, "months"),
                           "2017-12-01 00:00:00-05:00")

        # 2018-01-01 is a Monday
        self.assertDateIso(RDU(dt, "weeks"), "2017-12-31 00:00:00-05:00")
        self.assertDateIso(RDU(dt - timedelta(days=1) - TICK, "weeks"),
                           "2017-12-24 00:00:00-05:00")

        self.assertDateIso(RDU(dt, "days"), "2018-01-01 00:00:00-05:00")
        self.assertDateIso(RDU(dt - TICK, "days"), "2017-12-31 00:00:00-05:00")

        self.assertDateIso(RDU(dt, "hours"), "2018-01-01 00:00:00-05:00")
        self.assertDateIso(RDU(dt - TICK, "hours"),
                           "2017-12-31 23:00:00-05:00")
Ejemplo n.º 3
0
 def test_zone(self):
     name = "America/New_York"
     tzinfo = moment.tzinfo(name)
     data = self.new_york
     for entry in data:
         date = entry[0]
         ts = entry[1]
         abbr = entry[2]
         offset = entry[3]
         dt = moment.tz(ts, name).datetime()
         self.assertEqual(dt.tzname(), abbr)
         self.assertEqual(dt.utcoffset(), timedelta(minutes=-offset))
Ejemplo n.º 4
0
 def tzinfo(rec, table):
     # pylint: disable=no-self-use
     try:
         return moment.tzinfo(rec.timezone)
     except KeyError:
         return moment.TZ_UTC
Ejemplo n.º 5
0
 def setUpClass(cls):
     global _orig_global_tz_getter  # pylint: disable=global-statement
     _orig_global_tz_getter = _date._get_global_tz
     _date._get_global_tz = lambda: moment.tzinfo('America/New_York')
Ejemplo n.º 6
0
def date_setUp(doc_test):
    # pylint: disable=unused-argument
    global _old_date_get_global_tz  # pylint: disable=global-statement
    _old_date_get_global_tz = functions.date._get_global_tz
    functions.date._get_global_tz = lambda: moment.tzinfo('America/New_York')
Ejemplo n.º 7
0
    def test_record_date_options(self):
        self.load_sample(testsamples.sample_students)
        self.add_column("Schools", "Foo", formula='RECORD(rec, expand_refs=1)')
        self.add_column("Address", "DT", type='DateTime')
        self.add_column("Address",
                        "D",
                        type='Date',
                        formula="$DT and $DT.date()")
        self.update_records("Address", ['id', 'DT'], [
            [11, 1600000000],
            [13, 1500000000],
        ])

        d1 = datetime.datetime(2020,
                               9,
                               13,
                               8,
                               26,
                               40,
                               tzinfo=moment.tzinfo('America/New_York'))
        d2 = datetime.datetime(2017,
                               7,
                               13,
                               22,
                               40,
                               tzinfo=moment.tzinfo('America/New_York'))
        self.assertPartialData("Schools", ["id", "Foo"], [
            [
                1, {
                    'address': {
                        'city': 'New York',
                        'DT': d1,
                        'id': 11,
                        'D': d1.date()
                    },
                    'id': 1,
                    'name': 'Columbia'
                }
            ],
            [
                2, {
                    'address': {
                        'city': 'Colombia',
                        'DT': None,
                        'id': 12,
                        'D': None
                    },
                    'id': 2,
                    'name': 'Columbia'
                }
            ],
            [
                3, {
                    'address': {
                        'city': 'New Haven',
                        'DT': d2,
                        'id': 13,
                        'D': d2.date()
                    },
                    'id': 3,
                    'name': 'Yale'
                }
            ],
            [
                4, {
                    'address': {
                        'city': 'West Haven',
                        'DT': None,
                        'id': 14,
                        'D': None
                    },
                    'id': 4,
                    'name': 'Yale'
                }
            ],
        ])

        self.modify_column(
            "Schools",
            "Foo",
            formula='RECORD(rec, expand_refs=1, dates_as_iso=True)')
        self.assertPartialData("Schools", ["id", "Foo"], [
            [
                1, {
                    'address': {
                        'city': 'New York',
                        'DT': d1.isoformat(),
                        'id': 11,
                        'D': d1.date().isoformat()
                    },
                    'id': 1,
                    'name': 'Columbia'
                }
            ],
            [
                2, {
                    'address': {
                        'city': 'Colombia',
                        'DT': None,
                        'id': 12,
                        'D': None
                    },
                    'id': 2,
                    'name': 'Columbia'
                }
            ],
            [
                3, {
                    'address': {
                        'city': 'New Haven',
                        'DT': d2.isoformat(),
                        'id': 13,
                        'D': d2.date().isoformat()
                    },
                    'id': 3,
                    'name': 'Yale'
                }
            ],
            [
                4, {
                    'address': {
                        'city': 'West Haven',
                        'DT': None,
                        'id': 14,
                        'D': None
                    },
                    'id': 4,
                    'name': 'Yale'
                }
            ],
        ])
Ejemplo n.º 8
0
def _get_tzinfo(zonelabel):
  """
  A helper that returns a `datetime.tzinfo` instance for zonelabel. Returns the global
  document timezone if zonelabel is None.
  """
  return moment.tzinfo(zonelabel) if zonelabel else _get_global_tz()