Skip to content

Commit 0d87c96

Browse files
authored
Merge pull request #6 from dapper91/dev
Dev
2 parents f6d210b + c0c8a25 commit 0d87c96

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
0.1.4 (2021-03-19)
5+
------------------
6+
7+
- timezone bug fixed
8+
9+
410
0.1.3 (2021-03-18)
511
------------------
612

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Quickstart
4141

4242

4343
Get next cron fire time:
44-
________________________
44+
~~~~~~~~~~~~~~~~~~~~~~~~
4545

4646
.. code-block:: python
4747
@@ -62,7 +62,7 @@ ________________________
6262
6363
6464
Iteration over cron fire times starting from now:
65-
_________________________________________________
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6666

6767
.. code-block:: python
6868

crontools/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__description__ = 'Python cron tools'
33
__url__ = 'https://github.com/dapper91/crontools'
44

5-
__version__ = '0.1.3'
5+
__version__ = '0.1.4'
66

77
__author__ = 'Dmitry Pershin'
88
__email__ = '[email protected]'

crontools/crontab.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class DayField:
289289
crontab week days and month days of the current month sequentially.
290290
"""
291291

292-
def __init__(self, monthday_field: Field[MonthdayRange], weekday_field: Field[WeekdayRange], tz: dt.timezone):
292+
def __init__(self, monthday_field: Field[MonthdayRange], weekday_field: Field[WeekdayRange], tz: dt.tzinfo):
293293
self._monthday_field = monthday_field
294294
self._weekday_field = weekday_field
295295
self._tz = tz
@@ -378,7 +378,7 @@ class Crontab:
378378

379379
seconds_ext: bool = False
380380
years_ext: bool = False
381-
tz: dt.timezone = dt.timezone.utc
381+
tz: dt.tzinfo = dt.timezone.utc
382382

383383
@property
384384
def day_field(self) -> DayField:
@@ -407,7 +407,7 @@ def parse(
407407
expr: str,
408408
seconds_ext: bool = False,
409409
years_ext: bool = False,
410-
tz: dt.timezone = tzlocal.get_localzone(),
410+
tz: dt.tzinfo = tzlocal.get_localzone(),
411411
now: Optional[dt.datetime] = None,
412412
) -> 'Crontab':
413413
"""
@@ -427,7 +427,7 @@ def parse(
427427
raise ValueError(f"crontab expression must be of {fields_number} fields")
428428

429429
fields_iter = iter(fields)
430-
now = now or dt.datetime.now(tz=tz)
430+
now = (now or dt.datetime.now(tz=tz)).astimezone(tz)
431431

432432
return cls(
433433
second_field=SecondsField.fromstr(next(fields_iter)) if seconds_ext else SecondsField.fromstr('0'),
@@ -439,7 +439,7 @@ def parse(
439439
year_field=YearField.fromstr(next(fields_iter)) if years_ext else YearField.fromstr(f'{now.year}-2099'),
440440
seconds_ext=seconds_ext,
441441
years_ext=years_ext,
442-
tz=tz,
442+
tz=now.tzinfo,
443443
)
444444

445445
def __iter__(self) -> Iterator[dt.datetime]:
@@ -461,6 +461,7 @@ def iter(self, start_from: dt.datetime) -> Iterator[dt.datetime]:
461461
:return: datetime iterator
462462
"""
463463

464+
start_from = start_from.astimezone(self.tz)
464465
first_run = True
465466
year_iter = self.year_field.iter(start_from=start_from.year)
466467

0 commit comments

Comments
 (0)