From 2a5d9498d1dd7bb6ac62a27d518a87542ec3f344 Mon Sep 17 00:00:00 2001 From: Krateng Date: Fri, 15 Jan 2021 19:57:53 +0100 Subject: [PATCH] Restored functionality for older Python versions --- maloja/__pkginfo__.py | 2 +- maloja/malojatime.py | 2 +- maloja/monkey.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index 98957c7..6123e25 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -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", diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 588cb8c..78eb801 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -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) diff --git a/maloja/monkey.py b/maloja/monkey.py index 8a0974e..0e02757 100644 --- a/maloja/monkey.py +++ b/maloja/monkey.py @@ -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