|
3 | 3 | import pickle
|
4 | 4 | import re
|
5 | 5 | import warnings
|
6 |
| -from datetime import date, datetime |
| 6 | +from datetime import datetime |
7 | 7 | from pathlib import Path
|
| 8 | +from zoneinfo import ZoneInfo |
8 | 9 |
|
9 | 10 | import tagulous
|
10 | 11 | from crispy_forms.bootstrap import InlineCheckboxes, InlineRadios
|
@@ -188,7 +189,8 @@ def __init__(self, attrs=None, years=None, *, required=True):
|
188 | 189 | if years:
|
189 | 190 | self.years = years
|
190 | 191 | else:
|
191 |
| - this_year = date.today().year |
| 192 | + local_tz = ZoneInfo(get_system_setting("time_zone")) |
| 193 | + this_year = datetime.now(tz=local_tz).year |
192 | 194 | self.years = list(range(this_year - 10, this_year + 1))
|
193 | 195 |
|
194 | 196 | def render(self, name, value, attrs=None, renderer=None):
|
@@ -642,7 +644,8 @@ def clean_tags(self):
|
642 | 644 | # date can only be today or in the past, not the future
|
643 | 645 | def clean_scan_date(self):
|
644 | 646 | date = self.cleaned_data.get("scan_date", None)
|
645 |
| - if date and date.date() > datetime.today().date(): |
| 647 | + local_tz = ZoneInfo(get_system_setting("time_zone")) |
| 648 | + if date and date.date() > datetime.now(tz=local_tz).date(): |
646 | 649 | msg = "The date cannot be in the future!"
|
647 | 650 | raise forms.ValidationError(msg)
|
648 | 651 | return date
|
@@ -3582,7 +3585,8 @@ class Meta:
|
3582 | 3585 | def clean_expiration(self):
|
3583 | 3586 | expiration = self.cleaned_data.get("expiration", None)
|
3584 | 3587 | if expiration:
|
3585 |
| - today = datetime.today().date() |
| 3588 | + local_tz = ZoneInfo(get_system_setting("time_zone")) |
| 3589 | + today = datetime.now(tz=local_tz).date() |
3586 | 3590 | if expiration < today:
|
3587 | 3591 | msg = "The expiration cannot be in the past"
|
3588 | 3592 | raise forms.ValidationError(msg)
|
|
0 commit comments