diff --git a/CHANGELOG.md b/CHANGELOG.md index 16fc792..6c4f258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 1.6.1 + +- Add `equals` method to check if two dates are equal +- Add `operator -` to subtract a duration from a date +- Add `operator +` to add a duration to a date + + +## 1.6.0 + +- **Fork Release**: Published as `ensemble_date` - a maintained fork of `dart_date` +- Updated package name from `dart_date` to `ensemble_date` +- Updated repository links and documentation +- Improved dependency constraints +- Enhanced pub.dev compatibility + ## 1.1.1 - Merge [PR](https://github.com/xantiagoma/dart_date/pull/16) to fix week calculation diff --git a/LICENSE b/LICENSE index d7c2910..ca2fd74 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) 2020 Santiago Montoya Angarita (@xantiagoma) +Copyright (c) 2024 EnsembleUI (https://github.com/EnsembleUI) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index aef67b2..979e987 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,28 @@ -# dart_date +# ensemble_date -Dart Extensions for `DartTime` +Dart Extensions for `DateTime` -dart_date provides the most comprehensive, yet simple and consistent toolset for manipulating Dart dates. +ensemble_date provides the most comprehensive, yet simple and consistent toolset for manipulating Dart dates. + +**This package is a maintained fork of [dart_date](https://pub.dev/packages/dart_date), providing continued updates and improvements.** Inspired by [date-fns](https://date-fns.org/) +## Installation + +Add this to your package's `pubspec.yaml` file: + +```yaml +dependencies: + ensemble_date: ^1.6.0 +``` + +Then run: + +```bash +dart pub get +``` + ## Usage - Use `instance.method()` for added methods. @@ -27,6 +44,8 @@ Tomorrow: 2020-06-19 08:33:52.700579 ``` ```dart +import 'package:ensemble_date/ensemble_date.dart'; + const pattern = '\'Heute ist\' dd-MMMM-yyyy'; final n = DateTime.now(); final de_String = DateTime.now().format(pattern, 'de_DE'); @@ -74,7 +93,7 @@ Tomorrow: 2020-06-19 08:33:52.700579 ## API -[Check full docs](https://pub.dev/documentation/dart_date/latest/) +[Check full docs](https://pub.dev/documentation/ensemble_date/latest/) Date extension on DateTime diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..ae4ee37 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,25 @@ +include: package:lints/recommended.yaml + +analyzer: + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" + +linter: + rules: + # Disable rules that conflict with existing code patterns + prefer_relative_imports: false + avoid_dynamic_calls: false + comment_references: false + constant_identifier_names: false + unnecessary_brace_in_string_interps: false + + # Keep essential rules + avoid_slow_async_io: true + cancel_subscriptions: true + close_sinks: true + literal_only_boolean_expressions: true + no_adjacent_strings_in_list: true + test_types_in_equals: true + throw_in_finally: true + unnecessary_statements: true \ No newline at end of file diff --git a/example/dart_date_example.dart b/example/dart_date_example.dart index ff843b2..e7af600 100644 --- a/example/dart_date_example.dart +++ b/example/dart_date_example.dart @@ -1,4 +1,4 @@ -import 'package:dart_date/dart_date.dart'; +import 'package:ensemble_date/ensemble_date.dart'; main(List args) { const pattern = '\'Heute ist\' dd-MMMM-yyyy'; diff --git a/lib/dart_date.dart b/lib/dart_date.dart deleted file mode 100644 index 6aa5b8c..0000000 --- a/lib/dart_date.dart +++ /dev/null @@ -1,3 +0,0 @@ -library dart_date; - -export 'src/dart_date.dart'; diff --git a/lib/ensemble_date.dart b/lib/ensemble_date.dart new file mode 100644 index 0000000..9216a15 --- /dev/null +++ b/lib/ensemble_date.dart @@ -0,0 +1,4 @@ +/// Date manipulation library. DateTime extensions. Also includes an Interval object. +library ensemble_date; + +export 'src/dart_date.dart'; diff --git a/lib/src/dart_date.dart b/lib/src/dart_date.dart index 5400bdc..21d950b 100644 --- a/lib/src/dart_date.dart +++ b/lib/src/dart_date.dart @@ -167,6 +167,9 @@ extension Date on DateTime { /// Get [Date] object in LocalTime of current object. DateTime get toLocalTime => toLocal(); + /// Creates a new [DateTime] instance with the same value as this one + /// + /// Returns an exact copy of this [DateTime] preserving the isUtc flag and all time components. DateTime get clone => DateTime.fromMicrosecondsSinceEpoch( microsecondsSinceEpoch, isUtc: isUtc, @@ -559,7 +562,12 @@ extension Date on DateTime { static bool isDate(argument) => argument is DateTime; /// Check if a date is [equals] to other - bool isEqual(other) => equals(other); + bool isEqual(dynamic other) { + if (other is DateTime) { + return equals(other); + } + return false; + } /// Return true if this date day is monday bool get isMonday => weekday == DateTime.monday; @@ -923,27 +931,29 @@ extension Date on DateTime { DateTime subDays(int amount) => addDays(-amount); /// Subtracts an amout of milliseconds from this [DateTime] - DateTime subMilliseconds(amount) => addMilliseconds(-amount); + DateTime subMilliseconds(int amount) => addMilliseconds(-amount); /// Subtracts an amout of microseconds from this [DateTime] - DateTime subMicroseconds(amount) => addMicroseconds(-amount); + DateTime subMicroseconds(int amount) => addMicroseconds(-amount); // DateTime subISOYears(amount) /// Subtracts an amout of minutes from this [DateTime] - DateTime subMinutes(amount) => addMinutes(-amount); + DateTime subMinutes(int amount) => addMinutes(-amount); /// Subtracts an amout of months from this [DateTime] - DateTime subMonths(amount) => addMonths(-amount); + DateTime subMonths(int amount) => addMonths(-amount); // DateTime subQuarters(amount) /// Subtracts an amout of seconds from this [DateTime] - DateTime subSeconds(amount) => addSeconds(-amount); + DateTime subSeconds(int amount) => addSeconds(-amount); // DateTime subWeeks(amount) /// Subtracts an amout of years from this [DateTime] - DateTime subYears(amount) => addYears(-amount); + DateTime subYears(int amount) => addYears(-amount); - // Check if two dates are [equals] + /// Check if two dates are equal to each other + /// + /// Returns true if this [DateTime] represents exactly the same moment in time as [other]. bool equals(DateTime other) => isAtSameMomentAs(other); bool operator <(DateTime other) => isBefore(other); @@ -1090,10 +1100,16 @@ extension Date on DateTime { isUtc: false, ); + /// Subtract a [Duration] from this [DateTime] + /// + /// Returns a new [DateTime] representing the moment that is [other] duration before this [DateTime]. DateTime operator -(Duration other) { return this.subtract(other); } + /// Add a [Duration] to this [DateTime] + /// + /// Returns a new [DateTime] representing the moment that is [other] duration after this [DateTime]. DateTime operator +(Duration other) { return add(other); } diff --git a/pubspec.yaml b/pubspec.yaml index 8e744a6..8446ce7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,17 @@ -name: dart_date -description: Date manipulation library. DateTime extensions. Also includes an Interval object. -version: 1.1.1 -homepage: https://github.com/xantiagoma/dart_date +name: ensemble_date +description: Date manipulation library. DateTime extensions. Also includes an Interval object. Forked from dart_date with additional improvements and maintenance. +version: 1.6.1 +homepage: https://github.com/EnsembleUI/dart_date +repository: https://github.com/EnsembleUI/dart_date +issue_tracker: https://github.com/EnsembleUI/dart_date/issues environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.12.0 <4.0.0' dependencies: - intl: ">=0.18.1 <=0.19.0" + intl: ">=0.18.1 <0.21.0" timeago: ^3.0.2 dev_dependencies: test: ^1.16.0 + lints: ^3.0.0 diff --git a/test/dart_date_test.dart b/test/dart_date_test.dart index f1eb7e4..2dbe68f 100644 --- a/test/dart_date_test.dart +++ b/test/dart_date_test.dart @@ -1,4 +1,4 @@ -import 'package:dart_date/dart_date.dart'; +import 'package:ensemble_date/ensemble_date.dart'; import 'package:test/test.dart'; void main() {