mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-01 19:19:57 +00:00
f08257b853
`strict_rfc3339.rfc3339_to_timestamp()` is tz aware `datetime.datetime.fromtimestamp` is not this causes the test `test_string_format_datetime` to fail on system that are not on utc
26 lines
574 B
Python
26 lines
574 B
Python
"""OpenAPI core schemas util module"""
|
|
import datetime
|
|
from distutils.util import strtobool
|
|
from json import dumps
|
|
from six import string_types
|
|
import strict_rfc3339
|
|
|
|
|
|
def forcebool(val):
|
|
if isinstance(val, string_types):
|
|
val = strtobool(val)
|
|
|
|
return bool(val)
|
|
|
|
|
|
def dicthash(d):
|
|
return hash(dumps(d, sort_keys=True))
|
|
|
|
|
|
def format_date(value):
|
|
return datetime.datetime.strptime(value, '%Y-%m-%d').date()
|
|
|
|
|
|
def format_datetime(value):
|
|
timestamp = strict_rfc3339.rfc3339_to_timestamp(value)
|
|
return datetime.datetime.utcfromtimestamp(timestamp)
|