mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
Modifications to Date object to handle multiple string format
Signed-off-by: Christian Tremblay, ing. <christian.tremblay@servisys.com>
This commit is contained in:
parent
852b1833dc
commit
736187580b
|
@ -1132,17 +1132,20 @@ class Date(Atomic):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_app_tag = Tag.dateAppTag
|
_app_tag = Tag.dateAppTag
|
||||||
_date_regex_mmddyyyy = re.compile(r'[0-1]*\d[-/][0-3]*\d[-/]\d{4}$')
|
_date_regex_mmddyyyy = re.compile(r'([0-1]*\d)[-/]([0-3]*\d)[-/](\d{4}$)')
|
||||||
_date_regex_ddmmyyyy = re.compile(r'[0-3]*\d[-/][0-1]*\d[-/]\d{4}$')
|
_date_regex_yyyymmdd = re.compile(r'(\d{4})[-/]([0-1]*\d)[-/]([0-3]*\d$)')
|
||||||
_date_regex_mmddyy = re.compile(r'[0-1]*\d[-/][0-3]*\d[-/]\d{2}$')
|
_date_regex_ddmmyyyy = re.compile(r'([0-3]*\d)[-/]([0-1]*\d)[-/](\d{4}$)')
|
||||||
_date_regex_ddmmyy = re.compile(r'[0-3]*\d[-/][0-1]*\d[-/]\d{2}$')
|
_date_regex_mmddyy = re.compile(r'([0-1]*\d)[-/]([0-3]*\d)[-/](\d{2}$)')
|
||||||
|
_date_regex_ddmmyy = re.compile(r'([0-3]*\d)[-/]([0-1]*\d)[-/](\d{2}$)')
|
||||||
|
_date_regex_dmy = re.compile(r'(\d)[-/](\d)[-/](\d$)')
|
||||||
_day_names = ['', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
_day_names = ['', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||||
|
|
||||||
DONT_CARE = 255
|
DONT_CARE = 255
|
||||||
|
|
||||||
def __init__(self, arg=None, year=255, month=255, day=255, dayOfWeek=255):
|
def __init__(self, arg=None, year=255, month=255, day=255, dayOfWeek=255):
|
||||||
self.value = (year, month, day, dayOfWeek)
|
self.value = (year, month, day, dayOfWeek)
|
||||||
|
date_groups = [0,0,0,None]
|
||||||
|
|
||||||
if arg is None:
|
if arg is None:
|
||||||
pass
|
pass
|
||||||
elif isinstance(arg,Tag):
|
elif isinstance(arg,Tag):
|
||||||
|
@ -1150,25 +1153,39 @@ class Date(Atomic):
|
||||||
elif isinstance(arg, tuple):
|
elif isinstance(arg, tuple):
|
||||||
self.value = arg
|
self.value = arg
|
||||||
elif isinstance(arg, str):
|
elif isinstance(arg, str):
|
||||||
if Date._date_regex_mmddyyyy.match(arg) and not Date._date_regex_ddmmyyyy.match(arg):
|
if (Date._date_regex_mmddyyyy.match(arg) and not Date._date_regex_ddmmyyyy.match(arg)):
|
||||||
#Will be mmddyyyy
|
#Will be mmddyyyy
|
||||||
pass
|
month, day, year = Date._date_regex_mmddyyyy.match(arg).groups()
|
||||||
|
|
||||||
|
elif Date._date_regex_yyyymmdd.match(arg):
|
||||||
|
#will be yyyymmdd
|
||||||
|
year, month, day = Date._date_regex_yyyymmdd.match(arg).groups()
|
||||||
|
|
||||||
elif Date._date_regex_ddmmyyyy.match(arg) and not Date._date_regex_mmddyyyy.match(arg) :
|
elif Date._date_regex_ddmmyyyy.match(arg) and not Date._date_regex_mmddyyyy.match(arg) :
|
||||||
#will be ddmmyyyy
|
#will be ddmmyyyy
|
||||||
pass
|
day, month, year = Date._date_regex_ddmmyyyy.match(arg).groups()
|
||||||
|
|
||||||
elif Date._date_regex_ddmmyyyy.match(arg) and Date._date_regex_mmddyyyy.match(arg) :
|
elif Date._date_regex_ddmmyyyy.match(arg) and Date._date_regex_mmddyyyy.match(arg) :
|
||||||
#will be ddmmyyyy
|
#will be ddmmyyyy
|
||||||
pass
|
day, month, year = Date._date_regex_ddmmyyyy.match(arg).groups()
|
||||||
elif Date._date_regex_mmddyy.match(arg) and not Date._date_regex_mmddyy.match(arg) :
|
|
||||||
pass
|
elif Date._date_regex_ddmmyy.match(arg) and not Date._date_regex_mmddyy.match(arg) :
|
||||||
elif Date._date_regex_mmddyy.match(arg) and not Date._date_regex_mmddyy.match(arg):
|
day, month, year = Date._date_regex_ddmmyy.match(arg).groups()
|
||||||
pass
|
|
||||||
elif Date._date_regex_mmddyy.match(arg) and Date._date_regex_mmddyy.match(arg):
|
elif Date._date_regex_mmddyy.match(arg) and not Date._date_regex_ddmmyy.match(arg):
|
||||||
pass
|
month, day, year = Date._date_regex_mmddyy.match(arg).groups()
|
||||||
|
|
||||||
|
elif Date._date_regex_ddmmyy.match(arg) and Date._date_regex_mmddyy.match(arg):
|
||||||
|
day, month, year = Date._date_regex_ddmmyy.match(arg).groups()
|
||||||
|
elif Date._date_regex_dmy.match(arg):
|
||||||
|
day, month, year = Date._date_regex_dmy.match(arg).groups()
|
||||||
else:
|
else:
|
||||||
raise ValueError("invalid date pattern")
|
raise ValueError("invalid date pattern")
|
||||||
date_groups = date_match.groups()
|
|
||||||
|
|
||||||
|
|
||||||
|
date_groups[0] = year
|
||||||
|
date_groups[1] = month
|
||||||
|
date_groups[2] = day
|
||||||
# day/month/year
|
# day/month/year
|
||||||
tup_list = []
|
tup_list = []
|
||||||
for s in date_groups[:3]:
|
for s in date_groups[:3]:
|
||||||
|
@ -1180,8 +1197,8 @@ class Date(Atomic):
|
||||||
tup_list.append(int(s))
|
tup_list.append(int(s))
|
||||||
|
|
||||||
# clean up the year
|
# clean up the year
|
||||||
if (tup_list[2] < 100):
|
if (tup_list[0] < 100):
|
||||||
tup_list[2] += 2000
|
tup_list[0] += 1900
|
||||||
#tup_list[1] -= 1900
|
#tup_list[1] -= 1900
|
||||||
|
|
||||||
# day-of-week madness
|
# day-of-week madness
|
||||||
|
@ -1251,7 +1268,7 @@ class Date(Atomic):
|
||||||
if year == 255:
|
if year == 255:
|
||||||
rslt += "* "
|
rslt += "* "
|
||||||
else:
|
else:
|
||||||
rslt += "%d " % (year + 1900,)
|
rslt += "%d " % (year,)
|
||||||
if dayOfWeek == 255:
|
if dayOfWeek == 255:
|
||||||
rslt += "*)"
|
rslt += "*)"
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user