How to use the isodate.parse_date function in isodate

To help you get started, we’ve selected a few isodate 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 Azure / autorest / src / generator / AutoRest.Python.Tests / AcceptanceTests / array_tests.py View on Github external
client.array.get_long_invalid_string()

        self.assertEqual(client.array.get_float_invalid_null(), [0.0, None, -1.2e20])

        with self.assertRaises(DeserializationError):
            client.array.get_float_invalid_string()

        self.assertEqual(client.array.get_double_invalid_null(), [0.0, None, -1.2e20])

        with self.assertRaises(DeserializationError):
            client.array.get_double_invalid_string()

        self.assertEqual(client.array.get_string_with_invalid(), ["foo", "123", "foo2"])

        d_array = client.array.get_date_invalid_null()
        self.assertEqual(d_array, [isodate.parse_date("2012-01-01"), None, isodate.parse_date("1776-07-04")])

        with self.assertRaises(DeserializationError):
            client.array.get_date_invalid_chars()

        dt_array = client.array.get_date_time_invalid_null()
        self.assertEqual(dt_array, [isodate.parse_datetime("2000-12-01T00:00:01Z"), None])

        with self.assertRaises(DeserializationError):
            client.array.get_date_time_invalid_chars()

        test_array = ['a string that gets encoded with base64url'.encode(),
                      'test string'.encode(),
                      'Lorem ipsum'.encode()]
        self.assertEqual(client.array.get_base64_url(), test_array)
github Azure / autorest / src / generator / AutoRest.Python.Tests / AcceptanceTests / date_tests.py View on Github external
def test_date(self):
        client = AutoRestDateTestService(base_url="http://localhost:3000")

        max_date = isodate.parse_date("9999-12-31T23:59:59.999999Z")
        min_date = isodate.parse_date("0001-01-01T00:00:00Z")
        client.date_model.put_max_date(max_date)
        client.date_model.put_min_date(min_date)

        self.assertEqual(max_date, client.date_model.get_max_date())
        self.assertEqual(min_date, client.date_model.get_min_date())
        self.assertIsNone(client.date_model.get_null())

        # Python isodate.parse support too wild input, and won't raise error
        #with self.assertRaises(DeserializationError):
        #    client.date_model.get_invalid_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_overflow_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_underflow_date()
github Azure / azure-sdk-for-java / AutoRest / Generators / Python / Python.Tests / AcceptanceTests / complex_tests.py View on Github external
self.assertEqual("goodrequest", stringResult.field)
        self.assertEqual("", stringResult.empty)
        self.assertIsNone(stringResult.null)

        # PUT primitive/string
        stringRequest = StringWrapper(null=None, empty="", field="goodrequest")
        client.primitive.put_string(stringRequest);

        # GET primitive/date
        dateResult = client.primitive.get_date()
        self.assertEqual(isodate.parse_date("0001-01-01"), dateResult.field)
        self.assertEqual(isodate.parse_date("2016-02-29"), dateResult.leap)

        dateRequest = DateWrapper(
            field=isodate.parse_date('0001-01-01'), 
            leap=isodate.parse_date('2016-02-29'))
        client.primitive.put_date(dateRequest)

        # GET primitive/datetime
        datetimeResult = client.primitive.get_date_time()
        min_date = datetime.min
        min_date = min_date.replace(tzinfo=UTC())
        self.assertEqual(min_date, datetimeResult.field)
        
        datetime_request = DatetimeWrapper(
            field=isodate.parse_datetime("0001-01-01T00:00:00Z"),
            now=isodate.parse_datetime("2015-05-18T18:38:00Z"))
        client.primitive.put_date_time(datetime_request)
        
        # GET primitive/datetimerfc1123
        datetimeRfc1123Result = client.primitive.get_date_time_rfc1123()
        self.assertEqual(min_date, datetimeRfc1123Result.field)
github Azure / azure-sdk-for-java / AutoRest / Generators / Python / Python.Tests / AcceptanceTests / date_tests.py View on Github external
def test_date(self):
        client = AutoRestDateTestService(base_url="http://localhost:3000")

        max_date = isodate.parse_date("9999-12-31T23:59:59.999999Z")
        min_date = isodate.parse_date("0001-01-01T00:00:00Z")
        client.date_model.put_max_date(max_date)
        client.date_model.put_min_date(min_date)

        self.assertEqual(max_date, client.date_model.get_max_date())
        self.assertEqual(min_date, client.date_model.get_min_date())
        self.assertIsNone(client.date_model.get_null())

        # Python isodate.parse support too wild input, and won't raise error
        #with self.assertRaises(DeserializationError):
        #    client.date_model.get_invalid_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_overflow_date()

        with self.assertRaises(DeserializationError):
            client.date_model.get_underflow_date()
github nazrulworld / fhir.resources / fhir / resources / STU3 / fhirdate.py View on Github external
isstr = isinstance(jsonval, str)
            if (
                not isstr and sys.version_info[0] < 3
            ):  # Python 2.x has 'str' and 'unicode'
                isstr = isinstance(jsonval, basestring)
            if not isstr:
                raise TypeError(
                    "Expecting string when initializing {}, but got {}".format(
                        type(self), type(jsonval)
                    )
                )
            try:
                if "T" in jsonval:
                    self.date = isodate.parse_datetime(jsonval)
                else:
                    self.date = isodate.parse_date(jsonval)
            except Exception as e:
                logger.warning(
                    'Failed to initialize FHIRDate from "{}": {}'.format(jsonval, e)
                )

        self.origval = jsonval
github amccollum / microtron / microtron / microtron.py View on Github external
if value:
                                break
                        except:
                            pass
                        
                    else:
                        if len(prop):
                            value = self._parse_node(prop_node, prop)
                            if not value:
                                value = self._parse_value(prop_node)
                     
                        elif not prop_type or prop_type in ('text', 'url', 'image'):
                            value = self._parse_value(prop_node)
            
                        elif prop_type == 'date':
                            value = isodate.parse_date(self._parse_value(prop_node))
                    
                        else:
                            value = self.parse_format(prop_type, prop_node)[0]
                            if not value:
                                value = self._parse_value(prop_node)
                
                except Exception, e:
                    if self.strict:
                        raise ParseError("Error parsing value for property %s: %s" % (prop_name, e))
                    else:
                        value = self._parse_value(prop_node)
            
                if self.strict and prop_values and value.lower() not in prop_values:
                    raise ParseError("Invalid value for property %s: %s" % (prop_name, value))
            
                if prop_many == 'many':
github F-Secure / resource-api / src / resource_api / schema.py View on Github external
def _parse(self, val):
        return isodate.parse_date(val)
github Azure / azure-sdk-for-java / ClientRuntimes / Python / msrest / msrest / serialization.py View on Github external
    @staticmethod
    def deserialize_date(attr):
        """Deserialize ISO-8601 formatted string into Date object.

        :param str attr: response string to be deserialized.
        :rtype: Date
        :raises: DeserializationError if string format invalid.
        """
        return isodate.parse_date(attr)
github smart-on-fhir / client-py / fhirclient / models / fhirdate.py View on Github external
def __init__(self, jsonval=None):
        self.date = None
        if jsonval is not None:
            isstr = isinstance(jsonval, str)
            if not isstr and sys.version_info[0] < 3:       # Python 2.x has 'str' and 'unicode'
                isstr = isinstance(jsonval, basestring)
            if not isstr:
                raise TypeError("Expecting string when initializing {}, but got {}"
                    .format(type(self), type(jsonval)))
            try:
                if 'T' in jsonval:
                    self.date = isodate.parse_datetime(jsonval)
                else:
                    self.date = isodate.parse_date(jsonval)
            except Exception as e:
                logger.warning("Failed to initialize FHIRDate from \"{}\": {}"
                    .format(jsonval, e))
        
        self.origval = jsonval
github RDFLib / rdflib / rdflib / term.py View on Github external
(Decimal, (None, _XSD_DECIMAL)),
    (datetime, (lambda i:i.isoformat(), _XSD_DATETIME)),
    (date, (lambda i:i.isoformat(), _XSD_DATE)),
    (time, (lambda i:i.isoformat(), _XSD_TIME)),
    (xml.dom.minidom.Document, (_writeXML, _RDF_XMLLITERAL)),
    # this is a bit dirty - by accident the html5lib parser produces
    # DocumentFragments, and the xml parser Documents, letting this
    # decide what datatype to use makes roundtripping easier, but it a
    # bit random
    (xml.dom.minidom.DocumentFragment, (_writeXML, _RDF_HTMLLITERAL))
]

XSDToPython = {
    None : None, # plain literals map directly to value space
    URIRef(_XSD_PFX + 'time'): parse_time,
    URIRef(_XSD_PFX + 'date'): parse_date,
    URIRef(_XSD_PFX + 'dateTime'): parse_datetime,
    URIRef(_XSD_PFX + 'string'): None,
    URIRef(_XSD_PFX + 'normalizedString'): None,
    URIRef(_XSD_PFX + 'token'): None,
    URIRef(_XSD_PFX + 'language'): None,
    URIRef(_XSD_PFX + 'boolean'): lambda i: i.lower() in ['1', 'true'],
    URIRef(_XSD_PFX + 'decimal'): Decimal,
    URIRef(_XSD_PFX + 'integer'): long,
    URIRef(_XSD_PFX + 'nonPositiveInteger'): int,
    URIRef(_XSD_PFX + 'long'): long,
    URIRef(_XSD_PFX + 'nonNegativeInteger'): int,
    URIRef(_XSD_PFX + 'negativeInteger'): int,
    URIRef(_XSD_PFX + 'int'): long,
    URIRef(_XSD_PFX + 'unsignedLong'): long,
    URIRef(_XSD_PFX + 'positiveInteger'): int,
    URIRef(_XSD_PFX + 'short'): int,