diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 9c27148..3ed172f 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -13,6 +13,7 @@ extension DateTimeRrule on DateTime { int? minute, int? second, int? millisecond, + int? microsecond, bool? isUtc, }) { return InternalDateTimeRrule.create( @@ -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, ); } @@ -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]) { diff --git a/test/recurrence_rule_test.dart b/test/recurrence_rule_test.dart index 89da00a..d054aff 100644 --- a/test/recurrence_rule_test.dart +++ b/test/recurrence_rule_test.dart @@ -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), + ); + }); }