forked from WMInfoTech/python-msgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
24 lines (21 loc) · 878 Bytes
/
base.py
File metadata and controls
24 lines (21 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from datetime import datetime
class Base(object):
date_format = '%Y-%m-%d'
time_format = '%H:%M:%S'
datetime_format = date_format + 'T%s' % time_format
full_datetime_format = date_format + 'T' + time_format + '.%f'
iso_format = date_format + 'T%sZ' % time_format
standard_datetime_format = date_format + ' ' + time_format
extended_datetime_format = date_format + 'T' + time_format +'.%fZ'
@classmethod
def parse_date_time(cls, text):
instance = None
formats = [cls.extended_datetime_format, cls.full_datetime_format, cls.datetime_format, cls.standard_datetime_format, cls.iso_format, cls.date_format]
for format in formats:
try:
instance = datetime.strptime(text, format)
except Exception:
pass
else:
break
return instance