Example #1
0
 def test_compare_micros(self):
     zulu = timeutils.parse_isotime('2012-02-14T20:53:07.6544')
     east = timeutils.parse_isotime('2012-02-14T19:53:07.654321-01:00')
     west = timeutils.parse_isotime('2012-02-14T21:53:07.655+01:00')
     self.assertTrue(east < west)
     self.assertTrue(east < zulu)
     self.assertTrue(zulu < west)
Example #2
0
 def test_compare(self):
     zulu = timeutils.parse_isotime('2012-02-14T20:53:07')
     east = timeutils.parse_isotime('2012-02-14T20:53:07-01:00')
     west = timeutils.parse_isotime('2012-02-14T20:53:07+01:00')
     self.assertTrue(east > west)
     self.assertTrue(east > zulu)
     self.assertTrue(zulu > west)
Example #3
0
    def _get_filters(self, req):
        """Return a dictionary of query param filters from the request

        :param req: the Request object coming from the wsgi layer
        :returns: a dict of key/value filters
        """
        filters = {}
        properties = {}

        for param in req.params:
            if param in SUPPORTED_FILTERS:
                filters[param] = req.params.get(param)
            if param.startswith('property-'):
                _param = param[9:]
                properties[_param] = req.params.get(param)

        if 'changes-since' in filters:
            isotime = filters['changes-since']
            try:
                filters['changes-since'] = timeutils.parse_isotime(isotime)
            except ValueError:
                raise exc.HTTPBadRequest(_("Unrecognized changes-since value"))

        if 'protected' in filters:
            value = self._get_bool(filters['protected'])
            if value is None:
                raise exc.HTTPBadRequest(
                    _("protected must be True, or "
                      "False"))

            filters['protected'] = value

        # only allow admins to filter on 'deleted'
        if req.context.is_admin:
            deleted_filter = self._parse_deleted_filter(req)
            if deleted_filter is not None:
                filters['deleted'] = deleted_filter
            elif 'changes-since' not in filters:
                filters['deleted'] = False
        elif 'changes-since' not in filters:
            filters['deleted'] = False

        if properties:
            filters['properties'] = properties

        return filters
Example #4
0
    def _get_filters(self, req):
        """Return a dictionary of query param filters from the request

        :param req: the Request object coming from the wsgi layer
        :returns: a dict of key/value filters
        """
        filters = {}
        properties = {}

        for param in req.params:
            if param in SUPPORTED_FILTERS:
                filters[param] = req.params.get(param)
            if param.startswith('property-'):
                _param = param[9:]
                properties[_param] = req.params.get(param)

        if 'changes-since' in filters:
            isotime = filters['changes-since']
            try:
                filters['changes-since'] = timeutils.parse_isotime(isotime)
            except ValueError:
                raise exc.HTTPBadRequest(_("Unrecognized changes-since value"))

        if 'protected' in filters:
            value = self._get_bool(filters['protected'])
            if value is None:
                raise exc.HTTPBadRequest(_("protected must be True, or "
                                           "False"))

            filters['protected'] = value

        # only allow admins to filter on 'deleted'
        if req.context.is_admin:
            deleted_filter = self._parse_deleted_filter(req)
            if deleted_filter is not None:
                filters['deleted'] = deleted_filter
            elif 'changes-since' not in filters:
                filters['deleted'] = False
        elif 'changes-since' not in filters:
            filters['deleted'] = False

        if properties:
            filters['properties'] = properties

        return filters
Example #5
0
 def _to_datetime(obj):
     return timeutils.normalize_time(timeutils.parse_isotime(obj))
Example #6
0
 def _do_test(self, time_str, yr, mon, day, hr, minute, sec, micro, shift):
     DAY_SECONDS = 24 * 60 * 60
     timestamp = timeutils.parse_isotime(time_str)
     self._instaneous(timestamp, yr, mon, day, hr, minute, sec, micro)
     offset = timestamp.tzinfo.utcoffset(None)
     self.assertEqual(offset.seconds + offset.days * DAY_SECONDS, shift)
Example #7
0
 def test_parse_isotime_micro_second_precision(self):
     expect = timeutils.parse_isotime(self.skynet_self_aware_time_ms_str)
     skynet_self_aware_time_ms_utc = self.skynet_self_aware_ms_time.replace(
         tzinfo=iso8601.iso8601.UTC)
     self.assertEqual(skynet_self_aware_time_ms_utc, expect)
Example #8
0
 def test_normalize_zulu_aware_to_naive(self):
     dt = datetime.datetime(2011, 2, 14, 20, 53, 7)
     time_str = '2011-02-14T19:53:07Z'
     aware = timeutils.parse_isotime(time_str)
     naive = timeutils.normalize_time(aware)
     self.assertTrue(naive < dt)
Example #9
0
 def test_west_normalize(self):
     time_str = '2012-02-14T20:53:07+21:00'
     west = timeutils.parse_isotime(time_str)
     normed = timeutils.normalize_time(west)
     self._instaneous(normed, 2012, 2, 13, 23, 53, 7, 0)
Example #10
0
 def test_east_normalize(self):
     time_str = '2012-02-14T20:53:07-07:00'
     east = timeutils.parse_isotime(time_str)
     normed = timeutils.normalize_time(east)
     self._instaneous(normed, 2012, 2, 15, 3, 53, 7, 0)
Example #11
0
 def test_zulu_normalize(self):
     time_str = '2012-02-14T20:53:07Z'
     zulu = timeutils.parse_isotime(time_str)
     normed = timeutils.normalize_time(zulu)
     self._instaneous(normed, 2012, 2, 14, 20, 53, 7, 0)
Example #12
0
 def test_now_roundtrip(self):
     time_str = timeutils.isotime()
     now = timeutils.parse_isotime(time_str)
     self.assertEqual(now.tzinfo, iso8601.iso8601.UTC)
     self.assertEqual(timeutils.isotime(now), time_str)
Example #13
0
 def test_west_roundtrip(self):
     time_str = '2012-02-14T20:53:07+11:30'
     west = timeutils.parse_isotime(time_str)
     self.assertEqual(west.tzinfo.tzname(None), '+11:30')
     self.assertEqual(timeutils.isotime(west), time_str)
Example #14
0
 def test_east_roundtrip(self):
     time_str = '2012-02-14T20:53:07-07:00'
     east = timeutils.parse_isotime(time_str)
     self.assertEqual(east.tzinfo.tzname(None), '-07:00')
     self.assertEqual(timeutils.isotime(east), time_str)
Example #15
0
 def test_zulu_roundtrip(self):
     time_str = '2012-02-14T20:53:07Z'
     zulu = timeutils.parse_isotime(time_str)
     self.assertEqual(zulu.tzinfo, iso8601.iso8601.UTC)
     self.assertEqual(timeutils.isotime(zulu), time_str)