Move datetime util to own module
Committed 7ef293
index 0000000..5602c8e
--- /dev/null
+import pendulum
+
+__all__ = ["parse_dt", "now"]
+
+
+def parse_dt(dt: str, **options) -> pendulum.DateTime:
+ """Parse `dt` and return a datetime object."""
+ return pendulum.parser.parse(dt, **options)
+
+
+def now() -> pendulum.DateTime:
+ """Return the current datetime."""
+ return pendulum.now("UTC")
--- a/web/framework/__init__.py
+++ b/web/framework/__init__.py
from newmath import nb60_re, nbdecode, nbencode, nbrandom
from .. import templating
+from ..dt import now, parse_dt
from ..response import Status # noqa
from ..response import (
OK,
return dict(handlers)[best_match](*args, **kwargs)
-def parse_dt(dt: str, **options) -> pendulum.datetime.DateTime:
- """Parse `dt` and return a datetime object."""
- return pendulum.parser.parse(dt, **options)
-
-
-def now() -> pendulum.datetime.DateTime:
- """Return the current datetime."""
- return pendulum.now("UTC")
-
-
-def utcnow(): # TODO XXX
- print(" USE NOW() INSTEAD ")
- return now()
-
-
_punct_re = r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+'
_punct_split = re.compile(_punct_re).split
--- a/web/headers/entity.py
+++ b/web/headers/entity.py
import datetime
import email
+from ..dt import now
from .util import Header
__all__ = [
def __init__(self, when):
# FIXME either seconds a la TTL or datetime according to W3C
- now = datetime.datetime.utcnow()
+ now = web.now()
if isinstance(when, str):
try:
when = int(when)