예제 #1
0
    def test_date_range_str_repr(self):

        self._check_rpr_and_str(
            DateRange(value=DateRangeBound(self.dt, 'SECOND')),
            '1990-02-03T13:58:45Z')

        self._check_rpr_and_str(
            DateRange(lower_bound=DateRangeBound(self.dt, 'SECOND'),
                      upper_bound=OPEN_BOUND), '[1990-02-03T13:58:45Z TO *]')

        self._check_rpr_and_str(
            DateRange(lower_bound=OPEN_BOUND,
                      upper_bound=DateRangeBound(self.dt, 'SECOND')),
            '[* TO 1990-02-03T13:58:45Z]')

        self._check_rpr_and_str(
            DateRange(lower_bound=OPEN_BOUND, upper_bound=OPEN_BOUND),
            '[* TO *]')

        self._check_rpr_and_str(
            DateRange(lower_bound=DateRangeBound(self.dt, 'SECOND'),
                      upper_bound=DateRangeBound(self.dt, 'YEAR')),
            '[1990-02-03T13:58:45Z TO 1990]')

        self._check_rpr_and_str(DateRange(value=OPEN_BOUND), '*')
예제 #2
0
 def test_from_dict_value(self):
     self.assertEqual(
         DateRangeBound(self.dt, 'DAY'),
         DateRangeBound.from_value({
             'milliseconds': self.dt,
             'precision': 'DAY'
         }))
예제 #3
0
 def test_bound_rounding_month(self):
     actual = _daterangebound_to_dict(
         DateRangeBound(self.dt,
                        precision=DateRangePrecision.MONTH).round_down())
     expected = {
         'milliseconds': 633830400000,
         'precision': DateRangePrecision.MONTH
     }
     self.assertEqual(actual, expected)
예제 #4
0
 def test_bound_rounding_year(self):
     actual = _daterangebound_to_dict(
         DateRangeBound(self.dt,
                        precision=DateRangePrecision.YEAR).round_down())
     expected = {
         'milliseconds': 631152000000,
         'precision': DateRangePrecision.YEAR
     }
     self.assertEqual(actual, expected)
예제 #5
0
 def test_bound_rounding_minute(self):
     actual = _daterangebound_to_dict(
         DateRangeBound(self.dt,
                        precision=DateRangePrecision.MINUTE).round_down())
     expected = {
         'milliseconds': 634053480000,
         'precision': DateRangePrecision.MINUTE
     }
     self.assertEqual(actual, expected)
예제 #6
0
 def test_bound_rounding_second(self):
     actual = _daterangebound_to_dict(
         DateRangeBound(self.dt,
                        precision=DateRangePrecision.SECOND).round_down())
     expected = {
         'milliseconds': 634053525000,
         'precision': DateRangePrecision.SECOND
     }
     self.assertEqual(actual, expected)
예제 #7
0
    def test_date_range_bound_str_repr(self):
        self._check_rpr_and_str(DateRangeBound.from_value((None, None)), '*')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'YEAR'), '1990')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'MONTH'), '1990-02')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'DAY'), '1990-02-03')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'HOUR'),
                                '1990-02-03T13Z')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'MINUTE'),
                                '1990-02-03T13:58Z')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'SECOND'),
                                '1990-02-03T13:58:45Z')

        self._check_rpr_and_str(DateRangeBound(self.dt, 'MILLISECOND'),
                                '1990-02-03T13:58:45.778Z')
예제 #8
0
    def test_comparison_operators(self):
        l = [
            DateRange(lower_bound=OPEN_BOUND, upper_bound=OPEN_BOUND),
            DateRange(lower_bound=OPEN_BOUND, upper_bound=OPEN_BOUND)
        ]
        check_sequence_consistency(self, l, equal=True)

        l = [
            DateRange(value=DateRangeBound(datetime.datetime(2014, 10, 1, 0),
                                           DateRangePrecision.YEAR)),
            DateRange(value=DateRangeBound(datetime.datetime(2014, 10, 2, 0),
                                           DateRangePrecision.YEAR)),
            DateRange(value=DateRangeBound(datetime.datetime(2014, 10, 3, 0),
                                           DateRangePrecision.YEAR))
        ]
        check_sequence_consistency(self, l, equal=True)

        l = [
            DateRange(value=DateRangeBound(datetime.datetime(2014, 10, 1, 0),
                                           DateRangePrecision.DAY)),
            DateRange(value=DateRangeBound(datetime.datetime(2014, 10, 2, 0),
                                           DateRangePrecision.DAY)),
            DateRange(value=DateRangeBound(datetime.datetime(2014, 10, 3, 0),
                                           DateRangePrecision.DAY))
        ]
        check_sequence_consistency(self, l)

        l = [
            DateRange(
                lower_bound=OPEN_BOUND,
                upper_bound=DateRangeBound(
                    datetime.datetime(2016, 1, 1, 10, 15, 15, 999000),
                    DateRangePrecision.MILLISECOND),
            ),
            DateRange(lower_bound=DateRangeBound(
                datetime.datetime(2015, 3, 1, 10, 15, 15, 10000),
                DateRangePrecision.MILLISECOND),
                      upper_bound=DateRangeBound(
                          datetime.datetime(2016, 1, 1, 10, 15, 30, 999000),
                          DateRangePrecision.MILLISECOND)),
            DateRange(lower_bound=DateRangeBound(
                datetime.datetime(2015, 3, 1, 10, 15, 16, 10000),
                DateRangePrecision.MILLISECOND),
                      upper_bound=OPEN_BOUND),
            DateRange(lower_bound=DateRangeBound(
                datetime.datetime(2015, 3, 1, 10, 15, 16, 10000),
                DateRangePrecision.MILLISECOND),
                      upper_bound=DateRangeBound(
                          datetime.datetime(2016, 1, 1, 10, 15, 30, 999000),
                          DateRangePrecision.MILLISECOND)),
            DateRange(lower_bound=DateRangeBound(
                datetime.datetime(2015, 3, 1, 10, 15, 16, 10000),
                DateRangePrecision.MILLISECOND),
                      upper_bound=DateRangeBound(
                          datetime.datetime(2016, 1, 1, 10, 15, 31, 999000),
                          DateRangePrecision.MILLISECOND))
        ]

        check_sequence_consistency(self, l)
예제 #9
0
 def test_daterange_with_negative_bound_str_repr(self):
     self._check_rpr_and_str(
         DateRange(lower_bound=DateRangeBound(
             self.smallest_datetime_timestamp - 1, 'MILLISECOND'),
                   upper_bound=DateRangeBound(self.dt, 'SECOND')),
         '[-62135596800001ms TO 1990-02-03T13:58:45Z]')
예제 #10
0
 def test_negative_daterangebound_str_repr(self):
     self._check_rpr_and_str(
         DateRangeBound(self.smallest_datetime_timestamp - 1,
                        'MILLISECOND'), '-62135596800001ms')
예제 #11
0
 def test_from_tuple_value(self):
     self.assertEqual(DateRangeBound(self.dt, 'DAY'),
                      DateRangeBound.from_value((self.dt, 'DAY')))
예제 #12
0
 def test_from_daterange_value(self):
     drb = DateRangeBound(self.dt, 'HOUR')
     self.assertEqual(drb, DateRangeBound.from_value(drb))
예제 #13
0
 def test_bound_requires_not_None_precision(self):
     with self.assertRaises(TypeError):
         DateRangeBound(datetime=self.dt, precision=None)
예제 #14
0
 def test_bound_requires_not_None_datetime(self):
     with self.assertRaises(TypeError):
         DateRangeBound(datetime=None, precision='YEAR')
예제 #15
0
def _new_date_range_bound(datetime, precision):
    millis = ms_timestamp_from_datetime(datetime)
    return DateRangeBound(value=millis, precision=precision)