Added pillar.api.utils.utcnow() which returns a datetime for 'now'

This replaces pillar.web.utils.datetime_now() and can be used in a wider
setting (since we don't import web stuff in the api, but we do vice versa).
This commit is contained in:
2018-02-13 14:36:05 +01:00
parent d0520484bb
commit f2888069db
15 changed files with 41 additions and 52 deletions

View File

@@ -10,6 +10,7 @@ import typing
import urllib.request, urllib.parse, urllib.error
import bson.objectid
import bson.tz_util
from eve import RFC1123_DATE_FORMAT
from flask import current_app
from werkzeug import exceptions as wz_exceptions
@@ -200,3 +201,7 @@ def random_etag() -> str:
randbytes = random.getrandbits(256).to_bytes(32, 'big')
return base64.b64encode(randbytes)[:-1].decode()
def utcnow() -> datetime.datetime:
return datetime.datetime.now(tz=bson.tz_util.utc)