How to use the ciso8601.parse_datetime function in ciso8601

To help you get started, we’ve selected a few ciso8601 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 closeio / ciso8601 / tests.py View on Github external
def test_excessive_subsecond_precision(self):
        self.assertEqual(
            ciso8601.parse_datetime('20140203T103527.234567891234'),
            datetime.datetime(2014, 2, 3, 10, 35, 27, 234567)
        )
github jclgoodwin / bustimes.org / departures / live.py View on Github external
def get_row(self, item):
        time = item['scheduledCall']['scheduledDepartureTime']
        if not time:
            return
        live = item.get('expectedDepartureTime')
        if live:
            live = ciso8601.parse_datetime(live)
        return {
            'time': ciso8601.parse_datetime(time),
            'live': live,
            'service': self.get_service(item['routeInfo']['lineName']),
            'destination': item['tripInfo']['headsign'],
            'vehicle': item['vehicleRTI']['vehicleID'],
            'operator': item['agencyCode'],
        }
github CenterForOpenScience / osf.io / osf / utils / datetime_aware_jsonfield.py View on Github external
def decode_datetime_objects(nested_value):
    if isinstance(nested_value, list):
        return [decode_datetime_objects(item) for item in nested_value]
    elif isinstance(nested_value, dict):
        for key, value in nested_value.iteritems():
            if isinstance(value, dict) and 'type' in value.keys():
                if value['type'] == 'encoded_datetime':
                    nested_value[key] = ciso8601.parse_datetime(value['value'])
                if value['type'] == 'encoded_date':
                    nested_value[key] = ciso8601.parse_datetime(value['value']).date()
                if value['type'] == 'encoded_time':
                    nested_value[key] = ciso8601.parse_datetime(value['value']).time()
                if value['type'] == 'encoded_decimal':
                    nested_value[key] = Decimal(value['value'])
            elif isinstance(value, dict):
                nested_value[key] = decode_datetime_objects(value)
            elif isinstance(value, list):
                nested_value[key] = decode_datetime_objects(value)
        return nested_value
    return nested_value
github jclgoodwin / bustimes.org / vehicles / management / commands / import_cambridge.py View on Github external
print(item)
        elif operator.pk == 'SCCM':
            operator_options = ('SCCM', 'SCPB', 'SCHU', 'SCBD')
        elif operator.pk == 'CBBH':
            operator_options = ('CBBH', 'CBNL')

        vehicle, created = self.get_vehicle(operator_options or operator, item)

        journey = None

        if 'PublishedLineName' in item:
            line_name = item['PublishedLineName']
            journey_code = item['DatedVehicleJourneyRef']
            if journey_code == 'UNKNOWN':
                journey_code = ''
            departure_time = ciso8601.parse_datetime(item['OriginAimedDepartureTime'])
        else:
            line_name = ''
            journey_code = ''
            departure_time = None

        recorded_at_time = ciso8601.parse_datetime(item['RecordedAtTime'])

        if not created and vehicle.latest_location:
            location = vehicle.latest_location
            latest_journey = location.journey
            if line_name == latest_journey.route_name and journey_code == latest_journey.code:
                if departure_time is None or departure_time == latest_journey.datetime:
                    if recorded_at_time - location.datetime < timedelta(hours=1):
                        journey = journey = latest_journey
        else:
            location = VehicleLocation()
github IRC-SPHERE / HyperStream / hyperstream / time_interval.py View on Github external
if isinstance(end, int):
        # TODO: add check for future (negative values) and ensure that start < end
        if not isinstance(start_time, timedelta):
            raise ValueError("Can't mix relative and absolute times")
        end_time = timedelta(seconds=end)
    elif isinstance(end, timedelta):
        if not isinstance(start_time, timedelta):
            raise ValueError("Can't mix relative and absolute times")
        end_time = end
    elif end is None:
        end_time = utcnow()  # TODO: or MAX_DATE?
    elif isinstance(end, datetime):
        end_time = end.replace(tzinfo=UTC)
    else:
        end_time = ciso8601.parse_datetime(end).replace(tzinfo=UTC)

    if isinstance(start_time, timedelta):
        return RelativeTimeInterval(start=start_time, end=end_time)
    else:
        return TimeInterval(start=start_time, end=end_time)
github jclgoodwin / bustimes.org / vehicles / management / commands / import_nx.py View on Github external
def get_datetime(item):
        try:
            return timezone.make_aware(parse_datetime(item['live']['timestamp']['dateTime']))
        except AmbiguousTimeError:
            return timezone.make_aware(parse_datetime(item['live']['timestamp']['dateTime']), is_dst=True)
github jclgoodwin / bustimes.org / vehicles / management / commands / import_bushub.py View on Github external
def get_datetime(string):
    if string:
        try:
            when = parse_datetime(string)
        except ValueError:
            when = datetime.strptime(string, '%d/%m/%Y %H:%M:%S')
        try:
            return timezone.make_aware(when)
        except ValueError:
            return when
github jclgoodwin / bustimes.org / departures / live.py View on Github external
def departures_from_response(self, res):
        return sorted([{
            'time': ciso8601.parse_datetime(item['ScheduledArrival']),
            'live': ciso8601.parse_datetime(item['ExpectedArrival']),
            'service': self.get_service(item['LineName']),
            'destination': item['DestinationName'],
        } for item in res.json()['Predictions']['Prediction'] if item['ExpectedArrival']], key=lambda d: d['live'])
github CenterForOpenScience / osf.io / osf / utils / datetime_aware_jsonfield.py View on Github external
def decode_datetime_objects(nested_value):
    if isinstance(nested_value, list):
        return [decode_datetime_objects(item) for item in nested_value]
    elif isinstance(nested_value, dict):
        for key, value in nested_value.iteritems():
            if isinstance(value, dict) and 'type' in value.keys():
                if value['type'] == 'encoded_datetime':
                    nested_value[key] = ciso8601.parse_datetime(value['value'])
                if value['type'] == 'encoded_date':
                    nested_value[key] = ciso8601.parse_datetime(value['value']).date()
                if value['type'] == 'encoded_time':
                    nested_value[key] = ciso8601.parse_datetime(value['value']).time()
                if value['type'] == 'encoded_decimal':
                    nested_value[key] = Decimal(value['value'])
            elif isinstance(value, dict):
                nested_value[key] = decode_datetime_objects(value)
            elif isinstance(value, list):
                nested_value[key] = decode_datetime_objects(value)
        return nested_value
    return nested_value

ciso8601

Fast ISO8601 date time parser for Python written in C

MIT
Latest version published 16 days ago

Package Health Score

88 / 100
Full package analysis

Similar packages