Skip to content

Commit

Permalink
Always use UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Feb 23, 2021
1 parent 3435301 commit 8ed5b2a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ requires = ['appdirs', 'bleach', 'bleach_allowlist', 'httpx', 'humanize',
'quart-trio-twice', 'rethinkdb >=2.4.8']
description-file = 'README.md'
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Development Status :: 3 - Alpha',
'Environment :: Web Environment',
'Framework :: Trio',
'Intended Audience :: Education',
Expand Down
17 changes: 9 additions & 8 deletions src/acanban/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from __future__ import annotations

from contextlib import asynccontextmanager
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone as tz
from secrets import token_urlsafe
from time import timezone
from typing import Any, AsyncIterator
from urllib.parse import urlsplit

Expand All @@ -45,12 +46,10 @@

__all__ = ['app']
__doc__ = 'Academic Kanban'
__version__ = '0.0.7'
__version__ = '0.1.0'


def utc(dt: datetime) -> datetime:
"""Convert the datetime object to UTC with microsecond being 0."""
return dt.astimezone(timezone.utc).replace(microsecond=0, tzinfo=None)
# Nope, the negative operator is not a typo, see also tzset(3posix).
TZ = tz(timedelta(seconds=-timezone))


class Acanban(QuartTrio):
Expand Down Expand Up @@ -99,8 +98,10 @@ def as_markdown(text: str) -> str:
@app.template_filter('naturaltime')
def fuzzytime(dt: datetime) -> str:
"""Convert datetime into fuzzy time in HTML with precise hovertext."""
udt = utc(dt)
return f"<span title='{udt} UTC'>{naturaltime(udt)}</span>"
rounded = dt.replace(microsecond=0)
fuzzy = naturaltime(rounded.replace(tzinfo=None), when=datetime.utcnow())
exact = rounded.astimezone(TZ)
return f"<span title='{exact}'>{fuzzy}</span>"


@app.before_serving
Expand Down
Loading

0 comments on commit 8ed5b2a

Please sign in to comment.