Skip to content

Commit

Permalink
Change: Handle timezone-aware timestamps in acls
Browse files Browse the repository at this point in the history
The django config now has USE_TZ=True, so the timestamps it produces
have timezone info. Because python does not allow comparing aware
timestamps with naive timestamps, the current time is also made aware.

Note that the per-day start and end times are not aware, but always
interpreted in the local timezone of the lock.
  • Loading branch information
matthijskooijman committed May 1, 2024
1 parent f9bf6cb commit 6e449bd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libs/module/DjangoBackendRfidAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,12 @@ def keys_hash(self):
).hexdigest()

def acl_parse_rule(self, rule):
now = datetime.datetime.now()
now = datetime.datetime.now().astimezone()

# Note that after/before are expected to have a timezone
# specifier and are interpret as absolute timestamps, while
# time_start/time_end are just plain times and are interpreted
# in the local timezone (independent of the server timezone).
after = rule.get("after", None)
before = rule.get("before", None)
weekdays = rule.get("weekdays", [])
Expand Down

0 comments on commit 6e449bd

Please sign in to comment.