-
Notifications
You must be signed in to change notification settings - Fork 0
/
times.py
34 lines (28 loc) · 907 Bytes
/
times.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
# The quick-n-dirty LPC BBB frontend system
# Copyright 2020 Jonathan Corbet <corbet@lwn.net>
# Copyright 2020 Guy Lunardi <guy@linux.com>
# Redistributable under the terms of the GNU General Public License,
# version 2 or greater
#
#
# Simple time manipulation.
#
import datetime
from datetime import timezone
def real_current_time():
return datetime.datetime.now(tz = timezone.utc)
def fake_current_time():
return datetime.datetime(2021, 9, 21, 13, 30, 0, tzinfo = timezone.utc)
current_time = real_current_time
def user_tz_offset(request):
return -int(request.get_cookie('tzoffset', '0'))
#
# Shift a datetime from its current zone to our current offset.
#
def offset_time(request, dt):
current = dt.tzinfo.utcoffset(dt)
shift = current - datetime.timedelta(minutes = user_tz_offset(request))
return dt - shift
def utc_time(dt):
return dt.astimezone(timezone.utc)