time and date utils

This commit is contained in:
Kameron Kenny 2024-10-02 16:27:13 -04:00
parent c5959a945f
commit 3a79f22315
No known key found for this signature in database
GPG Key ID: E5006629839D2276
2 changed files with 39 additions and 0 deletions

0
__model.py Normal file
View File

39
_time_and_date_utils.py Normal file
View File

@ -0,0 +1,39 @@
import time
from datetime import datetime
def convert_from_seconds(seconds):
return time.strftime("%H:%M:%S", time.gmtime(seconds))
def set_generic_date_time(datestamp='1900:01:01',
timestamp='00:00:00',
f='%Y:%m:%d %H:%M:%S'):
t = datetime.strptime(str(f'{datestamp} {timestamp}'), f)
return t
def process_img_date_tag(tag, image_tags, date_time_format):
try:
t = datetime.strptime(str(image_tags[tag]), date_time_format)
except:
t = None
return t
def get_img_date(image_tags):
t = None
for tag in image_tags:
if 'DateTime' in tag:
t = tag
break
for f in ['%Y:%m:%d %H:%M:%S',
'%Y/%m/%d %H:%M:%S',
'%Y-%m-%d-%H-%M-%S']:
dt_tag = process_img_date_tag(t,image_tags,f)
if dt_tag is not None:
break
if dt_tag is None:
dt_tag = set_generic_date_time()
return dt_tag