Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit ff5ba65

Browse files
mrGrazyhjacobs
authored andcommitted
Weekday should respect timezone (#25)
* weekday should come from local_time * added test to time spec
1 parent 9f55506 commit ff5ba65

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

kube_downscaler/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def matches_time_spec(time: datetime.datetime, spec: str):
5656
if not match:
5757
raise ValueError(
5858
f'Time spec value "{spec}" does not match format (Mon-Fri 06:30-20:30 Europe/Berlin)')
59-
day_from = WEEKDAYS.index(match.group(1).upper())
60-
day_to = WEEKDAYS.index(match.group(2).upper())
61-
day_matches = day_from <= time.weekday() <= day_to
6259
tz = pytz.timezone(match.group('tz'))
6360
local_time = tz.fromutc(time.replace(tzinfo=tz))
61+
day_from = WEEKDAYS.index(match.group(1).upper())
62+
day_to = WEEKDAYS.index(match.group(2).upper())
63+
day_matches = day_from <= local_time.weekday() <= day_to
6464
local_time_minutes = local_time.hour * 60 + local_time.minute
6565
minute_from = int(match.group(3)) * 60 + int(match.group(4))
6666
minute_to = int(match.group(5)) * 60 + int(match.group(6))

tests/test_time.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ def test_time_spec():
2121
assert not matches_time_spec(dt, 'Mon-Fri 08:00-18:00 UTC')
2222

2323
assert matches_time_spec(dt, 'Mon-Fri 08:00-18:00 UTC, Sun-Sun 15:30-16:00 UTC')
24+
25+
dt = datetime(2018, 11, 4, 20, 30, 00)
26+
assert matches_time_spec(dt, 'Mon-Fri 09:00-10:00 Pacific/Auckland')
27+
assert not matches_time_spec(dt, 'Sat-Sun 09:00-10:00 Pacific/Auckland')

0 commit comments

Comments
 (0)