From c87dc32455e0095195f0351195e4b038162db88c Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 30 Nov 2020 14:02:03 -0500 Subject: [PATCH 1/6] Display full datetime using system timezone When displaying a full datetime to the user use the system timezone instead of hardcoded UTC --- maloja/malojatime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 43379c6..cc6cf4d 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -545,7 +545,7 @@ def timestamp_desc(t,short=False): return timeobject.strftime("%Y") else: - timeobject = datetime.datetime.utcfromtimestamp(t) + timeobject = datetime.datetime.fromtimestamp(t) return timeobject.strftime("%d. %b %Y %I:%M %p") From e475b0c7160142c4b9d9524d2d2a3013c09067a1 Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 1 Dec 2020 18:59:39 +0100 Subject: [PATCH 2/6] Added setting for timezone --- maloja/data_files/settings/default.ini | 3 +++ maloja/malojatime.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/maloja/data_files/settings/default.ini b/maloja/data_files/settings/default.ini index 824e695..4c11155 100644 --- a/maloja/data_files/settings/default.ini +++ b/maloja/data_files/settings/default.ini @@ -71,6 +71,9 @@ CHARTS_DISPLAY_TILES = false # prevent visitors from mindlessly clicking on those options and hogging your cpu DISCOURAGE_CPU_HEAVY_STATS = false +# offset to UTC +TIMEZONE = 0 + [Fluff] # how many scrobbles a track needs to aquire this status diff --git a/maloja/malojatime.py b/maloja/malojatime.py index cc6cf4d..712f4d8 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -1,9 +1,13 @@ import datetime from datetime import datetime as dtm +from datetime import timezone, timedelta from calendar import monthrange from os.path import commonprefix import math +from doreah.settings import get_settings +OFFSET = get_settings("TIMEZONE") +TIMEZONE = timezone(timedelta(hours=OFFSET)) FIRST_SCROBBLE = int(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()) @@ -545,7 +549,7 @@ def timestamp_desc(t,short=False): return timeobject.strftime("%Y") else: - timeobject = datetime.datetime.fromtimestamp(t) + timeobject = datetime.datetime.fromtimestamp(t,tz=TIMEZONE) return timeobject.strftime("%d. %b %Y %I:%M %p") From 951f6bb5623a8d8a77cec752ceb53b619ba5cd0a Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 1 Dec 2020 19:12:20 +0100 Subject: [PATCH 3/6] Timeranges should now consider timezone --- maloja/malojatime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 712f4d8..5ca28a5 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -182,10 +182,10 @@ class MTime(MRangeDescriptor): def first_stamp(self): day = self.first_day().dateobject - return int(datetime.datetime.combine(day,datetime.time(tzinfo=datetime.timezone.utc)).timestamp()) + return int(datetime.datetime.combine(day,datetime.time(tzinfo=TIMEZONE)).timestamp()) def last_stamp(self): day = self.last_day().dateobject + datetime.timedelta(days=1) - return int(datetime.datetime.combine(day,datetime.time(tzinfo=datetime.timezone.utc)).timestamp() - 1) + return int(datetime.datetime.combine(day,datetime.time(tzinfo=TIMEZONE)).timestamp() - 1) # next range of equal length (not exactly same amount of days, but same precision level) def next(self,step=1): From e6535eb6bc3f9df93be176c702c730153d055f7c Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 1 Dec 2020 19:19:01 +0100 Subject: [PATCH 4/6] Adjusted predefined ranges to consider timezone --- maloja/malojatime.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 5ca28a5..89aae20 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -383,18 +383,18 @@ y = MTime(2020) def today(): - tod = datetime.datetime.utcnow() + tod = datetime.datetime.now(tz=TIMEZONE) return MTime(tod.year,tod.month,tod.day) def thisweek(): - tod = datetime.datetime.utcnow() + tod = datetime.datetime.now(tz=TIMEZONE) tod = datetime.date(tod.year,tod.month,tod.day) y,w,_ = tod.chrcalendar() return MTimeWeek(y,w) def thismonth(): - tod = datetime.datetime.utcnow() + tod = datetime.datetime.now(tz=TIMEZONE) return MTime(tod.year,tod.month) def thisyear(): - tod = datetime.datetime.utcnow() + tod = datetime.datetime.now(tz=TIMEZONE) return MTime(tod.year) def alltime(): return MRange(None,None) From 75d8251a2967658d40a8a6e4cc42cda3b1849c06 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 1 Dec 2020 15:48:56 -0500 Subject: [PATCH 5/6] Use system timezone as TIMEZONE setting default --- maloja/data_files/settings/default.ini | 6 ++++-- maloja/malojatime.py | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/maloja/data_files/settings/default.ini b/maloja/data_files/settings/default.ini index 4c11155..5c72b93 100644 --- a/maloja/data_files/settings/default.ini +++ b/maloja/data_files/settings/default.ini @@ -71,8 +71,10 @@ CHARTS_DISPLAY_TILES = false # prevent visitors from mindlessly clicking on those options and hogging your cpu DISCOURAGE_CPU_HEAVY_STATS = false -# offset to UTC -TIMEZONE = 0 +# Use system timezone by default. Otherwise specify as either: +# offset in hours IE 0 = UTC, -5 = EST +# IANA time zone IE America/New_York = EST +TIMEZONE = None [Fluff] diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 89aae20..6853afd 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -6,8 +6,13 @@ from os.path import commonprefix import math from doreah.settings import get_settings +# use system timezone as default +# https://stackoverflow.com/a/39079819/1469797 +TIMEZONE = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo +# if user specifies a timezone in settings then try to use that instead OFFSET = get_settings("TIMEZONE") -TIMEZONE = timezone(timedelta(hours=OFFSET)) +if OFFSET is not None: + TIMEZONE = timezone(timedelta(hours=OFFSET)) FIRST_SCROBBLE = int(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()) From 64bb2350111b9aa5bf8e4a27358332a3c367cb40 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 12 Dec 2020 17:23:29 +0100 Subject: [PATCH 6/6] Fixed daily execution of tasks for different timezones --- maloja/__pkginfo__.py | 2 +- maloja/data_files/settings/default.ini | 6 ++---- maloja/globalconf.py | 7 ++++--- maloja/malojatime.py | 8 ++------ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index 2e9b709..9f8b37a 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -15,7 +15,7 @@ links = { requires = [ "bottle>=0.12.16", "waitress>=1.3", - "doreah>=1.6.10", + "doreah>=1.6.13", "nimrodel>=0.6.4", "setproctitle>=1.1.10", "wand>=0.5.4", diff --git a/maloja/data_files/settings/default.ini b/maloja/data_files/settings/default.ini index 5c72b93..b929df3 100644 --- a/maloja/data_files/settings/default.ini +++ b/maloja/data_files/settings/default.ini @@ -71,10 +71,8 @@ CHARTS_DISPLAY_TILES = false # prevent visitors from mindlessly clicking on those options and hogging your cpu DISCOURAGE_CPU_HEAVY_STATS = false -# Use system timezone by default. Otherwise specify as either: -# offset in hours IE 0 = UTC, -5 = EST -# IANA time zone IE America/New_York = EST -TIMEZONE = None +# Offset in hours to UTC +TIMEZONE = 0 [Fluff] diff --git a/maloja/globalconf.py b/maloja/globalconf.py index 4404677..61adb2c 100644 --- a/maloja/globalconf.py +++ b/maloja/globalconf.py @@ -57,9 +57,6 @@ config( caching={ "folder": datadir("cache") }, - regular={ - "autostart": False - }, auth={ "multiuser":False, "cookieprefix":"maloja", @@ -74,6 +71,10 @@ settingsconfig._readpreconfig() config( logging={ "logfolder": datadir("logs") if get_settings("LOGGING") else None + }, + regular={ + "autostart": False, + "offset": get_settings("TIMEZONE") } ) diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 6853afd..59b023c 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -6,13 +6,9 @@ from os.path import commonprefix import math from doreah.settings import get_settings -# use system timezone as default -# https://stackoverflow.com/a/39079819/1469797 -TIMEZONE = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo -# if user specifies a timezone in settings then try to use that instead + OFFSET = get_settings("TIMEZONE") -if OFFSET is not None: - TIMEZONE = timezone(timedelta(hours=OFFSET)) +TIMEZONE = timezone(timedelta(hours=OFFSET)) FIRST_SCROBBLE = int(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp())