How to use the iso8601.parse_date 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 / test_iso8601.py View on Github external
def test_parse_invalid_date():
    try:
        iso8601.parse_date(None)
    except iso8601.ParseError:
        pass
    else:
        assert 1 == 2
github ActivityWatch / aw-core / tests / test_query2.py View on Github external
def test_query2_query_categorize(datastore):
    bid = "test_bucket"
    qname = "test"
    starttime = iso8601.parse_date("1970")
    endtime = starttime + timedelta(hours=1)

    example_query = """
    events = query_bucket("{bid}");
    events = sort_by_timestamp(events);
    events = categorize(events, [[["test"], {{"regex": "test"}}], [["test", "subtest"], {{"regex": "test2"}}]]);
    events_by_cat = merge_events_by_keys(events, ["$category"]);
    RETURN = {{"events": events, "events_by_cat": events_by_cat}};
    """.format(
        bid=bid, bid_escaped=bid.replace("'", "\\'")
    )
    try:
        bucket = datastore.create_bucket(
            bucket_id=bid, type="test", client="test", hostname="test", name="asd"
        )
        events = [
github ActivityWatch / aw-core / tests / test_query2.py View on Github external
def test_query2_return_value():
    qname = "asd"
    starttime = iso8601.parse_date("1970-01-01")
    endtime = iso8601.parse_date("1970-01-02")
    example_query = "RETURN = 1;"
    result = query(qname, example_query, starttime, endtime, None)
    assert result == 1

    example_query = "RETURN = 'testing 123'"
    result = query(qname, example_query, starttime, endtime, None)
    assert result == "testing 123"

    example_query = "RETURN = {'a': 1}"
    result = query(qname, example_query, starttime, endtime, None)
    assert result == {"a": 1}

    # Nothing to return
    with pytest.raises(QueryParseException):
        example_query = "a=1"
github mk-fg / graphite-metrics / graphite_metrics / collectors / cron_log.py View on Github external
def read(self, _re_sanitize=re.compile('\s+|-')):
		# Cron
		if self.log_tailer:
			for line in iter(self.log_tailer.next, u''):
				# log.debug('LINE: {!r}'.format(line))
				ts, line = line.strip().split(None, 1)
				ts = calendar.timegm(iso8601.parse_date(ts).utctimetuple())
				matched = False
				for ev, regex in self.lines.viewitems():
					if not regex: continue
					match = regex.search(line)
					if match:
						matched = True
						job = match.group('job')
						for alias, regex in self.aliases:
							group = alias[1:] if alias.startswith('_') else None
							alias_match = regex.search(job)
							if alias_match:
								if group is not None:
									job = _re_sanitize.sub('_', alias_match.group(group))
								else: job = alias
								break
						else:
github ke4roh / RPiNWR / RPiNWR / sources / atom_events.py View on Github external
        for msg in sorted(new_messages, key=lambda x: iso8601.parse_date(
                x.find('{http://www.w3.org/2005/Atom}published').text).timestamp()):
            self.callback(NewAtomEntry(msg, http_time_now))
github ibm-watson-iot / iot-python / src / wiotp / sdk / api / lec / __init__.py View on Github external
def timestamp(self):
        return iso8601.parse_date(self["timestamp"])
github ExCiteS / geokey / opencomap / apps / backend / models / featuretype.py View on Github external
def validateInput(self, value):
		"""
		Checks if the provided value is a valid and ISO8601 compliant date string.
		"""
		
		try: 
			iso8601.parse_date(value)
			return True
		except iso8601.iso8601.ParseError: 
			return False
github broadinstitute / dalmatian / dalmatian / wmanager.py View on Github external
def get_submission_status(self, config=None, filter_active=True, show_namespaces=False):
        """
        Get status of all submissions in the workspace (replicates UI Monitor)
        """
        # filter submissions by configuration
        submissions = self.list_submissions(config=config)

        statuses = ['Succeeded', 'Running', 'Failed', 'Aborted', 'Aborting', 'Submitted', 'Queued']
        df = []
        for s in submissions:
            d = {
                'entity_id':s['submissionEntity']['entityName'],
                'status':s['status'],
                'submission_id':s['submissionId'],
                'date':iso8601.parse_date(s['submissionDate']).strftime('%H:%M:%S %m/%d/%Y'),
            }
            d.update({i:s['workflowStatuses'].get(i,0) for i in statuses})
            if show_namespaces:
                d['configuration'] = s['methodConfigurationNamespace']+'/'+s['methodConfigurationName']
            else:
                d['configuration'] = s['methodConfigurationName']
            df.append(d)
        df = pd.DataFrame(df)
        df.set_index('entity_id', inplace=True)
        df['date'] = pd.to_datetime(df['date'])
        df = df[['configuration', 'status']+statuses+['date', 'submission_id']]
        if filter_active:
            df = df[(df['Running']!=0) | (df['Submitted']!=0)]
        return df.sort_values('date')[::-1]
github kdart / pycopia / net / pycopia / ssl / certs.py View on Github external
def get_asn1time(when):
    """Return an ASN1 normalized time from a datetime object or ISO 8601
    string.
    """
    if when is None:
        when = now_utc()
    if isinstance(when, str):
        import iso8601
        when = iso8601.parse_date(when)
    assert type(when) is datetime
    return when.strftime("%Y%m%d%H%M%S%z")
github jhpyle / docassemble / docassemble_webapp / docassemble / webapp / worker.py View on Github external
def epoch_from_iso(datestring):
    return (iso8601.parse_date(datestring) - datetime.datetime(1970,1,1, tzinfo=pytz.utc)).total_seconds()