How to use the iso8601.UTC function in iso8601

To help you get started, we’ve selected a few iso8601 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github karpenoktem / kninfra / kn / agenda / iso8601 / View on Github external
def test_space_separator():
    """Handle a separator other than T

    d = iso8601.parse_date("2007-06-23 06:40:34.00Z")
    assert d.year == 2007
    assert d.month == 6
    assert == 23
    assert d.hour == 6
    assert d.minute == 40
    assert d.second == 34
    assert d.microsecond == 0
    assert d.tzinfo == iso8601.UTC
github fauna / faunadb-python / tests / View on Github external
def test_at(self):
    self.assertJson(, iso8601.UTC), query.get(query.index("widgets"))),
github voidfiles / strainer / tests / View on Github external
bowie = Artist(name='David Bowie')
    album = Album(
        title='Hunky Dory',
        release_date=datetime.datetime(1971, 12, 17)

    assert album_schema.serialize(album) == {
      'artist': {'name': 'David Bowie'},
      'release_date': '1971-12-17T00:00:00',
      'title': 'Hunky Dory'
    assert album_schema.deserialize(album_schema.serialize(album)) == {
      'artist': {'name': 'David Bowie'},
      'release_date': datetime.datetime(1971, 12, 17, 0, 0, tzinfo=iso8601.UTC),
      'title': 'Hunky Dory'
    input = album_schema.serialize(album)
    del input['artist']
    errors = None
    except Exception as e:
        errors = e.errors

    assert errors == {'artist': ['This field is required']}
github fauna / faunadb-python / tests / View on Github external
def test_fauna_time(self):
    self.assertJson(datetime.fromtimestamp(0, iso8601.UTC),
github fauna / faunadb-python / tests / View on Github external
def test_time_conversion(self):
    dt =
    self.assertEqual(FaunaTime(dt).to_datetime(), dt)

    # Must be time zone aware.
    self.assertRaises(ValueError, lambda: FaunaTime(datetime.utcnow()))

    dt = datetime.fromtimestamp(0, iso8601.UTC)
    ft = FaunaTime(dt)
    self.assertEqual(ft, FaunaTime("1970-01-01T00:00:00Z"))
    self.assertEqual(ft.to_datetime(), dt)
github karpenoktem / kninfra / utils / sync / gdata / iso8601 / View on Github external
def test_parse_date():
    d = iso8601.parse_date("2006-10-20T15:34:56Z")
    assert d.year == 2006
    assert d.month == 10
    assert == 20
    assert d.hour == 15
    assert d.minute == 34
    assert d.second == 56
    assert d.tzinfo == iso8601.UTC
github openstack / cinder / cinder / cmd / View on Github external
def _time_error(LOG, begin, end):
    if CONF.start_time:
        begin = datetime.datetime.strptime(CONF.start_time,
                                           "%Y-%m-%d %H:%M:%S")
    if CONF.end_time:
        end = datetime.datetime.strptime(CONF.end_time,
                                         "%Y-%m-%d %H:%M:%S")
    begin = begin.replace(tzinfo=iso8601.UTC)
    end = end.replace(tzinfo=iso8601.UTC)
    if end <= begin:
        msg = _("The end time (%(end)s) must be after the start "
                "time (%(start)s).") % {'start': begin,
                                        'end': end}
    return begin, end
github openstack / watcher / watcher / objects / View on Github external
"""Validate a datetime or None value."""
    if value is None:
        return None
    if isinstance(value, six.string_types):
        # NOTE(danms): Being tolerant of isotime strings here will help us
        # during our objects transition
        value = timeutils.parse_isotime(value)
    elif not isinstance(value, datetime.datetime):
        raise ValueError(
            _("A datetime.datetime is required here. Got %s"), value)

    if value.utcoffset() is None and tzinfo_aware:
        # NOTE(danms): Legacy objects from sqlalchemy are stored in UTC,
        # but are returned without a timezone attached.
        # As a transitional aid, assume a tz-naive object is in UTC.
        value = value.replace(tzinfo=iso8601.UTC)
    elif not tzinfo_aware:
        value = value.replace(tzinfo=None)

    return value
github openstack / nova / nova / scheduler / View on Github external
def decorated_function(self, spec_obj):
        return_value = None
            return_value = function(self, spec_obj)
        except Exception as e:
            # Ignores exception raised from consume_from_request() so that
            # booting instance would fail in the resource claim of compute
            # node, other suitable node may be chosen during scheduling retry.
            LOG.warning("Selected host: %(host)s failed to consume from "
                        "instance. Error: %(error)s",
                        {'host':, 'error': e})
            now = timeutils.utcnow()
            # NOTE(sbauza): Objects are UTC tz-aware by default
            self.updated = now.replace(tzinfo=iso8601.UTC)
        return return_value
github voidfiles / strainer / strainer / View on Github external
def datetime(value, default_tzinfo=iso8601.UTC, context=None):
    """validates that a a field is an ISO 8601 string, and converts it to a datetime object."""
    if not value:

        return iso8601.parse_date(value, default_timezone=default_tzinfo)
    except iso8601.ParseError as e:
        raise ValidationException('Invalid date: %s' % (e))