Skip to content

Commit

Permalink
Fix issue #41
Browse files Browse the repository at this point in the history
  • Loading branch information
ccl0326 committed Nov 13, 2022
1 parent c252c9f commit a7871c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.5.1

- Fixed scheduling issue. [#42](https://github.com/agilord/cron/issues/42) by [ccl0326](https://github.com/ccl0326)

## 0.5.0

- Improved time parsing. [#21](https://github.com/agilord/cron/issues/21) by [myConsciousness](https://github.com/myConsciousness)
Expand Down
12 changes: 12 additions & 0 deletions lib/cron.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,23 @@ class _ScheduledTask implements ScheduledTask {
Future? _running;
bool _overrun = false;

/// The datetime a Task last run.
DateTime lastTime = DateTime(0, 0, 0, 0, 0, 0, 0);

_ScheduledTask(this.schedule, this._task);

void tick(DateTime now) {
if (_closed) return;
if (!schedule.shouldRunAt(now)) return;
if ((schedule.seconds == null || lastTime.second == now.second) &&
(schedule.minutes == null || lastTime.minute == now.minute) &&
(schedule.hours == null || lastTime.hour == now.hour) &&
(schedule.days == null || lastTime.day == now.day) &&
(schedule.months == null || lastTime.month == now.month) &&
(schedule.weekdays == null || lastTime.weekday == now.weekday)) {
return;
}
lastTime = now;
_run();
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/constraint_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ List<int>? parseConstraint(dynamic constraint) {
if (constraint is int) return [constraint];
if (constraint is List<int>) return constraint;
if (constraint is String) {
if (constraint == '*' || constraint == '') return null;
if (constraint == '*') return List.generate(60, (i) => i);
if (constraint == '') return null;
final parts = constraint.split(',');
if (parts.length > 1) {
final items =
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: cron
description: A time-based job scheduler similar to cron. Run tasks periodically at fixed times or intervals.
version: 0.5.0
version: 0.5.1
homepage: https://github.com/agilord/cron

environment:
Expand Down

0 comments on commit a7871c1

Please sign in to comment.