Add timezone support and an authenticated view

This commit is contained in:
2023-01-18 00:39:12 -05:00
parent a0af0bce05
commit e75c22d583
6 changed files with 185 additions and 81 deletions

View File

@ -1,6 +1,9 @@
import datetime
import settings
import pytz
from django.conf import settings
from django.utils import timezone
# need to translate to a non-naive timezone, even if timezone == settings.TIME_ZONE, so we can compare two dates
def to_user_timezone(date, profile):
@ -17,7 +20,12 @@ def to_system_timezone(date, profile):
)
def now_timezone():
def now_user_timezone(profile):
timezone.activate(pytz.timezone(profile.timezone))
return timezone.localtime(timezone.now())
def now_system_timezone():
return (
datetime.datetime.now()
.replace(tzinfo=pytz.timezone(settings.TIME_ZONE))