bugfix
This commit is contained in:
parent
9cefb5b53e
commit
7cbeef06ed
@ -33,7 +33,7 @@ def isMonthLastDay(d):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isLearYear(year):
|
def isLeapYear(year):
|
||||||
if year % 4 == 0 and year % 100 == 0 and not (year % 400 == 0):
|
if year % 4 == 0 and year % 100 == 0 and not (year % 400 == 0):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -49,8 +49,7 @@ def addSeconds(dt,s):
|
|||||||
return ndt
|
return ndt
|
||||||
|
|
||||||
def monthMaxDay(y,m):
|
def monthMaxDay(y,m):
|
||||||
dt = ymdDate(y,m,1)
|
if isLeapYear(y):
|
||||||
if isLeapYear(dt):
|
|
||||||
return leapMonthDays[m]
|
return leapMonthDays[m]
|
||||||
return unleapMonthDays[m]
|
return unleapMonthDays[m]
|
||||||
|
|
||||||
@ -78,18 +77,27 @@ def ymdDate(y,m,d,H=0,M=0,S=0):
|
|||||||
return datetime.datetime(y,m,d,H,M,S)
|
return datetime.datetime(y,m,d,H,M,S)
|
||||||
|
|
||||||
def str2Datetime(dstr):
|
def str2Datetime(dstr):
|
||||||
d,t = dstr.split(' ')
|
x = dstr.split(' ')
|
||||||
|
d = x[0]
|
||||||
|
t = '00:00:00'
|
||||||
|
if len(x) > 1:
|
||||||
|
t = x[1]
|
||||||
y,m,d = d.split('-')
|
y,m,d = d.split('-')
|
||||||
H,M,S = t.split(':')
|
H,M,S = t.split(':')
|
||||||
return datetime.datetime(int(y),int(m),int(d),int(H),int(M),int(S))
|
return datetime.datetime(int(y),int(m),int(d),int(H),int(M),int(S))
|
||||||
|
|
||||||
|
def strdate_add(date_str, days=0, months=0, years=0):
|
||||||
|
dt = str2Datetime(date_str)
|
||||||
|
dt = dateAdd(dt, days=days, months=months, years=years)
|
||||||
|
ds = date2str(dt)
|
||||||
|
return ds
|
||||||
|
|
||||||
def addMonths(dt,months):
|
def addMonths(dt,months):
|
||||||
y = dt.year()
|
y = dt.year
|
||||||
m = dt.month()
|
m = dt.month + months
|
||||||
d = dt.day()
|
d = dt.day
|
||||||
mm = m % 12
|
mm = (m - 1) % 12 + 1
|
||||||
md = m / 12
|
md = int((m - 1) / 12)
|
||||||
if md != 0:
|
|
||||||
y += md
|
y += md
|
||||||
m = mm
|
m = mm
|
||||||
maxd = monthMaxDay(y,m)
|
maxd = monthMaxDay(y,m)
|
||||||
@ -98,9 +106,9 @@ def addMonths(dt,months):
|
|||||||
return ymdDate(y,m,d)
|
return ymdDate(y,m,d)
|
||||||
|
|
||||||
def addYears(dt,years):
|
def addYears(dt,years):
|
||||||
y = dt.year() + years
|
y = dt.year + years
|
||||||
m = dt.month()
|
m = dt.month
|
||||||
d = dt.day()
|
d = dt.day
|
||||||
maxd = monthMaxDay(y,m)
|
maxd = monthMaxDay(y,m)
|
||||||
if d > maxd:
|
if d > maxd:
|
||||||
d = maxd
|
d = maxd
|
||||||
|
Loading…
Reference in New Issue
Block a user