mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-28 11:49:42 -04:00
remove datetime.utcnow()
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
|
||||
SMS_CHAR_COUNT_LIMIT = 918 # 153 * 6, no network issues but check with providers before upping this further
|
||||
LETTER_MAX_PAGE_COUNT = 10
|
||||
@@ -23,3 +24,15 @@ email_with_smart_quotes_regex = re.compile(
|
||||
# and then later remove when performing tricky formatting operations
|
||||
MAGIC_SEQUENCE = "🇬🇧🐦✉️"
|
||||
magic_sequence_regex = re.compile(MAGIC_SEQUENCE)
|
||||
|
||||
|
||||
def aware_utcnow():
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
def naive_utcnow():
|
||||
return aware_utcnow().replace(tzinfo=None)
|
||||
|
||||
|
||||
def utc_now():
|
||||
return naive_utcnow()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from datetime import datetime
|
||||
from app.utils import utc_now
|
||||
|
||||
from .request_cache import RequestCache # noqa: F401 (unused import)
|
||||
|
||||
|
||||
def total_limit_cache_key(service_id):
|
||||
return "{}-{}-{}".format(
|
||||
str(service_id), datetime.utcnow().strftime("%Y-%m-%d"), "total-count"
|
||||
str(service_id), utc_now().strftime("%Y-%m-%d"), "total-count"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from collections import namedtuple
|
||||
from datetime import datetime, time, timedelta
|
||||
from datetime import time, timedelta
|
||||
|
||||
import pytz
|
||||
from govuk_bank_holidays.bank_holidays import BankHolidays
|
||||
|
||||
from app.utils import utc_now
|
||||
from notifications_utils.countries.data import Postage
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
|
||||
@@ -101,11 +102,7 @@ def get_letter_timings(upload_time, postage):
|
||||
|
||||
# print deadline is 3pm BST
|
||||
printed_by = set_gmt_hour(print_day, hour=15)
|
||||
now = (
|
||||
datetime.utcnow()
|
||||
.replace(tzinfo=pytz.utc)
|
||||
.astimezone(pytz.timezone("Europe/London"))
|
||||
)
|
||||
now = utc_now().replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Europe/London"))
|
||||
|
||||
return LetterTimings(
|
||||
printed_by=printed_by,
|
||||
@@ -135,7 +132,7 @@ def too_late_to_cancel_letter(notification_created_at):
|
||||
time_created_at = notification_created_at
|
||||
day_created_on = time_created_at.date()
|
||||
|
||||
current_time = datetime.utcnow()
|
||||
current_time = utc_now()
|
||||
current_day = current_time.date()
|
||||
if (
|
||||
_after_letter_processing_deadline()
|
||||
@@ -152,14 +149,14 @@ def too_late_to_cancel_letter(notification_created_at):
|
||||
|
||||
|
||||
def _after_letter_processing_deadline():
|
||||
current_utc_datetime = datetime.utcnow()
|
||||
current_utc_datetime = utc_now()
|
||||
bst_time = current_utc_datetime.time()
|
||||
|
||||
return bst_time >= LETTER_PROCESSING_DEADLINE
|
||||
|
||||
|
||||
def _notification_created_before_today_deadline(notification_created_at):
|
||||
current_bst_datetime = datetime.utcnow()
|
||||
current_bst_datetime = utc_now()
|
||||
todays_deadline = current_bst_datetime.replace(
|
||||
hour=LETTER_PROCESSING_DEADLINE.hour,
|
||||
minute=LETTER_PROCESSING_DEADLINE.minute,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import math
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from functools import lru_cache
|
||||
from html import unescape
|
||||
from os import path
|
||||
@@ -13,6 +12,7 @@ from notifications_utils import (
|
||||
LETTER_MAX_PAGE_COUNT,
|
||||
MAGIC_SEQUENCE,
|
||||
SMS_CHAR_COUNT_LIMIT,
|
||||
utc_now,
|
||||
)
|
||||
from notifications_utils.countries.data import Postage
|
||||
from notifications_utils.field import Field, PlainTextField
|
||||
@@ -739,7 +739,7 @@ class BaseLetterTemplate(SubjectMixin, Template):
|
||||
)
|
||||
self.admin_base_url = admin_base_url
|
||||
self.logo_file_name = logo_file_name
|
||||
self.date = date or datetime.utcnow()
|
||||
self.date = date or utc_now()
|
||||
|
||||
@property
|
||||
def subject(self):
|
||||
|
||||
Reference in New Issue
Block a user