From c3a3f81aff400c91d4b6af5f3b068802a0ab861a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 23:16:59 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v2.38.0 → v2.38.2](https://github.com/asottile/pyupgrade/compare/v2.38.0...v2.38.2) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 63b1efcc3..a54930fce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - flake8-bugbear exclude: doc/source/conf.py - repo: https://github.com/asottile/pyupgrade - rev: v2.38.0 + rev: v2.38.2 hooks: - id: pyupgrade args: [--py36-plus] From 49f4629d4a09befa0a995918399db112ad14712b Mon Sep 17 00:00:00 2001 From: "Daniel J. Perry" Date: Wed, 28 Sep 2022 16:21:25 -0400 Subject: [PATCH 2/3] Accept datetime fields as floats --- khal/parse_datetime.py | 12 ++++++------ tests/parse_datetime_test.py | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/khal/parse_datetime.py b/khal/parse_datetime.py index 35cfac05f..b1b6f9a71 100644 --- a/khal/parse_datetime.py +++ b/khal/parse_datetime.py @@ -291,7 +291,7 @@ def guesstimedeltafstr(delta_string: str) -> dt.timedelta: :rtype: datetime.timedelta """ - tups = re.split(r'(-?\d+)', delta_string) + tups = re.split(r'(-?\d+\.?\d*)', delta_string) if not re.match(r'^\s*$', tups[0]): raise ValueError('Invalid beginning of timedelta string "%s": "%s"' % (delta_string, tups[0])) @@ -300,22 +300,22 @@ def guesstimedeltafstr(delta_string: str) -> dt.timedelta: for num, unit in zip(tups[0::2], tups[1::2]): try: - numint = int(num) + numfloat = float(num) except ValueError: raise DateTimeParseError( f'Invalid number in timedelta string "{delta_string}": "{num}"') ulower = unit.lower().strip() if ulower == 'd' or ulower == 'day' or ulower == 'days': - res += dt.timedelta(days=numint) + res += dt.timedelta(days=numfloat) elif ulower == 'h' or ulower == 'hour' or ulower == 'hours': - res += dt.timedelta(hours=numint) + res += dt.timedelta(hours=numfloat) elif (ulower == 'm' or ulower == 'minute' or ulower == 'minutes' or ulower == 'min'): - res += dt.timedelta(minutes=numint) + res += dt.timedelta(minutes=numfloat) elif (ulower == 's' or ulower == 'second' or ulower == 'seconds' or ulower == 'sec'): - res += dt.timedelta(seconds=numint) + res += dt.timedelta(seconds=numfloat) else: raise ValueError('Invalid unit in timedelta string "%s": "%s"' % (delta_string, unit)) diff --git a/tests/parse_datetime_test.py b/tests/parse_datetime_test.py index b7412f742..0b007ec7d 100644 --- a/tests/parse_datetime_test.py +++ b/tests/parse_datetime_test.py @@ -183,6 +183,9 @@ def test_single(self): def test_seconds(self): assert dt.timedelta(seconds=10) == guesstimedeltafstr('10s') + def test_decimal(self): + assert dt.timedelta(hours=1.5) == guesstimedeltafstr('1.5h') + def test_negative(self): assert dt.timedelta(minutes=-10) == guesstimedeltafstr('-10m') From 4a3eea003ee1a2cc1bb589f9362c88db168a3a2a Mon Sep 17 00:00:00 2001 From: "Daniel J. Perry" Date: Wed, 28 Sep 2022 20:50:05 -0400 Subject: [PATCH 3/3] Add my name to authors --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 3fc9a8277..30442a57a 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -47,3 +47,4 @@ Fred Thomsen - me [at] fredthomsen [dot] net - http://fredthomsen.net Robin Schubert Axel Gschaider - axel.gschaider [at] posteo [dot] de Anuragh - kpanuragh [at] gmail [dot] com +Daniel James Perry - dperry45 [at] gatech [dot] edu