From 715401ca8eaa49c29b56f63132ce3bcec2f7f89f Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 15 May 2022 13:51:44 +0200 Subject: [PATCH] fix timezone in search, zipfiles, fuse --- bin/copyparty-fuse-streaming.py | 3 ++- bin/copyparty-fuse.py | 3 ++- copyparty/szip.py | 6 +++--- copyparty/u2idx.py | 11 +++++------ copyparty/web/browser.js | 3 +++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bin/copyparty-fuse-streaming.py b/bin/copyparty-fuse-streaming.py index a3ff6846..df4938e8 100755 --- a/bin/copyparty-fuse-streaming.py +++ b/bin/copyparty-fuse-streaming.py @@ -42,6 +42,7 @@ import threading import traceback import http.client # py2: httplib import urllib.parse +import calendar from datetime import datetime from urllib.parse import quote_from_bytes as quote from urllib.parse import unquote_to_bytes as unquote @@ -495,7 +496,7 @@ class Gateway(object): ts = 60 * 60 * 24 * 2 try: sz = int(fsize) - ts = datetime.strptime(fdate, "%Y-%m-%d %H:%M:%S").timestamp() + ts = calendar.timegm(time.strptime(fdate, "%Y-%m-%d %H:%M:%S")) except: info("bad HTML or OS [{}] [{}]".format(fdate, fsize)) # python cannot strptime(1959-01-01) on windows diff --git a/bin/copyparty-fuse.py b/bin/copyparty-fuse.py index cef8389d..2f7e4044 100755 --- a/bin/copyparty-fuse.py +++ b/bin/copyparty-fuse.py @@ -45,6 +45,7 @@ import threading import traceback import http.client # py2: httplib import urllib.parse +import calendar from datetime import datetime from urllib.parse import quote_from_bytes as quote from urllib.parse import unquote_to_bytes as unquote @@ -443,7 +444,7 @@ class Gateway(object): ts = 60 * 60 * 24 * 2 try: sz = int(fsize) - ts = datetime.strptime(fdate, "%Y-%m-%d %H:%M:%S").timestamp() + ts = calendar.timegm(time.strptime(fdate, "%Y-%m-%d %H:%M:%S")) except: info("bad HTML or OS [{}] [{}]".format(fdate, fsize)) # python cannot strptime(1959-01-01) on windows diff --git a/copyparty/szip.py b/copyparty/szip.py index 8e18eace..ff182033 100644 --- a/copyparty/szip.py +++ b/copyparty/szip.py @@ -3,7 +3,7 @@ from __future__ import print_function, unicode_literals import time import zlib -from datetime import datetime +import calendar from .sutil import errdesc from .util import yieldfile, sanitize_fn, spack, sunpack, min_ex @@ -25,8 +25,8 @@ def dostime2unix(buf): tf = "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}" iso = tf.format(*tt) - dt = datetime.strptime(iso, "%Y-%m-%d %H:%M:%S") - return int(dt.timestamp()) + dt = time.strptime(iso, "%Y-%m-%d %H:%M:%S") + return int(calendar.timegm(dt)) def unixtime2dos(ts): diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index 4228e9fc..89400133 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -4,8 +4,8 @@ from __future__ import print_function, unicode_literals import re import os import time +import calendar import threading -from datetime import datetime from operator import itemgetter from .__init__ import ANYWIN, unicode @@ -190,18 +190,17 @@ class U2idx(object): if is_date: is_date = False - v = v.upper().rstrip("Z").replace(",", " ").replace("T", " ") - while " " in v: - v = v.replace(" ", " ") - + v = re.sub(r"[tzTZ, ]+", " ", v).strip() for fmt in [ "%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d %H", "%Y-%m-%d", + "%Y-%m", + "%Y", ]: try: - v = datetime.strptime(v, fmt).timestamp() + v = calendar.timegm(time.strptime(v, fmt)) break except: pass diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index df1887c9..5db250af 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -4056,6 +4056,9 @@ document.onkeydown = function (e) { vs = ebi('srch_' + k + 'v').value, tvs = []; + if (a == 1) + vs = vs.trim().replace(/ +/, 'T'); + while (vs) { vs = vs.trim(); if (!vs)