-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatetimeParser.py
More file actions
61 lines (42 loc) · 1.38 KB
/
DatetimeParser.py
File metadata and controls
61 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from abc import ABCMeta
from datetime import datetime
class DatetimeParser(metaclass=ABCMeta):
def parse(self, string):
pass
def getHour(self):
pass
class AndroidDatetimeParser(DatetimeParser):
def parse(self, string):
try:
year, rest = string.split('년')
except ValueError as e:
raise ValueError
month, rest = rest.split('월')
day, rest = rest.split('일')
hourFlag, time = rest.strip().split(' ')
hour, minute = time.split(':')
hour = int(hour)
if hourFlag == '오전':
if hour == 12:
hour = 0
else:
if hour < 12:
hour += 12
return datetime(int(year), int(month), int(day), hour, int(minute), 0)
def getHour(self, string):
return self.parse(string).hour
class IOSDateTimeParser(DatetimeParser):
def parse(self, string):
year, month, day, rest = string.split('.')
hourFlag, time = rest.strip().split(' ')
hour, minute = time.split(':')
hour = int(hour)
if hourFlag == '오전':
if hour == 12:
hour = 0
else:
if hour < 12:
hour += 12
return datetime(int(year), int(month), int(day), hour, int(minute), 0)
def getHour(self, string):
return self.parse(string).hour