Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy microseconds in DateTime #49

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension DateTimeRrule on DateTime {
int? minute,
int? second,
int? millisecond,
int? microsecond,
bool? isUtc,
}) {
return InternalDateTimeRrule.create(
Expand All @@ -23,7 +24,7 @@ extension DateTimeRrule on DateTime {
minute: minute ?? this.minute,
second: second ?? this.second,
millisecond: millisecond ?? this.millisecond,
// Microseconds are not supported on web: https://github.com/dart-lang/sdk/issues/44876
microsecond: microsecond ?? this.microsecond,
isUtc: isUtc ?? this.isUtc,
);
}
Expand All @@ -38,10 +39,20 @@ extension InternalDateTimeRrule on DateTime {
int minute = 0,
int second = 0,
int millisecond = 0,
int microsecond = 0,
bool isUtc = true,
}) {
final constructor = isUtc ? DateTime.utc : DateTime.new;
return constructor(year, month, day, hour, minute, second, millisecond);
return constructor(
year,
month,
day,
hour,
minute,
second,
millisecond,
microsecond,
);
}

static DateTime date(int year, [int month = 1, int day = 1]) {
Expand Down
9 changes: 9 additions & 0 deletions test/recurrence_rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,19 @@ void main() {
00,
00,
123, // milliseconds
456, // microseconds
);
final instances = rrule.getInstances(start: start);

expect(instances.first, equals(start));
},
);
test('#48: DateTime.copyWith should preserve microseconds', () {
final start = DateTime(2023, 03, 20, 00, 00, 00, 0, 123);

expect(
start.copyWith(isUtc: true).copyWith(isUtc: false),
equals(start),
);
});
}