Skip to content

Commit

Permalink
Fix recurrence calculation if start has microseconds
Browse files Browse the repository at this point in the history
Closes: #62
  • Loading branch information
JonasWanke committed Sep 13, 2023
1 parent 3c4d1f2 commit dc8da9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### 🐛 Bug Fixes
* fix string serialization with intl set to non-latin locale ([#60](https://github.com/JonasWanke/rrule/pull/60)), closes: [#59](https://github.com/JonasWanke/rrule/issues/59). Thanks to [@absar](https://github.com/absar)!
* fix recurrence calculation if start has microseconds, closes: [#62](https://github.com/JonasWanke/rrule/issues/62)

## 0.2.13 · 2023-03-22

Expand Down
14 changes: 11 additions & 3 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ extension InternalDateTimeRrule on DateTime {
Duration get timeOfDay => difference(atStartOfDay);

DateTime get atStartOfDay => DateTimeRrule(this)
.copyWith(hour: 0, minute: 0, second: 0, millisecond: 0);
.copyWith(hour: 0, minute: 0, second: 0, millisecond: 0, microsecond: 0);
bool get isAtStartOfDay => this == atStartOfDay;
DateTime get atEndOfDay => DateTimeRrule(this)
.copyWith(hour: 23, minute: 59, second: 59, millisecond: 999);
DateTime get atEndOfDay {
return DateTimeRrule(this).copyWith(
hour: 23,
minute: 59,
second: 59,
millisecond: 999,
microsecond: 999,
);
}

bool get isAtEndOfDay => this == atEndOfDay;

static DateTime today() {
Expand Down
10 changes: 10 additions & 0 deletions test/recurrence_rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,14 @@ void main() {
);
},
);
test('#62: Monthly + byWeekDays + getInstances = fails assertion', () {
final rrule = RecurrenceRule(
frequency: Frequency.monthly,
byWeekDays: {ByWeekDayEntry(DateTime.friday, 1)},
);
final start = DateTime.utc(2023, 03, 20, 00, 00, 00, 0, 123);

final instances = rrule.getInstances(start: start);
expect(instances, isNotEmpty);
});
}

0 comments on commit dc8da9e

Please sign in to comment.