How to use the iso8601.iso8601.ISO8601_REGEX 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 nuxeo / nuxeo / nuxeo-distribution / nuxeo-server-cmis-tests / iso8601 / test_iso8601.py View on Github external
def test_iso8601_regex():
    assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")
github ansible / awx / awx / lib / site-packages / iso8601 / test_iso8601.py View on Github external
def test_iso8601_regex():
    assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")
github Pylons / deform / deform / widget.py View on Github external
def serialize(self, field, cstruct, **kw):
        if cstruct in (null, None):
            cstruct = ""
        readonly = kw.get("readonly", self.readonly)
        if cstruct:
            parsed = ISO8601_REGEX.match(cstruct)
            if parsed:  # strip timezone if it's there
                timezone = parsed.groupdict()["timezone"]
                if timezone and cstruct.endswith(timezone):
                    cstruct = cstruct[: -len(timezone)]

        try:
            date, time = cstruct.split("T", 1)
            try:
                # get rid of milliseconds
                time, _ = time.split(".", 1)
            except ValueError:
                pass
            kw["date"], kw["time"] = date, time
        except ValueError:  # need more than one item to unpack
            kw["date"] = kw["time"] = ""
github LearningRegistry / LearningRegistry / LR / lr / lib / helpers.py View on Github external
def getISO8601Granularity(iso8601string):
    '''Determine the precision of an ISO8601 datetime string'''

    def _getPrecision(gran, granule):
        if gran.precision == None:
            return len(granule)
        else:
            return gran.precision

    if not isinstance(iso8601string, basestring):
        raise ParseError("Expecting a string %r" % iso8601string)
    m = ISO8601_REGEX.match(iso8601string)
    if not m:
        raise ParseError("Unable to parse date string %r" % iso8601string)
    groups = m.groupdict()
    sandsOfTime = [
                   Granularity("year",  4, 1),
                   Granularity("month", 2, 2),
                   Granularity("day",   2, 3),
                   Granularity("hour",  2, 4),
                   Granularity("minute",2, 5),
                   Granularity("second",2, 6),
                   Granularity("fraction", None, 7) ]
    curGrain = Granularity()
    for s in sandsOfTime:
        if groups[s.granule] != None:
            curGrain.granule = s.granule
            curGrain.precision = _getPrecision(s, groups[s.granule])