Skip to content

Commit

Permalink
fix: ensure expiration date is properly formatted (bcgov#1564)
Browse files Browse the repository at this point in the history
* fix: ensure expiration date is properly formatted

* fix: update expiration date to be end of day pacific time
  • Loading branch information
EPortman authored Aug 22, 2024
1 parent d40cd04 commit faa8d6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.2.2'
__version__ = '1.2.3'

21 changes: 21 additions & 0 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

from datetime import datetime
from pytz import timezone, UTC

from flask import request, jsonify, g, current_app, make_response
from flask_restx import Namespace, Resource, fields, cors
Expand Down Expand Up @@ -749,6 +750,26 @@ def put(nr, *args, **kwargs):
json_input['submittedDate'] = str(datetime.strptime(
str(json_input['submittedDate'][5:]), '%d %b %Y %H:%M:%S %Z'))

# convert Expiration Date to correct format
if json_input.get('expirationDate', None):
expiration_str = json_input['expirationDate']

# Convert the date (either UTC or ISO) into a UTC datetime object
if expiration_str.endswith('UTC'):
parsed_date = datetime.strptime(expiration_str[5:], '%d %b %Y %H:%M:%S %Z')
parsed_date = parsed_date.replace(tzinfo=UTC)
else:
parsed_date = datetime.fromisoformat(expiration_str)
if parsed_date.tzinfo is None:
parsed_date = parsed_date.replace(tzinfo=UTC) # If it's naive, assume UTC
else:
parsed_date = parsed_date.astimezone(UTC) # Convert any timezone-aware datetime to UTC

# Convert the UTC datetime object to the end of day in pacific time without milliseconds
pacific_time = parsed_date.astimezone(timezone('US/Pacific'))
end_of_day_pacific = pacific_time.replace(hour=23, minute=59, second=0, microsecond=0)
json_input['expirationDate'] = end_of_day_pacific.strftime('%Y-%m-%d %H:%M:%S%z')

# convert NWPTA dates to correct format
if json_input.get('nwpta', None):
for region in json_input['nwpta']:
Expand Down

0 comments on commit faa8d6a

Please sign in to comment.