@@ -525,6 +525,8 @@ def verify_final_ack_file(file_key):
525525def get_file_name (vax_type , ods , version = "4" ):
526526 timestamp = datetime .now (timezone .utc ).strftime ("%Y%m%dT%H%M%S00" )
527527 # timestamp = timestamp[:-3]
528+ if is_valid_datetime (timestamp ) is False :
529+ print ("Timestamp is not valid" )
528530 return f"{ vax_type } _Vaccinations_v{ version } _{ ods } _{ timestamp } .csv"
529531
530532
@@ -546,3 +548,24 @@ def generate_csv_file(seed: TestData, actions: str) -> str:
546548 file_name = get_file_name (seed .vax , seed .ods , seed .version )
547549 df .to_csv (file_name , index = False , sep = "|" , quoting = csv .QUOTE_MINIMAL )
548550 return file_name
551+
552+
553+ def is_valid_datetime (timestamp : str ) -> bool :
554+ """
555+ Returns a bool to indicate whether the timestamp is a valid datetime in the format 'YYYYmmddTHHMMSSzz'
556+ where 'zz' is a two digit number indicating the timezone
557+ """
558+ # Check that datetime (excluding timezone) is a valid datetime in the expected format.
559+ print (f"Validating timestamp: { timestamp } " )
560+ if len (timestamp ) < 15 :
561+ print ("Timestamp is too short" )
562+ return False
563+
564+ # Note that any digits after the seconds (i.e. from the 16th character onwards, usually expected to represent
565+ # timezone), do not need to be validated
566+ try :
567+ datetime .strptime (timestamp [:15 ], "%Y%m%dT%H%M%S" )
568+ except ValueError :
569+ return False
570+
571+ return True
0 commit comments