How to use the iso8601.parse 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 skarra / ASynK / asynk / pimdb_cd.py View on Github external
    @classmethod
    def parse_vcard_time (self, t):
        """Return a datetime object containing the native UTC timestamp based
        on the specified vCard REV timestamp string."""

       # IMP: Note that we assume the time is in UTC - and ignore what is
       # actually in the string. This sucks, but this is all I am willing to
       # do for the m moment. FIXME

        res = re.search(r'(\d\d\d\d\d\d\d\dT\d\d\d\d\d\d).*', t)
        if res:
            t = res.group(1)
            return datetime.datetime.strptime(t, '%Y%m%dT%H%M%S')
        else:
            t = iso8601.parse(t)
            return datetime.datetime.utcfromtimestamp(t)
github skarra / ASynK / asynk / folder_ol.py View on Github external
else:
            dest2 = destid

        ctable = self.get_contents()
        stp = self.get_proptags().sync_tags[stag]

        cols = (mt.PR_ENTRYID, mt.PR_LAST_MODIFICATION_TIME,
                mt.PR_DISPLAY_NAME, stp)
        ctable.SetColumns(cols, 0)

        i   = 0

        synct_str = self.get_config().get_last_sync_start(pname)
        if not synct_sto:
            synct_sto = self.get_config().get_last_sync_stop(pname)
        synct     = iso8601.parse(synct_sto)
        logging.debug('Last Start iso str : %s', synct_str)
        logging.debug('Last Stop  iso str : %s', synct_sto)
        logging.debug('Current Time       : %s', iso8601.tostring(time.time()))

        logging.info('Data obtained from MAPI. Processing...')

        newi = {}
        while True:
            rows = ctable.QueryRows(1, 0)
            #if this is the last row then stop
            if len(rows) != 1:
                break

            ((entryid_tag, entryid), (tt, modt),
             (name_tag, name), (gid_tag, gid)) = rows[0]
            b64_entryid = base64.b64encode(entryid)
github gdoermann / django-chargify / chargify / pychargify / api.py View on Github external
constructor = globals()[self.__name__]
        else:
            constructor = globals()[obj_type]
        obj = constructor(self.api_key, self.sub_domain)
        
        for childnodes in node.childNodes:
            if childnodes.nodeType == 1 and not childnodes.nodeName == '':
                if childnodes.nodeName in self.__attribute_types__:
                    obj.__setattr__(childnodes.nodeName, self._applyS(childnodes.toxml(), self.__attribute_types__[childnodes.nodeName], childnodes.nodeName))
                else:
                    node_value = self.__get_xml_value(childnodes.childNodes)
                    if "type" in  childnodes.attributes.keys():
                        node_type = childnodes.attributes["type"]
                        if node_value:
                            if node_type.nodeValue == 'datetime':
                                node_value = datetime.datetime.fromtimestamp(iso8601.parse(node_value))
                    obj.__setattr__(childnodes.nodeName, node_value)
        
        return obj
github skarra / ASynK / asynk / utils.py View on Github external
def asynk_ts_to_iso8601 (ts):
    """The text timestamps in ASynK will be stored in a format that is readily
    usable by BBDB. Frequently there is a need to parse it into other formats,
    and as an intermediate step we would like to convert it into iso8601
    format to leverage the libraries available for handling iso8601. This
    routine converts a text string in the internal ASynK (BBDB) text format,
    into iso8601 format with Zone Specifier."""

    ## FIXME: All of these assume the timestamps are in UTC. Bad things can
    ## happen if some other timezone is provided.
    try:
        ## Eliminate the case where the input string is already in iso8601
        ## format... 
        iso8601.parse(ts)
        return ts
    except ValueError, e:
        return re.sub(r'(\d\d\d\d-\d\d-\d\d) (\d\d:\d\d:\d\d).*$',
                      r'\1T\2Z', ts)
github skarra / ASynK / asynk / utils.py View on Github external
def asynk_ts_parse (ts):
    """For historical reasons (IOW Bugs), ASynK versions have stored created
    and modified timestamps in two distinct text representations. This routine
    is a wrapper to gracefully handle both cases, convert it into a iso
    string, and then parse it into a python datetime object, which is returned
    """

    return iso8601.parse(asynk_ts_to_iso8601(ts))
github asascience-open / ncWMS / web / WEB-INF / jython / getmetadata.py View on Github external
def getCalendar(config, dsId, varID, dateTime):
    """ returns an HTML calendar for the given dataset and variable.
        dateTime is a string in ISO 8601 format with the required
        'focus time' """
    # Get an array of time axis values in seconds since the epoch
    tValues = config.datasets[dsId].variables[varID].tvalues
    # TODO: is this the right thing to do here?
    if len(tValues) == 0:
        return ""
    str = StringIO()
    prettyDateFormat = "%d %b %Y"

    # Find the closest time step to the given dateTime value
    # TODO: binary search would be more efficient
    reqTime = iso8601.parse(dateTime) # Gives seconds since the epoch
    diff = 1e20
    for i in xrange(len(tValues)):
        testDiff = math.fabs(tValues[i] - reqTime)
        if testDiff < diff:
            # Axis is monotonic so we should move closer and closer
            # to the nearest value
            diff = testDiff
            nearestIndex = i
        elif i > 0:
            # We've moved past the closest date
            break
    
    str.write("")
    str.write("%s" % iso8601.tostring(tValues[nearestIndex]))
    str.write("%s" % time.strftime(prettyDateFormat, time.gmtime(tValues[nearestIndex])))
    str.write("%d" % nearestIndex)