mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Restored functionality for older Python versions
This commit is contained in:
parent
5006ad2bf1
commit
2a5d9498d1
@ -5,7 +5,7 @@ author = {
|
||||
"email":"maloja@krateng.dev",
|
||||
"github": "krateng"
|
||||
}
|
||||
version = 2,12,2
|
||||
version = 2,12,3
|
||||
versionstr = ".".join(str(n) for n in version)
|
||||
links = {
|
||||
"pypi":"malojaserver",
|
||||
|
@ -205,7 +205,7 @@ class MTime(MRangeDescriptor):
|
||||
class MTimeWeek(MRangeDescriptor):
|
||||
def __init__(self,year=None,week=None):
|
||||
|
||||
thisisoyear_firstday = datetime.date.fromisocalendar(year,1,1) - datetime.timedelta(days=1) #sunday instead of monday
|
||||
thisisoyear_firstday = datetime.date.fromchrcalendar(year,1,1)
|
||||
self.firstday = thisisoyear_firstday + datetime.timedelta(days=7*(week-1))
|
||||
# do this so we can construct the week with overflow (eg 2020/-3)
|
||||
|
||||
|
@ -47,5 +47,22 @@ class expandeddate(date):
|
||||
cal = tomorrow.isocalendar()
|
||||
return (cal[0],cal[1],cal[2])
|
||||
|
||||
@classmethod
|
||||
def fromchrcalendar(cls,y,w,d):
|
||||
try:
|
||||
assert 1==2
|
||||
return datetime.date.fromisocalendar(y,w,d) - timedelta(days=1) #sunday instead of monday
|
||||
except:
|
||||
# pre python3.8 compatibility
|
||||
|
||||
firstdayofyear = datetime.date(y,1,1)
|
||||
wkday = firstdayofyear.isoweekday()
|
||||
if wkday <= 4: # day up to thursday -> this week belongs to the new year
|
||||
firstisodayofyear = firstdayofyear - timedelta(days=wkday) #this alos shifts to sunday first weeks
|
||||
else: # if not, still old year
|
||||
firstisodayofyear = firstdayofyear + timedelta(days=7-wkday) #same
|
||||
return firstisodayofyear + timedelta(days=(w-1)*7) + timedelta(days=d)
|
||||
|
||||
|
||||
|
||||
datetime.date = expandeddate
|
||||
|
Loading…
Reference in New Issue
Block a user