diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..8699ce8 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: ["https://www.buymeacoffee.com/jama"] \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..5e3d9a5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,38 +1,24 @@ --- name: Bug report about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - --- **Describe the bug** + A clear and concise description of what the bug is. -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error +**How to reproduce the bug** + +A clear and concise description of steps to reproduce the behavior + +**What is the expected behavior** -**Expected behavior** A clear and concise description of what you expected to happen. **Screenshots** -If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] +If applicable, add screenshots to help explain your problem. -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] +**Additional information** -**Additional context** -Add any other context about the problem here. +Add any additional information that you think may be relevant about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7..422624f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,20 +1,20 @@ --- name: Feature request about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - --- **Is your feature request related to a problem? Please describe.** + A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** + A clear and concise description of what you want to happen. **Describe alternatives you've considered** + A clear and concise description of any alternative solutions or features you've considered. **Additional context** + Add any other context or screenshots about the feature request here. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..db6cac3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: "pub" + directory: "/" + schedule: + interval: "weekly" + reviewers: + - "jama5262" + labels: + - "pub" + - "dependencies" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 85228c4..3e263c7 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,11 +1,20 @@ **What does this PR do?** -A clear and concise description of what this PR solves. +A clear and concise description of what this PR solves + +**Issue Reference** + + + +Fixes # **Types of changes** + - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) +- [ ] Maintenance change (non-breaking change such as upgrading a dependency, refactoring, or making a lint fix) +- [ ] Documentation update - [ ] Breaking change (a fix or feature that would cause existing functionality to change) **Screenshots** @@ -15,7 +24,11 @@ If applicable, add screenshots to help explain your problem. **Checklist** -- [ ] Directed the PR to `develop` branch and not the `master` branch + - [ ] Wrote additional tests, if needed - [ ] All tests have passed -- [ ] I have updated the documentation accordingly, if needed. \ No newline at end of file +- [ ] I have updated the documentation accordingly, if needed. + +**Additional Information** + + \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4bff29..1951894 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,35 +1,30 @@ -name: CI +name: Continuous Integration -on: [push] +on: [push, workflow_call] jobs: - test: + run-tests: + name: Run tests runs-on: ${{ matrix.os }} strategy: matrix: os: [ ubuntu-latest, macos-latest, windows-latest ] - steps: - - uses: actions/checkout@v2 - - uses: subosito/flutter-action@v1 - with: - channel: 'stable' - - - name: Install dependencies - run: flutter pub get - - - name: Verify formatting - run: flutter format --set-exit-if-changed lib test - - - name: Analyze project source - run: flutter analyze lib test - - - name: Run tests and generate coverage - run: flutter test --coverage - - - name: Send to Codecov - uses: codecov/codecov-action@v1 + - uses: actions/checkout@v3 + - uses: dart-lang/setup-dart@v1 + - name: Install dart dependencies + run: dart pub get + - name: Analyze package + run: dart analyze lib test example + - name: Verify package formatting + run: dart format --set-exit-if-changed lib test example + - name: Run tests and generate coverage reports + run: | + dart test --reporter=github --coverage=./coverage/reports + dart pub global activate coverage + dart pub global run coverage:format_coverage --report-on=./lib --lcov --in=./coverage/reports --out=coverage/lcov.info + - name: Report to Codecov + uses: codecov/codecov-action@v3 with: file: coverage/lcov.info - - + fail_ci_if_error: true \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7dc6c50..6660470 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,55 +1,18 @@ -name: Release +name: Release to pub.dev on: release: types: - - created + - published jobs: - test: - name: Test Package - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - - steps: - - uses: actions/checkout@v2 - - uses: subosito/flutter-action@v1 - with: - channel: 'stable' - - - name: Install dependencies - run: flutter pub get - - - name: Verify formatting - run: flutter format --set-exit-if-changed lib test - - - name: Analyze project source - run: flutter analyze lib test - - - name: Run tests and generate coverage - run: flutter test --coverage + run-tests: + uses: ./.github/workflows/ci.yml + publish: + needs: run-tests + uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 - - name: Send to Codecov - uses: codecov/codecov-action@v1 - with: - file: coverage/lcov.info - publish: - needs: test - name: Publish to Pub Dev - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Publishing to Pub Dev - uses: k-paxian/dart-package-publisher@master - with: - accessToken: ${{ secrets.PUB_DEV_PUBLISH_ACCESS_TOKEN }} - refreshToken: ${{ secrets.PUB_DEV_PUBLISH_REFRESH_TOKEN }} - skipTests: true diff --git a/.gitignore b/.gitignore index 286f9ad..baed70e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,13 @@ .* # except !.gitignore +!.pubignore !.github -*.iml +# IntelliJ related +*.ipr +*.iws +.idea # Remove the following pattern if you wish to check in your lock file pubspec.lock diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 5c98b42..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index c634881..0000000 --- a/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 639900d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6adbabe..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.pubignore b/.pubignore new file mode 100644 index 0000000..3bf569b --- /dev/null +++ b/.pubignore @@ -0,0 +1,3 @@ +bin +doc +test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ed5e606..b0f9731 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,161 +1,178 @@ -## 5.0.1 +# 5.0.1 ## What's Changed * change version intl to 0.18.0 by @nguyenxdat in https://github.com/jama5262/jiffy/pull/173 +* Release v5.0.1 by @jama5262 in https://github.com/jama5262/jiffy/pull/194 ## New Contributors * @nguyenxdat made their first contribution in https://github.com/jama5262/jiffy/pull/173 **Full Changelog**: https://github.com/jama5262/jiffy/compare/v5.0.0...v5.0.1 -## 5.0.0 +# 5.0.0 -### Major Changes +## What's Changed +* added Ukrainian locale by @yarmat in https://github.com/jama5262/jiffy/pull/113 +* Add dutch language support by @diegonuja in https://github.com/jama5262/jiffy/pull/114 +* Support Bangla Language by @yeahia2508 in https://github.com/jama5262/jiffy/pull/102 +* added Thailand locale by @srithong in https://github.com/jama5262/jiffy/pull/116 +* Bugfix/readme by @calvintam236 in https://github.com/jama5262/jiffy/pull/120 +* Fix jama5262#115 by @calvintam236 in https://github.com/jama5262/jiffy/pull/119 +* Bugfix/115 for nb by @calvintam236 in https://github.com/jama5262/jiffy/pull/122 +* [Issue 130] Update the unix parse function to be specific to either seconds of milliseconds by @jama5262 in https://github.com/jama5262/jiffy/pull/135 +* Release v5.0.0 to master by @jama5262 in https://github.com/jama5262/jiffy/pull/136 -1. Updated `Jiffy.unix()` to be more specific to seconds and milliseconds timestamps +## New Contributors +* @yarmat made their first contribution in https://github.com/jama5262/jiffy/pull/113 +* @diegonuja made their first contribution in https://github.com/jama5262/jiffy/pull/114 +* @yeahia2508 made their first contribution in https://github.com/jama5262/jiffy/pull/102 +* @srithong made their first contribution in https://github.com/jama5262/jiffy/pull/116 +* @calvintam236 made their first contribution in https://github.com/jama5262/jiffy/pull/120 -Previously -```dart -// Parsing a timestamp in milliseconds -Jiffy.unix(1318781876406); +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v4.1.0...v5.0.0 -// Parsing a timestamp in seconds -Jiffy.unix(1318781876).format(); // 2011-10-16T19:17:56.000 -``` -Now -```dart -// Parsing a timestamp in milliseconds -Jiffy.unixFromMillisecondsSinceEpoch(1318781876406); +# 4.1.0 -// Parsing a timestamp in seconds -Jiffy.unixFromSecondsSinceEpoch(1318781876).format(); // 2011-10-16T19:17:56.000 -``` +## What's Changed +* Add Az locale by @justkost in https://github.com/jama5262/jiffy/pull/105 +* Does not rely on method cascading for immutability by @jama5262 in https://github.com/jama5262/jiffy/pull/107 +* Add GitHub actions by @jama5262 in https://github.com/jama5262/jiffy/pull/109 +* Release v4.1.0 to master by @jama5262 in https://github.com/jama5262/jiffy/pull/110 -2. Added Ukranian `uk` locale contributed by [yarmat](https://github.com/yarmat) -3. Added Dutch `nl` locale contributed by [diegonuja](https://github.com/diegonuja) -4. Added Thailand `th` locale contributed by [srithong](https://github.com/srithong) -5. Minor bug fixes from [calvintam236](https://github.com/calvintam236) +## New Contributors +* @justkost made their first contribution in https://github.com/jama5262/jiffy/pull/105 -## 4.1.0 +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v4.0.0...v4.1.0 -### Minor Changes -1. All methods return `Jiffy`, except `utc()` and `local()` functions -2. Added github actions -3. Added Azerbaijani `az` locale contributed by [Konstantin](https://github.com/justkost) +# 4.0.0 +## What's Changed +* added Norwegian Bokmål (nb) language by @zeusbaba in https://github.com/jama5262/jiffy/pull/63 +* add mapping for 'de_DE' locale by @SebRut in https://github.com/jama5262/jiffy/pull/71 +* Added Persian locale by @mozaffari in https://github.com/jama5262/jiffy/pull/88 +* Fix diff function by @jama5262 in https://github.com/jama5262/jiffy/pull/91 +* All methods return jiffy and add Jiffy cloning by @jama5262 in https://github.com/jama5262/jiffy/pull/92 +* Implement null safety by @jama5262 in https://github.com/jama5262/jiffy/pull/93 +* Update locale functionality by @jama5262 in https://github.com/jama5262/jiffy/pull/99 +* Release version 4.0.0 to master by @jama5262 in https://github.com/jama5262/jiffy/pull/100 -## 4.0.0 +## New Contributors +* @zeusbaba made their first contribution in https://github.com/jama5262/jiffy/pull/63 +* @SebRut made their first contribution in https://github.com/jama5262/jiffy/pull/71 +* @mozaffari made their first contribution in https://github.com/jama5262/jiffy/pull/88 -### Major Changes +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v3.0.1...v4.0.0 -1. Implemented null safety -2. Jiffy cloning - ```dart - var jiffy1 = Jiffy(); - var jiffy2 = jiffy1.clone(); - // or - var jiffy1 = Jiffy(); - var jiffy2 = Jiffy(jiffy1); - ``` -3. Bug fix `diff()` function -4. Added Persian `fa` locale contributed by [mozaffari](https://github.com/mozaffari) -5. Added Norwegian `nb` locale contributed by [Yilmaz Guleryuz](https://github.com/zeusbaba) -6. Added `de_DE` mapping locale contributed by [Sebastian Rutofski](https://github.com/SebRut) -7. Fixed minor locale bugs +# 3.0.1 -## 3.0.1 +## What's Changed +* Added Swedish locale by @ercadev in https://github.com/jama5262/jiffy/pull/53 +* Fix enum by @jama5262 in https://github.com/jama5262/jiffy/pull/55 +* Releasing v3.0.1 by @jama5262 in https://github.com/jama5262/jiffy/pull/56 -### Patch changes +## New Contributors +* @ercadev made their first contribution in https://github.com/jama5262/jiffy/pull/53 -1. Fixed `Undefined name 'Units'` bug -2. Swedish locale `sv` contributed by [Erik Carlsson](https://github.com/ercadev) +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v3.0.0...v3.0.1 -## 3.0.0 +# 3.0.0 -### Major changes +## What's Changed +* Add Bahasa Indonesia (Indonesian) locale language by @ampersanda in https://github.com/jama5262/jiffy/pull/43 +* Add tr locale by @iozozturk in https://github.com/jama5262/jiffy/pull/44 +* Updated test names and descriptions by @jama5262 in https://github.com/jama5262/jiffy/pull/46 +* Setup unit enums by @jama5262 in https://github.com/jama5262/jiffy/pull/48 +* Update escape by @jama5262 in https://github.com/jama5262/jiffy/pull/49 +* Releasing v3.0.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/50 +* Releasing v3.0.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/52 -1. Unit of time are now in enums. Examples, previously `startOf("day")` can now be set as `startOf(Units.DAY)` -String escape changes to use square braces `[]`. Examples, previously -2. `Jiffy().format("yyyy 'escaped' yyyy");` and now updated to `Jiffy().format("yyyy [escaped] yyyy");` -3. Added Indonsia local `id` by [ampersanda](https://github.com/ampersanda) and Turkish local `tr` by [iozozturk](https://github.com/iozozturk) +## New Contributors +* @ampersanda made their first contribution in https://github.com/jama5262/jiffy/pull/43 +* @iozozturk made their first contribution in https://github.com/jama5262/jiffy/pull/44 +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v2.2.0...v3.0.0 -## 2.2.0 -### Minor Changes +# 2.2.0 -1. Added more string parsing functionality. See below +## What's Changed +* Added Polish locale by @leszekkrol in https://github.com/jama5262/jiffy/pull/38 +* Fix polish locale by @jama5262 in https://github.com/jama5262/jiffy/pull/39 +* Update string parsing by @jama5262 in https://github.com/jama5262/jiffy/pull/40 +* Releasing v2.2.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/41 -``` -Jiffy("1995/12/25"); // A calendar date part separated by slash "/" -Jiffy("19951225"); // Basic (short) full date -Jiffy("1995-12-25 12:00:00.000"); // An hour, minute, second, and millisecond time part -Jiffy("1995-12-25T12:00:00.000"); ISO dart format -Jiffy("1995-12-25T12:00:00.000Z"); ISO dart format (UTC) -``` -2. Added support to Polish locale `pl` added by [leszekkrol](https://github.com/leszekkrol) +## New Contributors +* @leszekkrol made their first contribution in https://github.com/jama5262/jiffy/pull/38 -## 2.1.2 +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v2.1.2...v2.2.0 -### Patch Changes +# 2.1.2 -1. Bug fix to support `startOf` and `endOf` for locales -2. Bug fix on week getter by [MrCasCode](https://github.com/MrCasCode) +## What's Changed +* Add support to locales to day getter by @MrCasCode in https://github.com/jama5262/jiffy/pull/32 +* Fix week by @jama5262 in https://github.com/jama5262/jiffy/pull/33 +* Releasing v2.1.2 by @jama5262 in https://github.com/jama5262/jiffy/pull/34 -## 2.1.1 +## New Contributors +* @MrCasCode made their first contribution in https://github.com/jama5262/jiffy/pull/32 -### Patch Changes +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v2.1.1...v2.1.2 -Previously +# 2.1.1 -`Jiffy([2014, 4, 23]).format("EEEE MMMM do, yyyy"); // Wednesday April 23o, 2014` +## What's Changed +* Releasing v2.1.1 by @jama5262 in https://github.com/jama5262/jiffy/pull/30 -Updated -`Jiffy([2014, 4, 23]).format("EEEE MMMM do, yyyy"); // Wednesday April 23rd, 2014` +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v2.1.0...v2.1.1 -## 2.1.0 +# 2.1.0 -### Minor Changes +## What's Changed +* Add days in month by @jama5262 in https://github.com/jama5262/jiffy/pull/27 +* Ordianl days by @jama5262 in https://github.com/jama5262/jiffy/pull/28 +* Releasing v2.1.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/29 -1. Ordinal date parsing and formating -In Jiffy you can now parse and format with ordinal date. e.g -```dart -Jiffy().format("MMM do yyyy"); // Oct 19th 2019 -``` -2. It also supports locales for the following -`"en", "es", "fr", "frch", "frca", "it", "itch", "ja", "ko", "pt", "ptbr", "zh", "zhcn", "zhhk", "zhtw", "de", "deat", "dech"` +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v2.0.0...v2.1.0 -3. Added `daysInMonth` method to get number of days for specific months .e.g -```dart -Jiffy([2016, 1]).daysInMonth; // 31 -Jiffy([2016, 2]).daysInMonth; // 28 -Jiffy([2017, 2]).daysInMonth; // 29 -``` +# 2.0.0 -## 2.0.0 +## What's Changed +* Support Duration by @yongjhih in https://github.com/jama5262/jiffy/pull/18 +* Updated docs by @jama5262 in https://github.com/jama5262/jiffy/pull/20 +* Update changelog by @jama5262 in https://github.com/jama5262/jiffy/pull/21 +* Releasing version v2.0.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/23 -### Major Changes +## New Contributors +* @yongjhih made their first contribution in https://github.com/jama5262/jiffy/pull/18 -1. Added params to add and subtract methods by [yongjhih](https://github.com/yongjhih) -Example -```dart -Jiffy().add(days: 1); -Jiffy().add(years: 2, months: 1, duration: Duration(days: 1, hours: 30)); -``` +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v1.1.0...v2.0.0 -## 1.1.0 +# 1.1.0 -### Minor Changes +## What's Changed +* Add more parsing by @jama5262 in https://github.com/jama5262/jiffy/pull/14 +* Releasing v1.1.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/15 +* Releasing Updated v1.1.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/16 -1. Add more functionality to parsing. These are -- Array parsing `Jiffy([2019, 10, 21]);` -- Map parsing `Jiffy({"year": 2019, "month": 10});` -- Dart DateTime parsing `Jiffy(DateTime.now());` -- String parsing `Jiffy("2019-10-21");` -## 1.0.0 +**Full Changelog**: https://github.com/jama5262/jiffy/compare/v1.0.0...v1.1.0 +# 1.0.0 -1. Launch 🚀 +## What's Changed +* Set up Travis and coveralls by @jama5262 in https://github.com/jama5262/jiffy/pull/1 +* Setup all methods by @jama5262 in https://github.com/jama5262/jiffy/pull/2 +* Setup jiffy date time by @jama5262 in https://github.com/jama5262/jiffy/pull/4 +* Setup unix parsing by @jama5262 in https://github.com/jama5262/jiffy/pull/5 +* Setup manipulation of datetime by @jama5262 in https://github.com/jama5262/jiffy/pull/6 +* Setup display by @jama5262 in https://github.com/jama5262/jiffy/pull/7 +* Setup query by @jama5262 in https://github.com/jama5262/jiffy/pull/8 +* Added example file by @jama5262 in https://github.com/jama5262/jiffy/pull/9 +* Setup docs by @jama5262 in https://github.com/jama5262/jiffy/pull/10 +* Releasing v1.0.0 by @jama5262 in https://github.com/jama5262/jiffy/pull/11 +* Releasing v1.0.0 to master by @jama5262 in https://github.com/jama5262/jiffy/pull/12 + + +**Full Changelog**: https://github.com/jama5262/jiffy/commits/v1.0.0 \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..98ebfc2 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,27 @@ +# Jiffy Code of Conduct + +Jiffy is a welcoming and inclusive community. We value the contributions of all individuals and believe that diverse perspectives and experiences are essential to creating a successful project. + +To ensure that our community is a safe and respectful place for everyone, we ask that all participants adhere to the following Code of Conduct below. + +### Be Respectful +We are committed to maintaining a respectful and professional environment. Please be considerate and respectful in your interactions with others, regardless of their background or experience. + +### Be Inclusive +We welcome and encourage participation from individuals of all backgrounds, identities, and perspectives. We strive to create an inclusive environment where everyone feels valued and heard. + +### Be Collaborative +We believe that collaboration is essential to building a successful project. We encourage constructive feedback and open communication, and we welcome suggestions and contributions from all members of the community. + +### Be Accountable +We hold ourselves accountable for our actions and words. We ask that all members of the community do the same, and take responsibility for any harm caused by their words or actions. + +### Reporting Violations +If you witness or experience behavior that violates this Code of Conduct, please report it to the project maintainers immediately at [jama3137@gmail.com](mailto:jama3137@gmail.com). All reports will be taken seriously and investigated promptly. + +### Consequences of Unacceptable Behavior +We will not tolerate behavior that violates this Code of Conduct. We reserve the right to take appropriate action, including but not limited to warning, suspension, or expulsion from the community. + +--- + +Please feel free to modify this Code of Conduct to suit your specific needs and community. It's important to communicate clearly and proactively about your expectations for behavior within your community. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..44df1e7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,29 @@ +# Contributing to Jiffy + +We welcome contributions to Jiffy! Whether you're a developer, designer, or just someone with an idea or suggestion, we'd love to hear from you. + +## Code of Conduct + +Before contributing, please take a chance to read our Code of Conduct to ensure that all contributors feel welcome and respected. Review our [Code of Conduct](./CODE_OF_CONDUCT.md). + +## What to Contribute + +There are many ways to contribute to Jiffy. Here are some ideas: + +- Report bugs or issues +- Suggest new features or improvements +- Submit code changes or bug fixes +- Write or update documentation or tutorials +- Help answer questions + +## How to contribute + +To contribute, follow the following easy steps, and we'll review your changes and get back to you as soon as possible. + +- Fork this repo +- Make your own updates +- Create a new pull request to the `master` branch + +--- + +Thank you for your interest in contributing to Jiffy. We appreciate your time and effort, and we look forward to working with you! diff --git a/README.md b/README.md index 3ebcc7a..8fa948f 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,113 @@ # Jiffy -[![.github/workflows/release.yml](https://github.com/jama5262/jiffy/actions/workflows/release.yml/badge.svg)](https://github.com/jama5262/jiffy/actions/workflows/release.yml) +[![Release to pub.dev](https://github.com/jama5262/jiffy/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/jama5262/jiffy/actions/workflows/release.yml) [![codecov](https://codecov.io/gh/jama5262/jiffy/branch/master/graph/badge.svg?token=Z2EGVUGWTE)](https://codecov.io/gh/jama5262/jiffy) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -[![Pub Version](https://img.shields.io/badge/pub-v5.0.1-blue)](https://pub.dev/packages/jiffy) +[![Pub Version](https://img.shields.io/badge/pub.dev-v5.0.1-blue)](https://pub.dev/packages/jiffy/versions/5.0.1) ![Platform](https://img.shields.io/badge/platform-flutter%7Cweb%7Cdart%20vm-orange) Jiffy is a Flutter (Android, IOS and Web) date time package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates -### [Full Documentation](doc) | [Installation](https://pub.dev/packages/jiffy#-installing-tab-) | [ChangeLog](https://pub.dev/packages/jiffy#-changelog-tab-) | [Examples](https://pub.dev/packages/jiffy#-example-tab-) - -#### [Follow the project board](https://github.com/jama5262/jiffy/projects/1) +### [Full Documentation](./doc) | [API Reference](https://pub.dev/documentation/jiffy/latest/jiffy/Jiffy-class.html) | [Installation](https://pub.dev/packages/jiffy#-installing-tab-) | [ChangeLog](https://pub.dev/packages/jiffy#-changelog-tab-) | [Examples](https://pub.dev/packages/jiffy#-example-tab-) # Usage ## Format Dates ```dart -Jiffy([2021, 1, 19]).format("MMMM do yyyy, h:mm:ss a"); // January 1st 2021, 12:00:00 AM -Jiffy().format("EEEE"); // Tuesday -Jiffy().format("MMM do yy"); // Mar 2nd 21 -Jiffy().format("yyyy [escaped] yyyy"); // 2021 escaped 2021 -Jiffy().format(); // 2021-03-02T15:18:29.922343 - -Jiffy([2020, 10, 19]).yMMMMd; // January 19, 2021 - -Jiffy({ - "year": 2020, - "month": 10, - "day": 19, - "hour": 19 +Jiffy.parse('2021/01/19').format('MMMM do yyyy, h:mm:ss a'); // January 1st 2021, 12:00:00 AM +Jiffy.now().format('EEEE'); // Tuesday +Jiffy.now().format('MMM do yy'); // Mar 2nd 21 +Jiffy.now().format('yyyy [escaped] yyyy'); // 2021 escaped 2021 +Jiffy.now().format(); // 2021-03-02T15:18:29.922343 + +Jiffy.parseFromList([2020, 10, 19]).yMMMMd; // January 19, 2021 + +Jiffy.parseFromMap({ + Unit.year: 2020, + Unit.month: 10, + Unit.day: 19, + Unit.hour: 19 }).yMMMMEEEEdjm; // Monday, October 19, 2020 7:14 PM -// You can also use default formats -Jiffy("19, Jan 2021", "dd, MMM yyyy").yMMMMd; // January 19, 2021 - -Jiffy().yMMMMEEEEdjm; // Tuesday, March 2, 2021 3:20 PM +// You can also use pre-set formats +Jiffy.parse('19, Jan 2021', pattern: 'dd, MMM yyyy').yMMMMd; // January 19, 2021 +Jiffy.now().yMMMMEEEEdjm; // Tuesday, March 2, 2021 3:20 PM ``` ## Relative Time ```dart -Jiffy("2011-10-31", "yyyy-MM-dd").fromNow(); // 9 years ago - -Jiffy().startOf(Units.DAY).fromNow(); // 19 hours ago - -Jiffy().endOf(Units.DAY).fromNow(); // in 5 hours - -Jiffy().startOf(Units.HOUR).add(hours: 2, minutes: 20).fromNow(); // in 2 hours +// From X +Jiffy.parse('1997/09/23').from(Jiffy.parse('2002/10/26')); // 5 years ago +// From Now +Jiffy.parse('1997/09/23').fromNow(); // 25 years ago + +// To X +Jiffy.parse('1997/09/23').to(Jiffy.parse('2002/10/26')); // in 5 years +// To Now +Jiffy.parse('1997/09/23').toNow(); // in 25 years ``` ## Manipulation ```dart -var jiffy1 = Jiffy().add(duration: Duration(days: 1)); -jiffy1.yMMMMd; // March 3, 2021 +var jiffy = Jiffy.now().add(duration: Duration(days: 1)); +jiffy.yMMMMd; // March 3, 2021 -Jiffy().subtract(days: 1).yMMMMd; // March 1, 2021 +Jiffy.now().subtract(days: 1).yMMMMd; // March 1, 2021 -Jiffy() +Jiffy.now() .add(hours: 3, days: 1) .subtract(minutes: 30, months: 1); .yMMMMEEEEdjm; // Wednesday, February 3, 2021 6:07 PM -// Months and year are added in respect to how many -// days there are in a months and if is a year is a leap year -Jiffy("2010/1/31", "yyyy-MM-dd"); // This is January 31 -Jiffy([2010, 1, 31]).add(months: 1); // This is February 28 +Jiffy.parse('1997/09/23') + .startOf(Unit.year) + .yMMMMEEEEd; // Wednesday, January 1, 1997 + +Jiffy.parse('1997/09/23') + .endOf(Unit.month) + .yMMMMEEEEd; // Tuesday, September 30, 1997 ``` -## Locale Support +## Querying + ```dart -// The locale method always return a future -// To get locale (The default locale is English) -await (Jiffy.locale()).code; // en +Jiffy.parse('1997/9/23').isBefore(Jiffy.parse('1997/9/24')); // true -// To set locale -await Jiffy.locale("fr"); -Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25 +Jiffy.parse('1997/9/23').isAfter(Jiffy.parse('1997/9/20')); // true -await Jiffy.locale("ar"); -Jiffy().yMMMMEEEEdjm; // السبت، ١٩ أكتوبر ٢٠١٩ ٧:٢٧ م +Jiffy.parse('1997/9/23').isSame(Jiffy.parse('1997/9/23')); // true -await Jiffy.locale("zh_cn"); -Jiffy().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28 +Jiffy.parse('1997/9/23') + .isBetween(Jiffy.parse('1997/9/20'), Jiffy.parse('1997/9/24')); // true ``` -## Contributing - -To contribute, follow the following easy steps - -##### Step 1 +## Locale Support +```dart +// Get current locale code, by default it is en_us +Jiffy.now().localeCode; // en_us -- Fork this repo! +// Setting your preferred locale +await Jiffy.setLocale('fr_ca'); +Jiffy.now().yMMMMEEEEdjm; // dimanche 26 février 2023 12 h 03 -##### Step 2 +await Jiffy.setLocale('ja'); +Jiffy.now().yMMMMEEEEdjm; // 2023年2月26日日曜日 12:02 -- Make your own updates +await Jiffy.setLocale('zh_cn'); +Jiffy.now().yMMMMEEEEdjm; // 2023年2月26日星期日 下午12:03 +``` -##### Step 3 +## Contributing -- Create a new pull request +For contribution guidelines, see [CONTRIBUTING](./CONTRIBUTING.md). ## Support Reach out to me at one of the following places! -- Email at jama3137@gmail.com +- Email me at [jama3137@gmail.com](mailto:jama3137@gmail.com) +- LinkedIn [Jama Mohamed](https://www.linkedin.com/in/jama-mohamed/) - Twitter [timedjama5262](https://twitter.com/timedjama5262) ## License diff --git a/analysis_options.yaml b/analysis_options.yaml index a686c1b..3322f66 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,7 +1,4 @@ -# Defines a default set of lint rules enforced for -# projects at Google. For details and rationale, -# see https://github.com/dart-lang/pedantic#enabled-lints. -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml # For lint rules and documentation, see http://dart-lang.github.io/linter/lints. # Uncomment to specify additional rules. diff --git a/bin/dart_analyze.bat b/bin/dart_analyze.bat new file mode 100644 index 0000000..3ca43e4 --- /dev/null +++ b/bin/dart_analyze.bat @@ -0,0 +1 @@ +dart analyze lib test example \ No newline at end of file diff --git a/bin/dart_analyze.sh b/bin/dart_analyze.sh new file mode 100644 index 0000000..60af726 --- /dev/null +++ b/bin/dart_analyze.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +dart analyze lib test example \ No newline at end of file diff --git a/bin/dart_format.bat b/bin/dart_format.bat new file mode 100644 index 0000000..bfb6412 --- /dev/null +++ b/bin/dart_format.bat @@ -0,0 +1 @@ +dart format lib test example \ No newline at end of file diff --git a/bin/dart_format.sh b/bin/dart_format.sh new file mode 100644 index 0000000..26c485c --- /dev/null +++ b/bin/dart_format.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +dart format lib test example \ No newline at end of file diff --git a/bin/dart_test.bat b/bin/dart_test.bat new file mode 100644 index 0000000..e55eba6 --- /dev/null +++ b/bin/dart_test.bat @@ -0,0 +1 @@ +dart test \ No newline at end of file diff --git a/bin/dart_test.sh b/bin/dart_test.sh new file mode 100644 index 0000000..57c1a60 --- /dev/null +++ b/bin/dart_test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +dart test \ No newline at end of file diff --git a/doc/README.md b/doc/README.md index 0efab43..1316404 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,144 +1,158 @@ # Jiffy -[![.github/workflows/release.yml](https://github.com/jama5262/jiffy/actions/workflows/release.yml/badge.svg)](https://github.com/jama5262/jiffy/actions/workflows/release.yml) -[![codecov](https://codecov.io/gh/jama5262/jiffy/branch/master/graph/badge.svg?token=Z2EGVUGWTE)](https://codecov.io/gh/jama5262/jiffy) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -[![Pub Version](https://img.shields.io/badge/pub-v5.0.1-blue)](https://pub.dev/packages/jiffy) -[![Platform](https://img.shields.io/badge/platform-flutter%7Cweb%7Cdart%20vm-orange)](https://github.com/jama5262/jiffy) - - -Jiffy is a Flutter (Android, IOS and Web) date time package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates - -# Table of content -- [Parsing](#parsing) - - [Now](#now) - - [String](#string) - - [String Formating](#string-formatting) - - [Maps](#maps) - - [Unix Timestamp](#unix-timestamp) - - [Jiffy Cloning](#jiffy-cloning) - - [DateTime](#datetime) - - [List](#list) - - [UTC](#utc) -- [Get](#get) - - [Millisecond](#millisecond) - - [Second](#second) - - [Minute](#minute) - - [Hour](#hour) - - [Date of Month](#date-of-month) - - [Days in Month](#days-in-month) - - [Day of Week](#day-of-week) - - [Day of Year](#day-of-year) - - [Week of Year](#week-of-year) - - [Month](#month) - - [Quarter](#quarter) - - [Year](#year) -- [Manipulation](#manipulation) - - [Add](#add) - - [Subtract](#subtract) - - [Start of Time](#start-of-time) - - [End of Time](#end-of-time) - - [Local](#local) - - [UTC](#utc) -- [Display](#display) - - [Format](#format) - - [Time from Now](#time-from-now) - - [Time from X](#time-from-x) - - [Difference](#difference) - - [Unix Timestamp (Milliseconds)](#unix-timestamp-milliseconds) - - [Unix Timestamp (Seconds)](#unix-timestamp-seconds) -- [Query](#query) - - [Is Before](#is-before) - - [Is Same](#is-same) - - [Is After](#is-after) - - [Is Same or Before](#is-same-or-before) - - [Is Same or After](#is-same-or-after) - - [Is Between](#is-between) - - [Is Leap Year](#is-leapyear) - - [Is Jiffy](#is-jiffy) - - [Is DateTime](#is-datetime) -- [Locale Support](#locale-support) +Jiffy is a Flutter (Android, IOS and Web) date time +package inspired by [momentjs](https://momentjs.com/) for parsing, +manipulating, querying and formatting dates # Parsing ### Now -To get the date now, just call `Jiffy()` without passing any parameters. This will return a Jiffy instance. See below +To get the current date time, just call `Jiffy.now()`. +This will return a Jiffy instance with the current date time. ```dart -Jiff(); // Returns a Jiffy instance -Jiffy().dateTime; // Returns a dart DateTime.now() -Jiffy().format(); // Return a ISO 8601 date time format +Jiffy.now(); // Returns a Jiffy instance +Jiffy.now().dateTime; // Returns a dart DateTime.now() +Jiffy.now().format(); // Return a ISO 8601 date time format ``` ### String -Creating a Jiffy from a string. See below +Creating a Jiffy date time by parsing a string. ```dart -Jiffy("2021-5-25"); // A calendar date part -Jiffy("2021/5/25"); // A calendar date part separated by slash "/" -Jiffy("2021525"); // Basic (short) full date -Jiffy("2021-5-25 12:00:00.000"); // An hour, minute, second, and millisecond time part -Jiffy("2021-5-25T12:00:00.000"); // ISO date format -Jiffy("2021-5-25T12:00:00.000Z"); // ISO date format (UTC) +Jiffy.parse('2021-05-25'); // A calendar date part +Jiffy.parse('2021/05/25'); // A calendar date part separated by slash "/" +Jiffy.parse('2021-05-25 12:00:00.000'); // An hour, minute, second, and millisecond time part +Jiffy.parse('2021-05-25T12:00:00.000'); // ISO date format +Jiffy.parse('2021-05-25T12:00:00.000Z'); // ISO date format (UTC) ``` ### String Formatting -To get a Jiffy date from a string, pass the string and its pattern to Jiffy as is parameters. See below +Create a Jiffy date time from a string date time pattern. +Use this if you know the format of an input string ```dart -Jiffy("2021-5-25", "yyyy-MM-dd"); -Jiffy("25-5-2021", "dd-MM-yyyy"); -Jiffy("5-2021", "MM-yyyy"); +Jiffy.parse('2021, May 25', pattern: 'yyyy, MMMM dd'); +Jiffy.parse('25-05-2021', pattern: 'dd-MM-yyyy'); +Jiffy.parse('5-2021', pattern: 'MM-yyyy'); ``` You can also parse ordinal date formats. The date pattern for the ordinal date is `do` ```dart -Jiffy("Jan 19th", "MMM do"); -Jiffy("19th January 2021", "do MMMM yyyy"); +Jiffy.parse('Jan 19th', pattern: 'MMM do'); +Jiffy.parse('19th January 2021', pattern: 'do MMMM yyyy'); ``` -**_Note: Jiffy runs on top of the [Intl DateFormat](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) package, so you can find all the date time patterns used by Jiffy [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html)_** +**_Note: Jiffy runs on top of the [Intl DateFormat](https://pub.dev/packages/intl) +package, so you can find all the date time patterns also +used by Jiffy [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html)_** -This is also same for Jiffy default formats. See below +This is also same for Jiffy pre-set formats. ```dart -Jiffy().MMMEd; // Tue, May 25 -Jiffy("2021-5-25", "yyyy-MM-dd").yMMMMd; // May 25, 2021 +Jiffy.now().MMMEd; // Tue, May 25 +Jiffy.parse('2021-05-25', pattern: 'yyyy-MM-dd').yMMMMd; // May 25, 2021 +``` + +If you want to parse them as `utc` do the following. This will return Jiffy instance in +UTC date time +```dart +Jiffy.parse('2021-05-25', isUtc: true) +Jiffy.parse('2021-05-25', pattern: 'yyyy-MM-dd', isUtc: true) +``` + +### DateTime +Jiffy date time can be created from a dart `DateTime` instance. +```dart +var dateTime = DateTime.now(); +Jiffy.parseFromDateTime(dateTime); + +Jiffy.parseFromDateTime(DateTime(2021, 5, 25)).yMMMM; // May 2021 +``` + +### Jiffy +Jiffy date time can be created from another `Jiffy` instance. +```dart +var jiffy = Jiffy.now(); +Jiffy.parseFromJiffy(jiffy); +``` + +### List +You can also create Jiffy from a List. But they should mirror the following order + +`[ year, month, day, hour, minute, second, millisecond, microsecond ]` +```dart +Jiffy.parseFromList([2021]); // January 1st 2021 +Jiffy.parseFromList([2021, 10]); // October 1st 2021 +Jiffy.parseFromList([2021, 10, 19]); // October 19th 2021 +``` + +If you want to parse them as `utc` do the following. This will return Jiffy instance in +UTC date time +```dart +Jiffy.parseFromList([2021, 10], isUtc: true); ``` ### Maps You can also create a Jiffy from a Map, Supported key pairs are, -`[ year, month, day, hour, minute, second and millisecond ]`. See below +`[ Unit.year, Unit.month, Unit.day, Unit.hour, +Unit.minute, Unit.second, Unit.millisecond and Unit.microsecond ]`. + +If any of the units are not provided, the current date time will be used + ```dart -Jiffy({ - "hour": 19, - "minutes": 20 -}); +Jiffy.parseFromMap( + { + Unit.hour: 19, + Unit.minute: 20 + } +); + +Jiffy.parseFromMap( + { + Unit.year: 2019, + Unit.month: 10, + Unit.day: 19, + Unit.hour: 19 + } +); +``` -Jiffy({ - "year": 2019, - "month": 10, - "day": 19, - "hour": 19 -}); +If you want to parse them as `utc` do the following. This will return Jiffy instance in +UTC date time +```dart +Jiffy.parseFromMap( + { + Unit.year: 2019, + Unit.month: 10, + Unit.day: 19, + Unit.hour: 19 + }, + isUtc: true +); ``` -### Unix Timestamp -Jiffy can also parse timestamp milliseconds and seconds. Just call `Jiffy.unix()` which return a dart Datetime. See below +### Timestamps since epoch +Jiffy can also parse timestamp milliseconds and microseconds since epoch. ```dart -// Parsing a timestamp in milliseconds -Jiffy.unixFromMillisecondsSinceEpoch(1318781876406); +// Parsing a timestamp in microseconds since epoch +Jiffy.parseFromMicrosecondsSinceEpoch(874962000000000); // 1997-09-23 00:00:00.000 -// Parsing a timestamp in seconds -Jiffy.unixFromSecondsSinceEpoch(1318781876).format(); // 2011-10-16T19:17:56.000 +// Parsing a timestamp in milliseconds since epoch +Jiffy.parseFromMillisecondsSinceEpoch(874962000000); // 1997-09-23 00:00:00.000 ``` -**_Note: `Jiffy.unixFromMillisecondsSinceEpoch() or Jiffy.unixFromSecondsSinceEpoch` returns a timestamp base on local time. You can also get it in UTC which returns a UTC in dart Datetime. See below_** +If you want to parse them as `utc` do the following. This will return Jiffy instance in +UTC date time ```dart -Jiffy.unixFromMillisecondsSinceEpoch(1318781876406).utc(); +// Parsing a timestamp in microseconds since epoch +Jiffy.parseFromMicrosecondsSinceEpoch(874962000000000, isUtc: true); // 1997-09-22 21:00:00.000Z + +// Parsing a timestamp in milliseconds since epoch +Jiffy.parseFromMillisecondsSinceEpoch(874962000000, isUtc: true); // 1997-09-22 21:00:00.000Z ``` ### Jiffy Cloning Jiffy date time can be created from another Jiffy instance, a way of cloning. ```dart -var jiffy1 = Jiffy([2021]); -var jiffy2 = Jiffy(jiffy1); +var jiffy1 = Jiffy.parseFromList([2021]); +var jiffy2 = Jiffy.parseFromJiffy(jiffy1); jiffy1.add(years: 10); jiffy1.year; // 2031 jiffy2.year; // 2021 @@ -146,436 +160,476 @@ jiffy2.year; // 2021 Or you can use the clone method itself ```dart -var jiffy1 = Jiffy([2021]); +var jiffy1 = Jiffy.parseFromList([2021]); var jiffy2 = jiffy1.clone(); jiffy1.add(years: 10); jiffy1.year; // 2031 jiffy2.year; // 2021 ``` -### DateTime -Jiffy date time can be created from a dart DateTime instance. See below -```dart -var dateTime = DateTime.now(); -Jiffy(dateTime); - -Jiffy(DateTime(2021, 5, 25)).yMMMM; // May 2021 -``` - -### List -You can also create Jiffy from a List. But they should mirror the following order - -`[ year, month, day, hour, minute, second, millisecond ]` -```dart -Jiffy([2021]); // January 1st 2021 -Jiffy([2021, 10]); // October 1st 2021 -Jiffy([2021, 10, 19]); // October 19th 2021 -``` - ### UTC -Get date time in UTC. See below +Get date time in UTC. ```dart // In local time -Jiffy().format(); // 2021-03-02T14:35:24.363919 +var jiffy1 = Jiffy.now(); +jiffy1.format(); // 2021-03-02T14:35:24.363919 // Change to UTC -var jiffy = (Jiffy()..utc()); -jiffy.format(); // 2021-03-02T11:35:24.363919 +var jiffy2 = jiffy1.toUtc(); +jiffy2.format(); // 2021-03-02T11:35:24.363919Z ``` # Get +### DateTime +Returns a new `DateTime` instance of the `Jiffy` object. +```dart +Jiffy.now().dateTime; +``` +### Microsecond +Returns the microsecond ranging from 0 to 999. +```dart +Jiffy.now().microsecond; +``` +### Microsecond since epoch +Returns the number of microseconds since epoch time `January 1, 1970, 00:00:00 UTC`. +```dart +Jiffy.now().microsecondsSinceEpoch; +``` ### Millisecond -Get millisecond (Returns from 0 - 999) +Returns the millisecond ranging from 0 to 999. ```dart -Jiffy().millisecond; +Jiffy.now().millisecond; +``` +### Millisecond since epoch +Returns the number of milliseconds since epoch time `January 1, 1970, 00:00:00 UTC`. +```dart +Jiffy.now().millisecondsSinceEpoch; ``` - ### Second -Get second (Returns from 0 - 59) +Returns the second ranging from 0 to 59. ```dart -Jiffy().second; +Jiffy.now().second; ``` ### Minute -Get minute (Returns from 0 - 59) +Returns the minute ranging from 0 to 59. ```dart -Jiffy().minute; +Jiffy.now().minute; ``` ### Hour -Get hour (Returns from 0 - 23) +Returns the hour ranging from 0 to 23. ```dart -Jiffy().hour; +Jiffy.now().hour; ``` ### Date of month -Get date of month (Returns from 1 - 31) +Returns the date ranging from 1 to 31. ```dart -Jiffy().date; +Jiffy.now().date; ``` -### Days in month -Get days in a month (Returns from 28 - 31) +### Day of week +Returns the day of the week according to the +locale's start of week. The return value is an integer +between 1 and 7, where 1 represents the +locale start of week, either Saturday, Sunday or Monday ```dart -Jiffy().daysInMonth; +Jiffy.now().dayOfWeek; ``` -### Day of week -Get day of week (Returns from 1 - 7 that is [Sunday - Saturday] depending on locale start of week) +### Days in a month +Returns the number of days in the month. ```dart -Jiffy().day; +Jiffy.now().daysInMonth; ``` ### Day of year -Get day o year (Returns from 1 - 366) +Returns the day of the year ranging from 1 to 366, +where 1 represents January 1st of the year and 366 represents +December 31st of a leap year. ```dart -Jiffy().dayOfYear; +Jiffy.now().dayOfYear; ``` ### Week of year -Get week of year +Returns the week of the year based on the current +locale's start of week. The week of the year ranges from 1 to 53, +where week 1 is the first week that has at least 'DateTime.daysPerWeek' days in the new year. ```dart -Jiffy().week; +Jiffy.now().weekOfYear; ``` ### Month -Get month (Returns from 1 - 12 [Jan - Dec]) +Returns the month of the year ranging from 1 to 12, +where 1 represents January and 12 represents December ```dart -Jiffy().month; +Jiffy.now().month; ``` ### Quarter -Get quarter (Returns from 1 - 4) +Returns the quarter on the year ranging from 1 to 4. ```dart -Jiffy().quarter; +Jiffy.now().quarter; ``` ### Year -Get year +Returns the year. ```dart -Jiffy().year; +Jiffy.now().year; ``` # Manipulation -### Add -This adds time to Jiffy by the following units `years, months, weeks, days, hours, minutes, seconds and milliseconds, microseconds and duration`. See below +### Add using Dart's `Duration` object ```dart -Jiffy().add(years: 1); -Jiffy().add(days: 3); -Jiffy().add(months: 3, duration: Duration(days: 3)); -Jiffy().add(years: 1, weeks: 3, duration: Duration(days: 3)); +Jiffy.parse('1997/09/23') + .addDuration(Duration(days: 5, hours: 6)) + .format(); // 1997-09-28T06:00:00.000 ``` -Below are the params that can be used - -`[ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, duration ]` +### Add +This adds time to Jiffy by the following units +`years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds`. ```dart -var jiffy = Jiffy() - .startOf(Units.DAY) - .add(days: 7, months: 1) - .subtract(years: 1); -jiffy.yMMMdjm; // Apr 8, 2020 9:00 PM +Jiffy.parse('1997/09/23') + .add(years: 2, months: 3, days: 5) + .yMMMMd; // December 28, 1999 ``` -**_Note: Months and year are added in respect to how many days there are in a months and if a year is a leap year. See below_** - +### Subtract using Dart's `Duration` object ```dart -Jiffy("2021-1-31", "yyyy-MM-dd").yMMMd; // Jan 31, 2021 -Jiffy("2021-1-31", "yyyy-MM-dd").add(months: 1).yMMMd; // Feb 28, 2021 +Jiffy.parse('1997/09/23') + .subtractDuration(Duration(days: 5, hours: 6)) + .format(); // 1997-09-17T18:00:00.000 ``` + ### Subtract -This subtracts time from Jiffy by the following units `years, months, weeks, days, hours, minutes, seconds and milliseconds`. See below +This subtracts time from Jiffy by the following units +`years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds`. ```dart -Jiffy().subtract(years: 1); -Jiffy().subtract(days: 3); +Jiffy.parse('1997/09/23') + .subtract(years: 2, months: 3, days: 5) + .yMMMMd; // June 18, 1995 ``` ### Start of Time -This set the Jiffy date time to a specific unit in time in terms of years, months, weeks, days, hours, minutes, seconds and milliseconds. See below +Returns a new Jiffy instance representing the start of the specified +`unit` of time The units that are available are, -`[ Units.MILLISECOND, Units.SECOND, Units.MINUTE, Units.HOUR, Units.DAY, Units.WEEK, Units.MONTH, Units.YEAR ]` +`[ Unit.microsecond, Unit.millisecond, Unit.second, Unit.minute, +Unit.hour, Unit.day, Unit.week, Unit.month, Unit.year ]` ```dart -Jiffy().startOf(Units.YEAR); // Set to January 1st, 12:00 am this year -Jiffy().startOf(Units.MONTH); // Set to the first of this month, 12:00 am -Jiffy().startOf(Units.WEEK); // Set to the first day of this week, 12:00 am -Jiffy().startOf(Units.DAY); // Set to 12:00 am today -Jiffy().startOf(Units.HOUR); // Set to now, but with 0 mins, 0 secs, and 0 ms -Jiffy().startOf(Units.MINUTE); // Set to now, but with 0 seconds and 0 milliseconds -Jiffy().startOf(Units.SECONDS); // Set to now, but with 0 milliseconds; -``` +// Set to now, but with 0 microseconds +Jiffy.now().startOf(Unit.millisecond); // 2023-02-26T13:28:20.047000 + +// Set to now, but with 0 milliseconds and microseconds +Jiffy.now().startOf(Unit.second); // 2023-02-26T13:28:20.00000 + +// Set to now, but with 0 seconds, milliseconds and microsecond +Jiffy.now().startOf(Unit.minute); // 2023-02-26T13:28:00.00000 + +// Set to now, but with 0 minutes, seconds, milliseconds and microseconds +Jiffy.now().startOf(Unit.hour); // 2023-02-26T13:00:00.00000 +// Set to now 12:00 am today +Jiffy.now().startOf(Unit.day); // 2023-02-26T00:00:00.00000 + +// Set to the first day of this week, 12:00 am +Jiffy.now().startOf(Unit.week); // 2023-02-26T00:00:00.00000 + +// Set to the first of this month, 12:00 am +Jiffy.now().startOf(Unit.month); // 2023-02-01T00:00:00.00000 + +// Set to January 1st, 12:00 am this year +Jiffy.now().startOf(Unit.year); // 2023-01-01T00:00:00.000000 +``` +Another example ```dart -var jiffy = Jiffy() - .startOf(Units.DAY) +Jiffy.now() + .startOf(Unit.day) .add(days: 1); - .format("MMMM do yyyy, h:mm:ss a"); // March 3rd 2021, 12:00:00 AM + .format('MMMM do yyyy, h:mm:ss a'); // March 3rd 2021, 12:00:00 AM ``` ### End of Time -This set the Jiffy date time to a specific unit in time in terms of years, months, weeks, days, hours, minutes, seconds and milliseconds. See below +Returns a new Jiffy instance representing the end of the specified unit of time ```dart -Jiffy().endOf(Units.YEAR); // Set to December 31st, 23:59:59:999 this year -Jiffy().endOf(Units.MONTH); // Set to the end of this month, 23:59:59:999 -Jiffy().endOf(Units.WEEK); // Set to the end day of this week, 23:59:59:999 -Jiffy().endOf(Units.DAY); // Set to 23:59:59:999 today +Jiffy.now().endOf(Unit.year); // Set to December 31st, 23:59:59:999 this year +Jiffy.now().endOf(Unit.month); // Set to the end of this month, 23:59:59:999 +Jiffy.now().endOf(Unit.week); // Set to the end day of this week, 23:59:59:999 +Jiffy.now().endOf(Unit.day); // Set to 23:59:59:999 today ``` -### Local -Sets Jiffy to local time. See below +### To Local +Sets Jiffy to local time. ```dart -var jiffy = Jiffy().utc(); // Time in utc +var jiffy = Jiffy.parseFromList([2022]).toUtc(); // Time in utc +var jiffy = Jiffy.parseFromList([2022], isUtc: true).utc(); // Also time in utc + jiffy.local(); // Set to local ``` -### UTC -Sets Jiffy to UTC time. See below +### To UTC +Sets Jiffy to UTC time. ```dart -var jiffy = Jiffy(); // Time in local -jiffy.utc(); // Set to utc +var jiffy = Jiffy.now(); // Time in local + +jiffy.toUtc(); // Set to utc ``` # Display ### Format -The format function takes in a string pattern, which can be found [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html), and format them. See below +**_Note: Jiffy runs on top of the [Intl DateFormat](https://pub.dev/packages/intl) +package, so you can find all the date time patterns used +by Jiffy [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html)_** ```dart -Jiffy().format("MMMM do yyyy, h:mm:ss a"); // October 19th 2019, 7:00:53 PM -Jiffy().format("EEEE"); // Saturday -Jiffy().format("yyyy [escaped] yyyy"); // 2019 escaped 2019 +Jiffy.now().format('MMMM do yyyy, h:mm:ss a'); // October 19th 2019, 7:00:53 PM +Jiffy.now().format('EEEE'); // Saturday +Jiffy.now().format('yyyy [escaped] yyyy'); // 2019 escaped 2019 -// Not passing a string pattern for format method will return an ISO Date format +// Not passing a string pattern to the format method will return an ISO Date format Jiffy().format(); // 2019-10-19T19:00:53.090646 ``` -You can also use Intl Dateformat default methods to format. See below +You can also use pre-set formats. ```dart -Jiffy().yMMMMd; // October 19, 2019 -Jiffy().yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM +Jiffy.now().yMMMMd; // October 19, 2019 +Jiffy.now().yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM ``` ### Time from Now -This method is used to get the relative time from now. See below +This method is used to get the relative time from now. ```dart -Jiffy("2007-1-29").fromNow(); // 14 years ago -Jiffy([2022, 10, 29]).fromNow(); // in a year -Jiffy(DateTime(2050, 10, 29)).fromNow(); // in 30 years +Jiffy.parse('2007-01-29').fromNow(); // 14 years ago +Jiffy.parseFromList([2022, 10, 29]).fromNow(); // in a year +Jiffy.parseFromDateTime(DateTime(2050, 10, 29)).fromNow(); // in 30 years -var jiffy = Jiffy().startOf(Units.HOUR).fromNow(); // 9 minutes ago +Jiffy.now().startOf(Unit.hour).fromNow(); // 9 minutes ago ``` ### Time from X -This method is used to get the relative time from a specific date time. See below +This method is used to get the relative time from a specific date time. ```dart -var jiffy1 = Jiffy("2007-1-28"); -var jiffy2 = Jiffy("2017-1-29", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse('2007-01-28'); +var jiffy2 = Jiffy.parse('2017-01-29'); jiffy1.from(jiffy2); // a day ago - -jiffy1.from([2017, 1, 30]); // 2 days ago ``` -### Difference -Used to get the difference between two Jiffy date times. See below + +### Time to Now +This works opposite to the `fromNow()` method. +This method is used to get the relative time to now. ```dart -// By default, diff method, get the difference in milliseconds -var jiffy1 = Jiffy("2007-1-28", "yyyy-MM-dd"); -var jiffy2 = Jiffy("2017-1-29", "yyyy-MM-dd"); -jiff1.diff(jiffy2); // 86400000 +Jiffy.parse('2007-01-29').toNow(); // in 14 years +Jiffy.parseFromList([2022, 10, 29]).toNow(); // a year ago +Jiffy.parseFromDateTime(DateTime(2050, 10, 29)).toNow(); // 30 years ago + +Jiffy.now().startOf(Unit.hour).toNow(); // in 9 minutes ``` -Getting difference in another unit of measurement. The units that are available are, -`[ Units.MILLISECOND, Units.SECOND, Units.MINUTE, Units.HOUR, Units.DAY, Units.WEEK, Units.MONTH, Units.YEAR ]` +### Time to X +This works opposite to the `from()` method. +This method is used to get the relative time to a specific date time. ```dart -Jiffy([2007, 1, 28]).diff([2017, 1, 29], Units.DAY); // -3654 +var jiffy1 = Jiffy.parse('2007-01-28'); +var jiffy2 = Jiffy.parse('2017-01-29'); + +jiffy1.to(jiffy2); // in a day ``` -Also by default `diff` will truncate the result to return a whole number. To get decimal numbers, just pass a third param as `true`. See below +### Difference +Used to get the difference between two Jiffy date times. ```dart -var jiffy1 = Jiffy("2008-10", "yyyy-MM"); -var jiffy2 = Jiffy("2007-1", "yyyy-MM"); +// By default, diff method, get the difference in microseconds +var jiffy1 = Jiffy.parse('2017-1-29'); +var jiffy2 = Jiffy.parse('2017-1-28'); -jiff1.diff(jiffy2, Units.YEAR); // 1 -jiff1.diff(jiffy2, Units.YEAR, true); // 1.75 +jiff1.diff(jiffy2); // 86400000000 ``` -**_Note: Months and years are added in respect to how many days there are in a months and if its a year is a leap year._** +You can get the difference in another unit of measurement. +The units that are available are, -### Unix Timestamp (Milliseconds) -To get timestamp in milliseconds see below +`[ Unit.microsecond, Unit.millisecond, Unit.second, Unit.minute, +Unit.hour, Unit.day, Unit.week, Unit.month, Unit.year ]` ```dart -Jiffy().valueOf(); +Jiffy.parseFromList([2007, 1, 28]) + .diff(Jiffy.parseFromList([2017, 1, 29]), unit: Unit.day); // -3654 ``` -### Unix Timestamp (Seconds) -To get timestamp in seconds see below +Also by default `diff` will truncate the result to return a whole number. +To get decimal numbers, just pass a third param `asFloat` to `false`. ```dart -Jiffy().unix(); +var jiffy1 = Jiffy.parse('2008-10', pattern: 'yyyy-MM'); +var jiffy2 = Jiffy.parse('2007-01', pattern: 'yyyy-MM'); + +jiffy1.diff(jiffy2, unit: Unit.year); // 1 +jiffy1.diff(jiffy2, unit: Unit.year, asFloat: false); // 1.75 ``` # Query ### Is Before -Check if date time is before another date time. See below +Check if date time is before another date time. ```dart -var jiffy1 = Jiffy("2021-10-20"); -var jiffy2 = Jiffy("2021-10-21"); +var jiffy1 = Jiffy.parse("2021-10-20"); +var jiffy2 = Jiffy.parse("2021-10-21"); + jiffy1.isBefore(jiffy2); // true ``` -You can also check in terms of units of measurement. The below example checks if year is before. +You can also check in terms of units of measurement. +The below example checks if year is before. ```dart -var jiffy1 = Jiffy([2020, 10, 20]); +var jiffy1 = Jiffy.parseFromList([2020, 10, 20]); -var jiffy2 = Jiffy("2020-12-31", "yyyy-MM-dd"); -var jiffy3 = Jiffy("2021-01-01", "yyyy-MM-dd"); +var jiffy2 = Jiffy.parse("2020-12-31"); +var jiffy3 = Jiffy.parse("2021-01-01"); -jiffy1.isBefore(jiffy2, Units.YEAR); // false -jiffy1.isBefore(jiffy3, Units.YEAR); // true +jiffy1.isBefore(jiffy2, unit: Unit.year); // false +jiffy1.isBefore(jiffy3, unit: Unit.year); // true ``` ### Is Same -Check if date time is same with another date time. See below +Check if date time is same with another date time. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); -var jiffy2 = Jiffy("2021-10-20", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); +var jiffy2 = Jiffy.parse("2021-10-20"); + jiffy1.isSame(jiffy2); // true ``` -You can also check in terms of units of measurement. The below example checks if years are the same. +You can also check in terms of units of measurement. +The below example checks if years are the same. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); -var jiffy2 = Jiffy("2020-12-31", "yyyy-MM-dd"); -var jiffy3 = Jiffy("2021-01-01", "yyyy-MM-dd"); +var jiffy2 = Jiffy.parse("2020-12-31"); +var jiffy3 = Jiffy.parse("2021-01-01"); -jiffy1.isSame(jiffy2, Units.YEAR); // false -jiffy1.isSame(jiffy3, Units.YEAR); // true +jiffy1.isSame(jiffy2, unit: Unit.year); // false +jiffy1.isSame(jiffy3, unit: Unit.year); // true ``` ### Is After -Check if date time is after another date time. See below +Check if date time is after another date time. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); -var jiffy2 = Jiffy("2021-10-19", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); +var jiffy2 = Jiffy.parse("2021-10-19"); + jiffy1.isAfter(jiffy2); // true ``` -You can also check in terms of units of measurement. The below example checks if year is after. +You can also check in terms of units of measurement. +The below example checks if year is after. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); -var jiffy2 = Jiffy("2021-01-01", "yyyy-MM-dd"); -var jiffy3 = Jiffy("2020-12-31", "yyyy-MM-dd"); +var jiffy2 = Jiffy.parse("2021-01-01"); +var jiffy3 = Jiffy.parse("2020-12-31"); -jiffy1.isAfter(jiffy2, Units.YEAR); // false -jiffy1.isAfter(jiffy3, Units.YEAR); // true +jiffy1.isAfter(jiffy2, Unit.year); // false +jiffy1.isAfter(jiffy3, Unit.year); // true ``` ### Is Same or Before -Check if date time is same or before with another date time. See below +Check if date time is same or before with another date time. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); -var jiffy2 = Jiffy("2020-12-31", "yyyy-MM-dd"); -var jiffy3 = Jiffy("2021-12-31", "yyyy-MM-dd"); -var jiffy4 = Jiffy("2022-01-01", "yyyy-MM-dd"); +var jiffy2 = Jiffy.parse("2020-12-31"); +var jiffy3 = Jiffy.parse("2021-12-31"); +var jiffy4 = Jiffy.parse("2022-01-01"); -jiffy1.isSameOrBefore(jiffy2, Units.YEAR); // false -jiffy1.isSameOrBefore(jiffy3, Units.YEAR); // true -jiffy1.isSameOrBefore(jiffy4, Units.YEAR); // true +jiffy1.isSameOrBefore(jiffy2, Unit.year); // false +jiffy1.isSameOrBefore(jiffy3, Unit.year); // true +jiffy1.isSameOrBefore(jiffy4, Unit.year); // true ``` ### Is Same or After -Check if date time is same or after with another date time. See below +Check if date time is same or after with another date time. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); -var jiffy2 = Jiffy("2022-12-31", "yyyy-MM-dd"); -var jiffy3 = Jiffy("2021-01-01", "yyyy-MM-dd"); -var jiffy4 = Jiffy("2020-12-31", "yyyy-MM-dd"); +var jiffy2 = Jiffy.parse("2022-12-31"); +var jiffy3 = Jiffy.parse("2021-01-01"); +var jiffy4 = Jiffy.parse("2020-12-31"); -jiffy1.isSameOrAfter(jiffy2, Units.YEAR); // false -jiffy1.isSameOrAfter(jiffy3, Units.YEAR); // true -jiffy1.isSameOrAfter(jiffy4, Units.YEAR); // true +jiffy1.isSameOrAfter(jiffy2, Unit.year); // false +jiffy1.isSameOrAfter(jiffy3, Unit.year); // true +jiffy1.isSameOrAfter(jiffy4, Unit.year); // true ``` ### Is Between -Check if a date time is between two date times. See below +Check if a date time is between two date times. ```dart -var jiffy1 = Jiffy("2021-10-20", "yyyy-MM-dd"); +var jiffy1 = Jiffy.parse("2021-10-20"); -var jiffy2 = Jiffy("2021-01-01", "yyyy-MM-dd"); -var jiffy3 = Jiffy("2023-01-01", "yyyy-MM-dd"); +var jiffy2 = Jiffy.parse("2021-01-01"); +var jiffy3 = Jiffy.parse("2023-01-01"); -var jiffy4 = Jiffy("2020-12-31", "yyyy-MM-dd"); -var jiffy5 = Jiffy("2023-01-01", "yyyy-MM-dd"); +var jiffy4 = Jiffy.parse("2020-12-31"); +var jiffy5 = Jiffy.parse("2023-01-01"); -jiffy1.isBetween(jiffy2, jiffy3, Units.YEAR); // false -jiffy1.isBetween(jiffy4, jiffy5, Units.YEAR); // true +jiffy1.isBetween(jiffy2, jiffy3, Unit.year); // false +jiffy1.isBetween(jiffy4, jiffy5, Unit.year); // true ``` -### Is LeapYear -Check if date time is a leap year or not. See below +### Is Local Date Time +Check if date time is local. ```dart -Jiffy("2019", "yyyy").isLeapYear; // false -Jiffy("2016", "yyyy").isLeapYear; // true +Jiffy.parse("2019", pattern: "yyyy").isLeapYear; // false +Jiffy.parse("2016", pattern: "yyyy").isLeapYear; // true ``` -### Is Jiffy -Check if it is a Jiffy instance. See below +### Is UTC Date Time +Check if date time is UTC. ```dart -Jiffy.isJiffy("string"); // false -Jiffy.isJiffy(Jiffy()); // true -Jiffy.isJiffy(DateTime.now()); // false +Jiffy.parse("2019", pattern: "yyyy").isLeapYear; // false +Jiffy.parse("2016", pattern: "yyyy").isLeapYear; // true ``` -### Is DateTime -Check if it is a dart DateTime instance. See below +### Is LeapYear +Check if date time is a leap year or not. ```dart -Jiffy.isDateTime("string"); // false -Jiffy.isDateTime(DateTime.now()); // true -Jiffy.isDateTime(Jiffy()); // false +Jiffy.parse("2019", pattern: "yyyy").isLeapYear; // false +Jiffy.parse("2016", pattern: "yyyy").isLeapYear; // true ``` # Locale Support -```dart -await Jiffy.locale("fr"); -Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25 -``` - -Below are the locales that are supported in Jiffy. More will be added - -| Key | Locale | -| ------------- | ------------- | -| English | en / en_sg / en_au / en_ca / en_gb / en_ie / en_il / en_nz | -| Spanish | es / es_do / es_us | -| Chinese | zh / zh_cn / zh_hk / zh_tw | -| Japanese | ja | -| German | de / de_at / de_ch | -| French | fr / fr_ch / fr_ca | -| Indonesian | id | -| Italian | it / it_ch | -| Korean | ko | -| Russian | ru | -| Ukrainian | uk | -| Hindi | hi | -| Arabic | ar / ar_ly / ar_dz / ar_kw / ar_sa / ar_ma / ar_tn | -| Portuguese | pt / pt_br | -| Polish | pl | -| Turkish | tr | -| Swedish | sv | -| Norwegian | nb | -| Persian | fa | -| Azerbaijani | az | -| Dutch | nl | -| Thailand | th | - -Getting and setting locales in Jiffy **_always returns a future_** - -```dart -// Get the locale (By default, the locale is "en") -await Jiffy.locale(); // en - -// To set locale -await Jiffy.locale("fr"); -Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25 - -await Jiffy.locale("ar"); -Jiffy().yMMMMEEEEdjm; // السبت، ١٩ أكتوبر ٢٠١٩ ٧:٢٧ م - -await Jiffy.locale("zh-cn"); -Jiffy().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28 -``` - -### Get all available locales - -To get all available locales in Jiffy run the following - -```dart -Jiffy.getAllAvailableLocales() // returns all locales -``` +Below are the locales that are supported in Jiffy. More can be added. + +| Locale | Locale Code | +|-------------|--------------------------------------------------------------------| +| English | en / en_us / en_sg / en_au / en_ca / en_gb / en_ie / en_il / en_nz | +| Spanish | es / es_us / es_do | +| French | fr / fr_ch / fr_ca | +| Chinese | zh / zh_cn / zh_hk / zh_tw | +| Japan | ja | +| Korean | ko | +| German | de / de_de / de_at / de_ch | +| Italian | it / it_ch | +| Hindi | hi | +| Bangladesh | bn | +| Portuguese | pt / pt_br | +| Indonesian | id | +| Russian | ru | +| Swedish | sv | +| Ukrainian | uk | +| Arabic | ar / ar_ly / ar_dz / ar_kw / ar_sa / ar_ma /_tn | +| Hungarian | hu / hu_hu | +| Polish | pl | +| Turkish | tr | +| Norwegian | nb | +| Persian | fa | +| Azerbaijani | az | +| Dutch | nl | +| Thailand | th | + + +## Setting a locale +Setting locales in Jiffy **_always returns a future_** + +```dart +// To set a locale +await Jiffy.setLocale('fr'); +Jiffy.now().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25 + +await Jiffy.setLocale('ar'); +Jiffy.now().yMMMMEEEEdjm; // السبت، ١٩ أكتوبر ٢٠١٩ ٧:٢٧ م + +await Jiffy.setLocale('zh-cn'); +Jiffy.now().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28 +``` + +## Getting the locale code +```dart +var localeCode = Jiffy.now().localeCode; // eu_us +``` \ No newline at end of file diff --git a/example/jiffy_example.dart b/example/jiffy_example.dart index 6bf5f3b..9b44bd3 100644 --- a/example/jiffy_example.dart +++ b/example/jiffy_example.dart @@ -1,74 +1,92 @@ import 'package:jiffy/jiffy.dart'; -Future main() async { -// DISPLAY - Jiffy([2021, 1, 19]) - .format('MMM do yyyy, h:mm:ss a'); // January 1st 2021, 12:00:00 AM - Jiffy().format('EEEE'); // Tuesday - Jiffy().format('MMM do yy'); // Mar 2nd 21 - Jiffy().format('yyyy [escaped] yyyy'); // 2021 escaped 2021 - Jiffy().format(); // 2021-03-02T15:18:29.922343 - -// Not passing a string pattern for format method will return an ISO Date format - Jiffy().format(); // 2021-03-02T15:18:29.922343 - -// Using lists - Jiffy([2019, 10, 19]).yMMMMd; // January 19, 2021 - -// Using maps - Jiffy({'year': 2019, 'month': 10, 'day': 19, 'hour': 19}) - .yMMMMEEEEdjm; // Monday, October 19, 2020 7:14 PM - - // 'From Now' implementation - Jiffy('2007-1-29').fromNow(); // 14 years ago - Jiffy([2022, 10, 29]).fromNow(); // in a year - Jiffy(DateTime(2050, 10, 29)).fromNow(); // in 30 years - - Jiffy().startOf(Units.HOUR).fromNow(); // 9 minutes ago - -// 'From X' implementation - var jiffy2 = Jiffy('2007-1-28'); - var jiffy3 = Jiffy('2017-1-29', 'yyyy-MM-dd'); - - jiffy2.from(jiffy3); // a day ago - - jiffy2.from([2017, 1, 30]); // 2 days ago - -// Displaying the 'Difference' between two date times -// By default, 'diff' method, get the difference in milliseconds - var jiffy4 = Jiffy('2007-1-28', 'yyyy-MM-dd'); - var jiffy5 = Jiffy('2017-1-29', 'yyyy-MM-dd'); - jiffy4.diff(jiffy5); // 86400000 - - // You can also get 'diff' in different units of time - Jiffy([2007, 1, 28]).diff([2017, 1, 29], Units.DAY); // -3654 - -// RELATIVE TIME - Jiffy('2011-10-31').fromNow(); // 8 years ago - Jiffy(DateTime(2012, 6, 20)).fromNow(); // 7 years ago - - Jiffy().startOf(Units.DAY).fromNow(); // 19 hours ago - - Jiffy().endOf(Units.DAY).fromNow(); // in 5 hours - - Jiffy().startOf(Units.HOUR).fromNow(); // 9 minutes ago - -// MANIPULATING DATES - Jiffy().add(duration: Duration(days: 1)).yMMMMd; // October 20, 2019 - - Jiffy().subtract(days: 1).yMMMMd; // October 18, 2019 - -// LOCALES -// The locale method always return a future -// To get locale (The default locale is English) - await Jiffy.locale(); // en -// To set locale - await Jiffy.locale('fr'); - Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25 - await Jiffy.locale('ar'); - Jiffy().yMMMMEEEEdjm; // السبت، ١٩ أكتوبر ٢٠١٩ ٧:٢٧ م - await Jiffy.locale('zh_cn'); - Jiffy().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28 - - return 0; +void main() { + // Parsing and formatting date time + // Parsing from string + Jiffy.parse('1997/09/23').format(); // 1997-09-23T00:00:00.000 + // Parsing from string and pattern + Jiffy.parse('Sep 97, 23rd', pattern: 'MMM yy, do') + .yMMMMEEEEd; // Tuesday, September 23, 1997 + // Parsing from a dart DateTime object + Jiffy.parseFromDateTime(DateTime(1997, 9, 23)).yMMMM; // September 1997 + // Parsing from a date time list + Jiffy.parseFromList([1997, 9, 23]).MMMEd; // Tue, Sep 23 + // Parsing from a date time map + Jiffy.parseFromMap({Unit.year: 1997, Unit.month: 9, Unit.day: 23}).format( + pattern: '[The date is] do, MMM yyyy'); // The date is 23rd, Sep 1997 + + // Relative date time + // From X + Jiffy.parse('1997/09/23').from(Jiffy.parse('2002/10/26')); // 5 years ago + // From Now + Jiffy.parse('1997/09/23').fromNow(); // 25 years ago + + // To X + Jiffy.parse('1997/09/23').to(Jiffy.parse('2002/10/26')); // in 5 years + // To Now + Jiffy.parse('1997/09/23').toNow(); // in 25 years + + // Manipulating date time + // Adding to date time using dart Duration object + Jiffy.parse('1997/09/23') + .addDuration(Duration(days: 5, hours: 6)) + .format(); // 1997-09-28T06:00:00.000 + // Adding to date time + Jiffy.parse('1997/09/23') + .add(years: 2, months: 3, days: 5) + .yMMMMd; // December 28, 1999 + + // Subtracting from date time using dart Duration object + Jiffy.parse('1997/09/23') + .subtractDuration(Duration(days: 5, hours: 6)) + .format(); // 1997-09-17T18:00:00.000 + // Subtracting from date time + Jiffy.parse('1997/09/23') + .subtract(years: 2, months: 3, days: 5) + .yMMMMd; // June 18, 1995 + + // Getting the start of date time + Jiffy.parse('1997/09/23') + .startOf(Unit.year) + .yMMMMEEEEd; // Wednesday, January 1, 1997 + Jiffy.parse('1997/09/23') + .startOf(Unit.month) + .yMMMMEEEEd; // Monday, September 1, 1997 + Jiffy.parse('1997/09/23') + .startOf(Unit.week) + .yMMMMEEEEd; // Sunday, September 21, 1997 + // Getting the end of date time + Jiffy.parse('1997/09/23') + .endOf(Unit.year) + .yMMMMEEEEd; // Wednesday, December 31, 1997 + Jiffy.parse('1997/09/23') + .endOf(Unit.month) + .yMMMMEEEEd; // Tuesday, September 30, 1997 + Jiffy.parse('1997/09/23') + .endOf(Unit.week) + .yMMMMEEEEd; // Saturday, September 27, 1997 + + // Querying date time + // Is before date time + Jiffy.parse('1997/9/23').isBefore(Jiffy.parse('1997/9/24')); // true + Jiffy.parse('1997/9/23').isBefore(Jiffy.parse('1997/9/20')); // false + // Is after date time + Jiffy.parse('1997/9/23').isAfter(Jiffy.parse('1997/9/24')); // false + Jiffy.parse('1997/9/23').isAfter(Jiffy.parse('1997/9/20')); // true + // Is same as date time + Jiffy.parse('1997/9/23').isSame(Jiffy.parse('1997/9/24')); // false + Jiffy.parse('1997/9/23').isSame(Jiffy.parse('1997/9/23')); // true + // Is same or before date time + Jiffy.parse('1997/9/23').isSameOrBefore(Jiffy.parse('1997/9/23')); // true + Jiffy.parse('1997/9/23').isSameOrBefore(Jiffy.parse('1997/9/20')); // false + Jiffy.parse('1997/9/23').isSameOrBefore(Jiffy.parse('1997/9/24')); // true + // Is same or after date time + Jiffy.parse('1997/9/23').isSameOrAfter(Jiffy.parse('1997/9/23')); // true + Jiffy.parse('1997/9/23').isSameOrAfter(Jiffy.parse('1997/9/20')); // true + Jiffy.parse('1997/9/23').isSameOrAfter(Jiffy.parse('1997/9/24')); // false + // Is between to date times + Jiffy.parse('1997/9/23') + .isBetween(Jiffy.parse('1997/9/20'), Jiffy.parse('1997/9/24')); // true + Jiffy.parse('1997/9/19') + .isBetween(Jiffy.parse('1997/9/20'), Jiffy.parse('1997/9/24')); // false } diff --git a/lib/jiffy.dart b/lib/jiffy.dart index b36c167..e17b4a7 100644 --- a/lib/jiffy.dart +++ b/lib/jiffy.dart @@ -1,7 +1,8 @@ -/// Support for doing something awesome. -/// -/// More dartdocs go here. +/// Jiffy is a Flutter (Android, IOS and Web) date time package inspired by +/// [momentjs](https://momentjs.com/) for parsing, manipulating, querying +/// and formatting dates library jiffy; +export 'src/enums/unit.dart'; +export 'src/enums/start_of_week.dart'; export 'src/jiffy.dart'; -export 'src/enums/units.dart'; diff --git a/lib/src/default_display.dart b/lib/src/default_display.dart new file mode 100644 index 0000000..417ae79 --- /dev/null +++ b/lib/src/default_display.dart @@ -0,0 +1,88 @@ +import 'package:intl/intl.dart'; + +class DefaultDisplay { + String E(DateTime dateTime) => DateFormat.E().format(dateTime); + + // ignore: non_constant_identifier_names + String EEEE(DateTime dateTime) => DateFormat.EEEE().format(dateTime); + + // ignore: non_constant_identifier_names + String Md(DateTime dateTime) => DateFormat.Md().format(dateTime); + + // ignore: non_constant_identifier_names + String MEd(DateTime dateTime) => DateFormat.MEd().format(dateTime); + + // ignore: non_constant_identifier_names + String MMM(DateTime dateTime) => DateFormat.MMM().format(dateTime); + + // ignore: non_constant_identifier_names + String MMMd(DateTime dateTime) => DateFormat.MMMd().format(dateTime); + + // ignore: non_constant_identifier_names + String MMMEd(DateTime dateTime) => DateFormat.MMMEd().format(dateTime); + + // ignore: non_constant_identifier_names + String MMMM(DateTime dateTime) => DateFormat.MMMM().format(dateTime); + + // ignore: non_constant_identifier_names + String MMMMd(DateTime dateTime) => DateFormat.MMMMd().format(dateTime); + + // ignore: non_constant_identifier_names + String MMMMEEEEd(DateTime dateTime) => + DateFormat.MMMMEEEEd().format(dateTime); + + // ignore: non_constant_identifier_names + String QQQ(DateTime dateTime) => DateFormat.QQQ().format(dateTime); + + // ignore: non_constant_identifier_names + String QQQQ(DateTime dateTime) => DateFormat.QQQQ().format(dateTime); + + String yM(DateTime dateTime) => DateFormat.yM().format(dateTime); + + String yMd(DateTime dateTime) => DateFormat.yMd().format(dateTime); + + String yMEd(DateTime dateTime) => DateFormat.yMEd().format(dateTime); + + String yMMM(DateTime dateTime) => DateFormat.yMMM().format(dateTime); + + String yMMMd(DateTime dateTime) => DateFormat.yMMMd().format(dateTime); + + String yMMMdjm(DateTime dateTime) => + DateFormat.yMMMd().add_jm().format(dateTime); + + String yMMMEd(DateTime dateTime) => DateFormat.yMMMEd().format(dateTime); + + String yMMMEdjm(DateTime dateTime) => + DateFormat.yMMMEd().add_jm().format(dateTime); + + String yMMMM(DateTime dateTime) => DateFormat.yMMMM().format(dateTime); + + String yMMMMd(DateTime dateTime) => DateFormat.yMMMMd().format(dateTime); + + String yMMMMdjm(DateTime dateTime) => + DateFormat.yMMMMd().add_jm().format(dateTime); + + String yMMMMEEEEd(DateTime dateTime) => + DateFormat.yMMMMEEEEd().format(dateTime); + + String yMMMMEEEEdjm(DateTime dateTime) => + DateFormat.yMMMMEEEEd().add_jm().format(dateTime); + + String yQQQ(DateTime dateTime) => DateFormat.yQQQ().format(dateTime); + + String yQQQQ(DateTime dateTime) => DateFormat.yQQQQ().format(dateTime); + + String H(DateTime dateTime) => DateFormat.H().format(dateTime); + + // ignore: non_constant_identifier_names + String Hm(DateTime dateTime) => DateFormat.Hm().format(dateTime); + + // ignore: non_constant_identifier_names + String Hms(DateTime dateTime) => DateFormat.Hms().format(dateTime); + + String j(DateTime dateTime) => DateFormat.j().format(dateTime); + + String jm(DateTime dateTime) => DateFormat.jm().format(dateTime); + + String jms(DateTime dateTime) => DateFormat.jms().format(dateTime); +} diff --git a/lib/src/display.dart b/lib/src/display.dart new file mode 100644 index 0000000..55fc26d --- /dev/null +++ b/lib/src/display.dart @@ -0,0 +1,222 @@ +import 'package:intl/intl.dart'; + +import 'getter.dart'; +import 'enums/unit.dart'; +import 'locale/locale.dart'; +import 'manipulator.dart'; +import 'query.dart'; +import 'utils/jiffy_exception.dart'; + +class Display { + final Getter _getter; + final Manipulator _manipulator; + final Query _query; + + Display(this._getter, this._manipulator, this._query); + + String formatToISO8601(DateTime dateTime) => dateTime.toIso8601String(); + + String format(DateTime dateTime, String pattern, Locale locale) { + if (pattern.trim().isEmpty) { + throw JiffyException('The provided pattern for datetime `$dateTime` ' + 'cannot be blank'); + } + try { + final escapedPattern = _replaceEscapePattern(pattern); + final localeOrdinal = _getLocaleOrdinal(locale, _getter.date(dateTime)); + final newPattern = + _replaceLocaleOrdinalDatePattern(escapedPattern, localeOrdinal); + return DateFormat(newPattern).format(dateTime); + } catch (error, stackTrace) { + throw JiffyException('The pattern `$pattern` might be invalid: \n' + 'Error: $error' + 'Stack Trace: $stackTrace'); + } + } + + String fromAsRelativeDateTime( + DateTime firstDateTime, DateTime secondDateTime, Locale locale) { + final isFirstDateTimeSameOrAfterSecondDateTime = _query.isSameOrAfter( + firstDateTime, secondDateTime, Unit.microsecond, locale.startOfWeek()); + + final relativeDateTime = locale.relativeDateTime(); + String prefix, suffix; + + if (isFirstDateTimeSameOrAfterSecondDateTime) { + prefix = relativeDateTime.prefixFromNow(); + suffix = relativeDateTime.suffixFromNow(); + } else { + prefix = relativeDateTime.prefixAgo(); + suffix = relativeDateTime.suffixAgo(); + } + + final seconds = + diff(firstDateTime, secondDateTime, Unit.second, false).abs(); + final minutes = + diff(firstDateTime, secondDateTime, Unit.minute, false).abs(); + final hours = diff(firstDateTime, secondDateTime, Unit.hour, false).abs(); + final days = diff(firstDateTime, secondDateTime, Unit.day, false).abs(); + final months = diff(firstDateTime, secondDateTime, Unit.month, false).abs(); + final years = diff(firstDateTime, secondDateTime, Unit.year, false).abs(); + + String result; + + if (seconds < 45) { + result = relativeDateTime.lessThanOneMinute(seconds.round()); + } else if (seconds < 90) { + result = relativeDateTime.aboutAMinute(minutes.round()); + } else if (minutes < 45) { + result = relativeDateTime.minutes(minutes.round()); + } else if (minutes < 90) { + result = relativeDateTime.aboutAnHour(minutes.round()); + } else if (hours < 24) { + result = relativeDateTime.hours(hours.round()); + } else if (hours < 48) { + result = relativeDateTime.aDay(hours.round()); + } else if (days < 30) { + result = relativeDateTime.days(days.round()); + } else if (days < 60) { + result = relativeDateTime.aboutAMonth(days.round()); + } else if (days < 365) { + result = relativeDateTime.months(months.round()); + } else if (years < 2) { + result = relativeDateTime.aboutAYear(months.round()); + } else { + result = relativeDateTime.years(years.round()); + } + + return [prefix, result, suffix] + .where((str) => str.isNotEmpty) + .join(relativeDateTime.wordSeparator()); + } + + String toAsRelativeDateTime( + DateTime firstDateTime, DateTime secondDateTime, Locale locale) { + return fromAsRelativeDateTime(secondDateTime, firstDateTime, locale); + } + + num diff(DateTime firstDateTime, DateTime secondDateTime, Unit unit, + bool asFloat) { + final firstDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch(firstDateTime); + final secondDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch(secondDateTime); + final diffMicrosecondsSinceEpoch = firstDateTimeMicrosecondsSinceEpoch - + secondDateTimeMicrosecondsSinceEpoch; + + num diff; + + switch (unit) { + case Unit.microsecond: + diff = diffMicrosecondsSinceEpoch; + break; + case Unit.millisecond: + diff = diffMicrosecondsSinceEpoch / Duration.microsecondsPerMillisecond; + break; + case Unit.second: + diff = diffMicrosecondsSinceEpoch / Duration.microsecondsPerSecond; + break; + case Unit.minute: + diff = diffMicrosecondsSinceEpoch / Duration.microsecondsPerMinute; + break; + case Unit.hour: + diff = diffMicrosecondsSinceEpoch / Duration.microsecondsPerHour; + break; + case Unit.day: + diff = diffMicrosecondsSinceEpoch / Duration.microsecondsPerDay; + break; + case Unit.week: + diff = (diffMicrosecondsSinceEpoch / Duration.microsecondsPerDay) / 7; + break; + case Unit.month: + diff = _monthDiff(firstDateTime, secondDateTime); + break; + case Unit.year: + diff = _monthDiff(firstDateTime, secondDateTime) / 12; + break; + } + + return asFloat ? _asFloor(diff) : diff; + } + + String _getLocaleOrdinal(Locale locale, int date) { + final ordinals = locale.ordinals(); + var suffix = ordinals.last; + final digit = date % 10; + if ((digit > 0 && digit < 4) && (date < 11 || date > 13)) { + suffix = ordinals[digit - 1]; + } + return suffix; + } + + String _replaceEscapePattern(String input) { + return input + .replaceAll('\'', '\'\'') + .replaceAll('[', '\'') + .replaceAll(']', '\''); + } + + String _replaceLocaleOrdinalDatePattern(String input, String localeOrdinal) { + var matches = _matchesOrdinalDatePattern(input); + var pattern = input; + + while (matches.isNotEmpty) { + final match = matches.first; + pattern = pattern.replaceRange(match.start, match.end, + 'd${localeOrdinal.isNotEmpty ? "'$localeOrdinal'" : ''}'); + matches = _matchesOrdinalDatePattern(pattern); + } + return pattern; + } + + List _matchesOrdinalDatePattern(String input) { + return RegExp(''''[^']*'|(do)''') + .allMatches(input) + .where((match) => match.group(1) == 'do') + .toList(); + } + + num _monthDiff(DateTime firstDateTime, DateTime secondDateTime) { + if (_getter.date(firstDateTime) < _getter.date(secondDateTime)) { + return -(_monthDiff(secondDateTime, firstDateTime)); + } + + final monthDiff = + ((_getter.year(secondDateTime) - _getter.year(firstDateTime)) * 12) + + (_getter.month(secondDateTime) - _getter.month(firstDateTime)); + + final thirdDateTime = _addMonths(firstDateTime, monthDiff); + final thirdDateTimeMicrosecondsSinceEpoch = + _getMicrosecondsSinceEpoch(thirdDateTime); + + final diffMicrosecondsSinceEpoch = + _getMicrosecondsSinceEpoch(secondDateTime) - + thirdDateTimeMicrosecondsSinceEpoch; + + double offset; + + if (diffMicrosecondsSinceEpoch < 0) { + final fifthDateTime = _addMonths(firstDateTime, monthDiff - 1); + offset = diffMicrosecondsSinceEpoch / + (thirdDateTimeMicrosecondsSinceEpoch - + _getMicrosecondsSinceEpoch(fifthDateTime)); + } else { + final fifthDateTime = _addMonths(firstDateTime, monthDiff + 1); + offset = diffMicrosecondsSinceEpoch / + (_getMicrosecondsSinceEpoch(fifthDateTime) - + thirdDateTimeMicrosecondsSinceEpoch); + } + + return -(monthDiff + offset); + } + + int _asFloor(num number) => number < 0 ? number.ceil() : number.floor(); + + DateTime _addMonths(DateTime dateTime, int months) { + return _manipulator.add(dateTime, 0, 0, 0, 0, 0, 0, 0, months, 0); + } + + int _getMicrosecondsSinceEpoch(DateTime dateTime) { + return _getter.microsecondsSinceEpoch(dateTime); + } +} diff --git a/lib/src/enums/startOfWeek.dart b/lib/src/enums/startOfWeek.dart deleted file mode 100644 index d635372..0000000 --- a/lib/src/enums/startOfWeek.dart +++ /dev/null @@ -1 +0,0 @@ -enum StartOfWeek { SATURDAY, SUNDAY, MONDAY } diff --git a/lib/src/enums/start_of_week.dart b/lib/src/enums/start_of_week.dart new file mode 100644 index 0000000..67ec522 --- /dev/null +++ b/lib/src/enums/start_of_week.dart @@ -0,0 +1 @@ +enum StartOfWeek { saturday, sunday, monday } diff --git a/lib/src/enums/unit.dart b/lib/src/enums/unit.dart new file mode 100644 index 0000000..83cd357 --- /dev/null +++ b/lib/src/enums/unit.dart @@ -0,0 +1,11 @@ +enum Unit { + microsecond, + millisecond, + second, + minute, + hour, + day, + week, + month, + year +} diff --git a/lib/src/enums/units.dart b/lib/src/enums/units.dart deleted file mode 100644 index d21a841..0000000 --- a/lib/src/enums/units.dart +++ /dev/null @@ -1 +0,0 @@ -enum Units { MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } diff --git a/lib/src/getter.dart b/lib/src/getter.dart new file mode 100644 index 0000000..214f0fe --- /dev/null +++ b/lib/src/getter.dart @@ -0,0 +1,76 @@ +import 'package:intl/intl.dart'; + +import 'enums/start_of_week.dart'; +import 'query.dart'; + +class Getter { + DateTime dateTime(DateTime dateTime) => dateTime.copyWith(); + + int microsecond(DateTime dateTime) => dateTime.microsecond; + + int microsecondsSinceEpoch(DateTime dateTime) { + return dateTime.microsecondsSinceEpoch; + } + + int millisecond(DateTime dateTime) => dateTime.millisecond; + + int millisecondsSinceEpoch(DateTime dateTime) { + return dateTime.millisecondsSinceEpoch; + } + + int second(DateTime dateTime) => dateTime.second; + + int minute(DateTime dateTime) => dateTime.minute; + + int hour(DateTime dateTime) => dateTime.hour; + + int date(DateTime dateTime) => dateTime.day; + + int dayOfWeek(DateTime dateTime, StartOfWeek startOfWeek) { + var weekDays = [1, 2, 3, 4, 5, 6, 7, 1, 2]; + var weekDayIndex = dateTime.weekday - 1; + + switch (startOfWeek) { + case StartOfWeek.monday: + break; + case StartOfWeek.sunday: + weekDayIndex += 1; + break; + case StartOfWeek.saturday: + weekDayIndex += 2; + break; + } + + return weekDays[weekDayIndex]; + } + + int daysInMonth(DateTime dateTime) => + _daysInMonth(dateTime.year, dateTime.month); + + int weekOfYear(DateTime dateTime, StartOfWeek startOfWeek) { + return ((dayOfYear(dateTime) - dayOfWeek(dateTime, startOfWeek) + 10) / 7) + .floor(); + } + + int month(DateTime dateTime) => dateTime.month; + + int quarterOfYear(DateTime dateTime) { + return int.parse(DateFormat('Q').format(dateTime)); + } + + int dayOfYear(DateTime dateTime) { + return int.parse(DateFormat('D').format(dateTime)); + } + + int year(DateTime dateTime) => dateTime.year; + + int _daysInMonth(int year, int month) { + var result = daysInMonthArray[month]; + if (month == 2 && Query.isLeapYear(year)) result++; + return result; + } + + static final List daysInMonthArray = List.from( + [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], + growable: false); +} diff --git a/lib/src/jiffy.dart b/lib/src/jiffy.dart index b261105..64fba49 100644 --- a/lib/src/jiffy.dart +++ b/lib/src/jiffy.dart @@ -1,605 +1,832 @@ -import 'dart:math'; - -import 'package:intl/date_symbol_data_local.dart'; import 'package:intl/intl.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/enums/units.dart'; -import 'package:jiffy/src/locale/availableLocales.dart'; -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/utils/exception.dart'; -import 'package:jiffy/src/utils/normalize_units.dart'; -import 'package:jiffy/src/utils/regex.dart'; -import 'package:jiffy/src/utils/replace.dart'; +import 'package:intl/date_symbol_data_local.dart'; +import './default_display.dart'; +import './display.dart'; +import './enums/start_of_week.dart'; +import './enums/unit.dart'; +import './getter.dart'; +import './locale/available_locales.dart'; +import './locale/locale.dart'; +import './locale/locales/en_locale.dart'; +import './manipulator.dart'; +import './parser.dart'; +import './query.dart'; +import './utils/jiffy_exception.dart'; + +/// Jiffy is a Flutter (Android, IOS and Web) date time package inspired by +/// [momentjs](https://momentjs.com/) for parsing, manipulating, querying and +/// formatting dates class Jiffy { - late DateTime _dateTime; - static late Locale _defaultLocale; - - DateTime get dateTime => _dateTime; - - Jiffy([var input, String? pattern]) { - _initializeDateTime(input, pattern); + late final Getter _getter; + late final DefaultDisplay _defaultDisplay; + late final Parser _parser; + late final Manipulator _manipulator; + late final Query _query; + late final Display _display; + + late Locale _locale; + late final DateTime _dateTime; + + Jiffy._internal(var input, {String? pattern, bool isUtc = false}) { + _initializeDependencies(); _initializeLocale(); - } - - Jiffy.unixFromSecondsSinceEpoch(int timestamp) { - _unix(timestamp * 1000); - } - - Jiffy.unixFromMillisecondsSinceEpoch(int timestamp) { - _unix(timestamp); - } - - void _unix(int timestamp) { - _dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp); - } - - Jiffy clone() { - return Jiffy(this); - } - - void _initializeDateTime(var input, [String? pattern]) { - _dateTime = _parse(input, pattern); - } - - DateTime _parse(var input, [String? pattern]) { - var dateTime; - if (input == null && pattern == null) { - dateTime = DateTime.now(); - } else if (isDateTime(input)) { - dateTime = input; - } else if (isJiffy(input)) { - dateTime = input.dateTime; - } else if (input is Map) { - dateTime = _parseMap(input); - } else if (input is List) { - dateTime = _parseList(input); + _initializeDateTime(input, pattern, isUtc); + } + + /// Constructs a new [Jiffy] instance by parsing a [String]. + /// + /// If [pattern] is not provided, [string] must be in one of the following + /// formats: + /// + /// * `'1997-09-23'` + /// * `'1997/09/23'` + /// * `'1997-09-23 11:18:12.946621'` + /// * `'1997-09-23T11:18:12.947031'` + /// + /// If [pattern] is provided, [string] should match the specified format. + /// + /// Example usage: + /// + /// ```dart + /// final jiffy1 = Jiffy.parse('1997-09-23'); + /// final jiffy2 = Jiffy.parse('1997 Sep 23th', pattern: 'yyyy MMM do'); + /// ``` + /// + /// Throws a [JiffyException] if the input [string] cannot be parsed. + factory Jiffy.parse(String string, {String? pattern, bool isUtc = false}) { + return Jiffy._internal(string, pattern: pattern, isUtc: isUtc); + } + + /// Constructs a new [Jiffy] instance from a [DateTime] object. + /// + /// The resulting [Jiffy] object will represent the same date and time as + /// the provided [dateTime] object. + /// + /// Example usage: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromDateTime(DateTime.now()); + /// ``` + factory Jiffy.parseFromDateTime(DateTime dateTime) { + return Jiffy._internal(dateTime); + } + + /// Constructs a new [Jiffy] instance from an existing [Jiffy] object. + /// + /// The resulting [Jiffy] object will have the same date and time values as + /// the provided [Jiffy] object. This can be useful if you need to create a + /// new [Jiffy] object based on an existing one, for example, to apply a + /// time zone offset or to format the date and time differently. + /// + /// Example usage: + /// + /// ```dart + /// final jiffy1 = Jiffy.now(); + /// final jiffy2 = Jiffy.parseFromJiffy(jiffy1); + /// ``` + /// + /// Alternatively, you can use the `clone` method of a [Jiffy] object to + /// create a new [Jiffy] object with the same values as the original. + /// + /// ```dart + /// final jiffy1 = Jiffy.now(); + /// final jiffy2 = jiffy1.clone(); + /// ``` + factory Jiffy.parseFromJiffy(Jiffy jiffy) { + return Jiffy._internal(jiffy); + } + + /// Constructs a [Jiffy] instance from a list of integers representing a + /// date and time. + /// + /// The [list] parameter should be a list of integers in the following order: + /// + /// `[year, month, day, hour, minute, second, millisecond, microsecond]`. + /// + /// At least `year` should be provided. Any other values that are not + /// provided will default to their minimum value (For example, day and month + /// will default to 1 and, hour, minute, second, millisecond, and microsecond + /// will default to 0 if not provided). + /// + /// Example usage: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromList([1997, 9, 23]); + /// ``` + /// Throws a [JiffyException] if the input [list] is empty. + factory Jiffy.parseFromList(List list, {bool isUtc = false}) { + return Jiffy._internal(list, isUtc: isUtc); + } + + /// Constructs a [Jiffy] instance from a [map] of date and time values. + /// + /// The [map] parameter should be a map of [Unit] values to integer values. + /// The [Unit] enum specifies the different date and time units that can be + /// provided in the map, including year, month, day, hour, minute, second, + /// millisecond, and microsecond. + /// + /// If any of the other keys ('UNIT.YEAR', 'UNIT.MONTH', 'UNIT.DAY', + /// 'UNIT.HOUR', 'UNIT.MINUTE', 'UNIT.SECOND', 'UNIT.MILLISECOND', + /// 'UNIT.MICROSECOND') are not provided, they default to the current + /// date time value. + /// + /// Example usage: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromMap( + /// { + /// Unit.YEAR: 1997, + /// Unit.MONTH: 9, + /// Unit.DAY: 23, + /// } + /// ); + /// ``` + /// + /// Throws a [JiffyException] if the input [map] is empty. + factory Jiffy.parseFromMap(Map map, {bool isUtc = false}) { + return Jiffy._internal(map, isUtc: isUtc); + } + + /// Constructs a [Jiffy] instance from a [microsecondsSinceEpoch] of type + /// [int]. + /// + /// The [microsecondsSinceEpoch] represents the number of microseconds since + /// epoch time, which is `January 1, 1970, 00:00:00 UTC`. + /// + /// ```dart + /// final now = DateTime.now(); + /// final jiffy = Jiffy.parseFromMicrosecondsSinceEpoch(now.microsecondsSinceEpoch); + /// ``` + factory Jiffy.parseFromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, + {bool isUtc = false}) { + return Jiffy._internal(DateTime.fromMicrosecondsSinceEpoch( + microsecondsSinceEpoch, + isUtc: isUtc)); + } + + /// Constructs a [Jiffy] instance from a [millisecondsSinceEpoch] of type + /// [int]. + /// + /// The [millisecondsSinceEpoch] represents the number of milliseconds since + /// epoch time, which is `January 1, 1970, 00:00:00 UTC`. + /// + /// ```dart + /// final now = DateTime.now(); + /// final jiffy = Jiffy.parseFromMillisecondsSinceEpoch(now.millisecondsSinceEpoch); + /// ``` + factory Jiffy.parseFromMillisecondsSinceEpoch(int millisecondsSinceEpoch, + {bool isUtc = false}) { + return Jiffy._internal(DateTime.fromMillisecondsSinceEpoch( + millisecondsSinceEpoch, + isUtc: isUtc)); + } + + /// Returns a [Jiffy] instance representing the current date and time. + /// + /// ```dart + /// final now = Jiffy.now(); + /// ``` + factory Jiffy.now() => Jiffy._internal(DateTime.now()); + + void _initializeDependencies() { + _getter = Getter(); + _defaultDisplay = DefaultDisplay(); + _parser = Parser(_getter); + _manipulator = Manipulator(_getter); + _query = Query(_getter, _manipulator); + _display = Display(_getter, _manipulator, _query); + } + + void _initializeDateTime(var input, String? pattern, bool isUtc) { + if (input is DateTime) { + _dateTime = _getter.dateTime(input); + } else if (input is Jiffy) { + _dateTime = input.dateTime; } else if (input is String) { - dateTime = _parseString(input, pattern); + _dateTime = _parser.fromString(input, pattern, _locale, isUtc); + } else if (input is List) { + _dateTime = _parser.fromList(input, isUtc); + } else if (input is Map) { + _dateTime = _parser.fromMap(input, isUtc); } else { - throw JiffyException( - 'Jiffy only accepts String, List, Map, DateTime or Jiffy itself as parameters') - .cause; + throw JiffyException('Could not parse input: `$input`, ' + 'only String, List, Map, DateTime and Jiffy are allowed'); } - return dateTime; } - DateTime _parseMap(Map input) { - input.forEach((key, value) { - validateUnits(key); - }); - if (input.isEmpty) { - return DateTime.now(); - } else { - return DateTime( - input['year'] ?? input['years'] ?? input['y'] ?? DateTime.now().year, - input['month'] ?? - input['months'] ?? - input['M'] ?? - DateTime.now().month, - input['day'] ?? input['days'] ?? input['d'] ?? DateTime.now().day, - input['hour'] ?? input['hours'] ?? input['h'] ?? DateTime.now().hour, - input['minute'] ?? - input['minutes'] ?? - input['m'] ?? - DateTime.now().minute, - input['second'] ?? - input['seconds'] ?? - input['s'] ?? - DateTime.now().second, - input['millisecond'] ?? - input['milliseconds'] ?? - input['ms'] ?? - DateTime.now().millisecond); - } - } - - DateTime _parseList(List input) { - if (input.isEmpty) { - return DateTime.now(); - } else { - return DateTime( - input[0], - input.length > 1 ? input[1] : 1, - input.length > 2 ? input[2] : 1, - input.length > 3 ? input[3] : 0, - input.length > 4 ? input[4] : 0, - input.length > 5 ? input[5] : 0, - input.length > 6 ? input[6] : 0); - } - } + void _initializeLocale() { + var systemLocale = Intl.getCurrentLocale(); - DateTime _parseString(String input, String? pattern) { - if (pattern != null) { - return DateFormat(replacePatternInput(pattern)) - .parse(replaceParseInput(input)); - } else if (matchHyphenStringDateTime(input)) { - return DateFormat('yyyy-MM-dd').parse(input); - } else if (matchDartStringDateTime(input) || - matchISOStringDateTime(input)) { - return DateTime.parse(input).toLocal(); - } else if (matchSlashStringDateTime(input)) { - return DateFormat('yyyy/MM/dd').parse(input); - } else if (matchBasicStringDateTime().hasMatch(input)) { - return DateFormat('yyyy/MM/dd') - .parse(input.replaceAllMapped(matchBasicStringDateTime(), (match) { - return '${match.group(1)}/${match.group(2)}/${match.group(3)}'; - })); + if (isLocalAvailable(systemLocale)) { + _locale = getLocale(systemLocale); } else { - throw JiffyException( - 'Date time not recognized, a pattern must be passed, e.g. Jiffy("12, Oct", "dd, MMM")') - .cause; + // The locale `systemLocale` is not supported by Jiffy, hence ' + // 'setting a default locale of `en_us` + _locale = EnUsLocale(); } } - static void _initializeLocale() { - var currentLocale = Intl.getCurrentLocale(); - _defaultLocale = getLocale(currentLocale); - _defaultLocale.code = currentLocale.toLowerCase(); - } - - static Future locale([String? locale]) async { - _initializeLocale(); - if (locale != null) { - if (isLocalAvailable(locale)) { - throw JiffyException( - 'The locale "$locale" does not exist in Jiffy, run Jiffy.getAllAvailableLocales() for more locales') - .cause; - } - await initializeDateFormatting(); + /// Returns the locale code for the current locale. + /// + /// The locale code is a string identifier that uniquely identifies a + /// Locale. Examples include "en-US" for English as used in the + /// United States, or "fr-CA" for French as used in Canada. + String get localeCode => _locale.code(); + + /// Returns a [StartOfWeek] enum value indicating the day on which the week + /// starts for the current locale. + /// + /// The start of the week can vary by locale, with some starting on Sunday, + /// and others starting on Monday or another day of the week. + StartOfWeek get localeStartOfWeek => _locale.startOfWeek(); + + /// Sets the locale for this [Jiffy] instance based on the [locale] provided. + /// + /// The [locale] parameter is expected to be a string representation of a + /// supported locale, such as 'en_US' or 'fr_FR'. If the [locale] provided + /// is not supported, a [JiffyException] will be thrown. + /// + /// ```dart + /// await Jiffy().setLocale('en_US'); + /// ``` + /// + /// Throws a [JiffyException] if the [locale] provided is not supported in + /// [Jiffy]. + static Future setLocale(String locale) async { + if (isLocalAvailable(locale)) { Intl.defaultLocale = locale; - _defaultLocale = getLocale(locale); - _defaultLocale.code = locale.toLowerCase(); - } - return Future.value(_defaultLocale); - } - - static List getAllAvailableLocales() { - return getAllLocales(); - } - -// GET - int get millisecond => _dateTime.millisecond; - - int get second => _dateTime.second; - - int get minute => _dateTime.minute; - - int get hour => _dateTime.hour; - - int get date => _dateTime.day; - - int get day { - var weekDays = [1, 2, 3, 4, 5, 6, 7, 1, 2]; - var weekDayIndex = _dateTime.weekday - 1; - - switch (_defaultLocale.startOfWeek()) { - case StartOfWeek.MONDAY: - weekDayIndex += 0; - break; - case StartOfWeek.SUNDAY: - weekDayIndex += 1; - break; - case StartOfWeek.SATURDAY: - weekDayIndex += 2; - break; + await initializeDateFormatting(); + } else { + // todo add github readme locale link to this exception and also + // update the doc comment + throw JiffyException('The locale `$locale` is not supported, ' + 'please check here for a list of supported locales'); } - return weekDays[weekDayIndex]; } - int get daysInMonth => _daysInMonth(_dateTime.year, _dateTime.month); - - int get dayOfYear => int.parse(DateFormat('D').format(_dateTime)); - - int get week => ((dayOfYear - day + 10) / 7).floor(); - - int get month => _dateTime.month; - - int get quarter => int.parse(DateFormat('Q').format(_dateTime)); - - int get year => _dateTime.year; - -// MANIPULATE + /// Returns a new [Jiffy] instance with the same date and time as the + /// original instance. + /// + /// ```dart + /// final originalJiffy = Jiffy(); + /// final newJiffy = originalJiffy.clone(); + /// ``` + /// + /// The returned instance is not tied to the original instance, so + /// modifying the new instance will not affect the original. + Jiffy clone() => Jiffy.parseFromDateTime(dateTime); + + Jiffy _clone(DateTime dateTime) => + Jiffy.parseFromDateTime(_getter.dateTime(dateTime)); + + /// Returns a new [DateTime] instance of the [Jiffy] object. + DateTime get dateTime => _getter.dateTime(_dateTime); + + /// Returns the microsecond ranging from 0 to 999. + int get microsecond => _getter.microsecond(dateTime); + + /// Returns the number of microseconds since epoch time + /// `January 1, 1970, 00:00:00 UTC`. + int get microsecondsSinceEpoch => _getter.microsecondsSinceEpoch(dateTime); + + /// Returns the millisecond ranging from 0 to 999. + int get millisecond => _getter.millisecond(dateTime); + + /// Returns the number of milliseconds since epoch time + /// `January 1, 1970, 00:00:00 UTC`. + int get millisecondsSinceEpoch => _getter.millisecondsSinceEpoch(dateTime); + + /// Returns the second ranging from 0 to 59. + int get second => _getter.second(dateTime); + + /// Returns the minute ranging from 0 to 59. + int get minute => _getter.minute(dateTime); + + /// Returns the hour ranging from 0 to 23. + int get hour => _getter.hour(dateTime); + + /// Returns the date ranging from 1 to 31. + int get date => _getter.date(dateTime); + + /// Returns the day of the week according to the [Locale.startOfWeek()]. + /// + /// The return value is an integer between 1 and 7, where 1 represents the + /// [Locale.startOfWeek()] + /// + /// By default, the day of the week is calculated based on the locale provided + /// during [Jiffy] initialization. If no locale was provided, it uses the + /// default `en_us` locale. + int get dayOfWeek => _getter.dayOfWeek(dateTime, _locale.startOfWeek()); + + /// Returns the number of days in the month. + int get daysInMonth => _getter.daysInMonth(dateTime); + + /// Returns the day of the year of this [Jiffy] instance. + /// + /// The returned value is an integer between 1 and 366, inclusive, where 1 + /// represents January 1st of the year and 366 represents December 31st of a + /// leap year. + int get dayOfYear => _getter.dayOfYear(dateTime); + + /// Returns the week of the year based on the current [Locale]'s start of + /// week. + /// + /// The week of the year ranges from 1 to 53, where week 1 is the first week + /// that has at least [DateTime.daysPerWeek] days in the new year. + /// + /// For example, in the United States, weeks typically start on Sunday. If + /// date and time is a Monday in the second week of the year (For example, + /// 8 days after the start of the year), the method returns 2. On the other + /// hand, in France, weeks typically start on Monday. If date and time is a + /// Sunday in the first week of the year (For example, 6 days after the + /// start of the year), the method returns 1. + int get weekOfYear => _getter.weekOfYear(dateTime, _locale.startOfWeek()); + + /// Returns the month of the year ranging from 1 to 12. + int get month => _getter.month(dateTime); + + /// Returns the quarter on the year ranging from 1 to 4. + int get quarter => _getter.quarterOfYear(dateTime); + + /// Returns the year. + int get year => _getter.year(dateTime); + + /// Adds the provided [duration] to the current [Jiffy] instance's date + /// and time, and returns a new [Jiffy] instance with the updated value. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromList([1997, 9, 23]); + /// final updatedJiffy = jiffy.addDuration(Duration(days: 10)); + /// print(updatedJiffy.yMMMMd); + /// // output: 'October 3, 1997' + /// ``` + Jiffy addDuration(Duration duration) { + final dateTime = _manipulator.addDuration(this.dateTime, duration); + return _clone(dateTime); + } + + /// Adds date and time to the current [Jiffy] instance and returns a + /// new [Jiffy] instance with the result. + /// + /// The [microseconds], [milliseconds], [seconds], [minutes], [hours], + /// [days], [weeks], [months], and [years] arguments allow you to specify + /// additional time to add to the current [Jiffy] instance. These arguments + /// are all optional and default to 0. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parse( + /// '1997-09-23 13:37:00', + /// pattern: 'yyyy-MM-dd HH:mm:ss' + /// ); + /// final nextHour = jiffy.add(hours: 1); + /// print(nextHour.format('yyyy-MM-dd HH:mm:ss')); + /// // output: '1997-09-23 14:37:00' + /// ``` Jiffy add({ - Duration duration = Duration.zero, - int years = 0, - int months = 0, - int weeks = 0, - int days = 0, - int hours = 0, - int minutes = 0, - int seconds = 0, - int milliseconds = 0, int microseconds = 0, + int milliseconds = 0, + int seconds = 0, + int minutes = 0, + int hours = 0, + int days = 0, + int weeks = 0, + int months = 0, + int years = 0, }) { - _dateTime = _dateTime.add(duration); - _dateTime = _dateTime.add(Duration( - days: days + (weeks * 7), - hours: hours, - minutes: minutes, - seconds: seconds, - milliseconds: milliseconds, - microseconds: microseconds, - )); - _dateTime = _addMonths(_dateTime, months); - _dateTime = _addMonths(_dateTime, years * 12); - return clone(); - } - + final dateTime = _manipulator.add(this.dateTime, microseconds, milliseconds, + seconds, minutes, hours, days, weeks, months, years); + return _clone(dateTime); + } + + /// Subtracts the provided [duration] from the current [Jiffy] instance's + /// date and time, and returns a new [Jiffy] instance with the updated value. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromList([1997, 9, 23]); + /// final updatedJiffy = jiffy.subtractDuration(Duration(days: 10)); + /// print(updatedJiffy.yMMMMd); + /// // output: 'September 13, 1997' + /// ``` + Jiffy subtractDuration(Duration duration) { + final dateTime = _manipulator.subtractDuration(this.dateTime, duration); + return _clone(dateTime); + } + + /// Subtracts the date and time from the current [Jiffy] instance and + /// returns a new [Jiffy] instance with the result. + /// + /// The [microseconds], [milliseconds], [seconds], [minutes], [hours], + /// [days], [weeks], [months], and [years] arguments allow you to specify + /// subtractive time to subtract from the current [Jiffy] instance. + /// These arguments are all optional and default to 0. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parse( + /// '1997-09-23 13:37:00', + /// pattern: 'yyyy-MM-dd HH:mm:ss' + /// ); + /// final previousHour = jiffy.subtract(hours: 1); + /// print(previousHour.format('yyyy-MM-dd HH:mm:ss')); + /// // output: '1997-09-23 12:37:00' + /// ``` Jiffy subtract({ - Duration duration = Duration.zero, - int years = 0, - int months = 0, - int weeks = 0, - int days = 0, - int hours = 0, - int minutes = 0, - int seconds = 0, - int milliseconds = 0, int microseconds = 0, + int milliseconds = 0, + int seconds = 0, + int minutes = 0, + int hours = 0, + int days = 0, + int weeks = 0, + int months = 0, + int years = 0, }) { - _dateTime = _dateTime.subtract(duration); - _dateTime = _dateTime.subtract(Duration( - days: days + weeks * 7, - hours: hours, - minutes: minutes, - seconds: seconds, - milliseconds: milliseconds, - microseconds: microseconds, - )); - _dateTime = _addMonths(_dateTime, -months); - _dateTime = _addMonths(_dateTime, -years * 12); - return clone(); - } - - Jiffy startOf(Units units) { - switch (units) { - case Units.MILLISECOND: - _dateTime = DateTime( - _dateTime.year, - _dateTime.month, - _dateTime.day, - _dateTime.hour, - _dateTime.minute, - _dateTime.second, - _dateTime.millisecond); - break; - case Units.SECOND: - _dateTime = DateTime(_dateTime.year, _dateTime.month, _dateTime.day, - _dateTime.hour, _dateTime.minute, _dateTime.second); - break; - case Units.MINUTE: - _dateTime = DateTime(_dateTime.year, _dateTime.month, _dateTime.day, - _dateTime.hour, _dateTime.minute); - break; - case Units.HOUR: - _dateTime = DateTime( - _dateTime.year, _dateTime.month, _dateTime.day, _dateTime.hour); - break; - case Units.DAY: - _dateTime = DateTime(_dateTime.year, _dateTime.month, _dateTime.day); - break; - case Units.WEEK: - var newDate = _dateTime.subtract(Duration(days: day - 1)); - _dateTime = DateTime(newDate.year, newDate.month, newDate.day); - break; - case Units.MONTH: - _dateTime = DateTime(_dateTime.year, _dateTime.month, 1); - break; - case Units.YEAR: - _dateTime = DateTime(_dateTime.year); - break; - } - return clone(); - } - - Jiffy endOf(Units units) { - switch (units) { - case Units.MILLISECOND: - _dateTime = DateTime( - _dateTime.year, - _dateTime.month, - _dateTime.day, - _dateTime.hour, - _dateTime.minute, - _dateTime.second, - _dateTime.millisecond); - break; - case Units.SECOND: - _dateTime = DateTime(_dateTime.year, _dateTime.month, _dateTime.day, - _dateTime.hour, _dateTime.minute, _dateTime.second, 999); - break; - case Units.MINUTE: - _dateTime = DateTime(_dateTime.year, _dateTime.month, _dateTime.day, - _dateTime.hour, _dateTime.minute, 59, 999); - break; - case Units.HOUR: - _dateTime = DateTime(_dateTime.year, _dateTime.month, _dateTime.day, - _dateTime.hour, 59, 59, 999); - break; - case Units.DAY: - _dateTime = DateTime( - _dateTime.year, _dateTime.month, _dateTime.day, 23, 59, 59, 999); - break; - case Units.WEEK: - var newDate = _dateTime.add(Duration(days: DateTime.daysPerWeek - day)); - _dateTime = - DateTime(newDate.year, newDate.month, newDate.day, 23, 59, 59, 999); - break; - case Units.MONTH: - var date = _daysInMonthArray[_dateTime.month]; - if (_isLeapYear(_dateTime.year) && _dateTime.month == 2) { - date = 29; - } - _dateTime = - DateTime(_dateTime.year, _dateTime.month, date, 23, 59, 59, 999); - break; - case Units.YEAR: - _dateTime = DateTime(_dateTime.year, 12, 31, 23, 59, 59, 999); - break; - } - return clone(); - } - - DateTime local() { - return _dateTime = _dateTime.toLocal(); - } - - DateTime utc() { - return _dateTime = _dateTime.toUtc(); - } - - static const _daysInMonthArray = [ - 0, - 31, - 28, - 31, - 30, - 31, - 30, - 31, - 31, - 30, - 31, - 30, - 31 - ]; - - int _daysInMonth(int year, int month) { - var result = _daysInMonthArray[month]; - if (month == 2 && _isLeapYear(year)) result++; - return result; - } - - DateTime _addMonths(DateTime from, int months) { - final r = months % 12; - final q = (months - r) ~/ 12; - var newYear = from.year + q; - var newMonth = from.month + r; - if (newMonth > 12) { - newYear++; - newMonth -= 12; - } - final newDay = min(from.day, _daysInMonth(newYear, newMonth)); - if (from.isUtc) { - return DateTime.utc(newYear, newMonth, newDay, from.hour, from.minute, - from.second, from.millisecond, from.microsecond); - } else { - return DateTime(newYear, newMonth, newDay, from.hour, from.minute, - from.second, from.millisecond, from.microsecond); - } - } - -// DISPLAY - String format([String? pattern]) { - if (pattern == null) return _dateTime.toIso8601String(); - var ordinal = _defaultLocale.ordinal(_dateTime.day); - var escaped = replaceEscapePattern(pattern); - var newPattern = replaceOrdinalDatePattern(escaped, ordinal); - return DateFormat(newPattern).format(_dateTime); - } - - String get E => DateFormat.E().format(_dateTime); - - String get EEEE => DateFormat.EEEE().format(_dateTime); - - String get LLL => DateFormat.LLL().format(_dateTime); - - String get LLLL => DateFormat.LLLL().format(_dateTime); - - String get Md => DateFormat.Md().format(_dateTime); - - String get MEd => DateFormat.MEd().format(_dateTime); - - String get MMM => DateFormat.MMM().format(_dateTime); - - String get MMMd => DateFormat.MMMd().format(_dateTime); - - String get MMMEd => DateFormat.MMMEd().format(_dateTime); - - String get MMMM => DateFormat.MMMM().format(_dateTime); - - String get MMMMd => DateFormat.MMMMd().format(_dateTime); - - String get MMMMEEEEd => DateFormat.MMMMEEEEd().format(_dateTime); - - String get QQQ => DateFormat.QQQ().format(_dateTime); - - String get QQQQ => DateFormat.QQQQ().format(_dateTime); - - String get yM => DateFormat.yM().format(_dateTime); - - String get yMd => DateFormat.yMd().format(_dateTime); - - String get yMEd => DateFormat.yMEd().format(_dateTime); - - String get yMMM => DateFormat.yMMM().format(_dateTime); - - String get yMMMd => DateFormat.yMMMd().format(_dateTime); - - String get yMMMdjm => DateFormat.yMMMd().add_jm().format(_dateTime); - - String get yMMMEd => DateFormat.yMMMEd().format(_dateTime); - - String get yMMMEdjm => DateFormat.yMMMEd().add_jm().format(_dateTime); - - String get yMMMM => DateFormat.yMMMM().format(_dateTime); - - String get yMMMMd => DateFormat.yMMMMd().format(_dateTime); - - String get yMMMMdjm => DateFormat.yMMMMd().add_jm().format(_dateTime); - - String get yMMMMEEEEd => DateFormat.yMMMMEEEEd().format(_dateTime); - - String get yMMMMEEEEdjm => DateFormat.yMMMMEEEEd().add_jm().format(_dateTime); - - String get yQQQ => DateFormat.yQQQ().format(_dateTime); - - String get yQQQQ => DateFormat.yQQQQ().format(_dateTime); - - String get Hm => DateFormat.Hm().format(_dateTime); - - String get Hms => DateFormat.Hms().format(_dateTime); - - String get j => DateFormat.j().format(_dateTime); - - String get jm => DateFormat.jm().format(_dateTime); - - String get jms => DateFormat.jms().format(_dateTime); - - String fromNow() { - return _defaultLocale.getRelativeTime(_dateTime); - } - - String from(var input) { - var dateTime = _parse(input); - return _defaultLocale.getRelativeTime(_dateTime, dateTime); - } - - num diff(var input, [Units units = Units.MILLISECOND, bool asFloat = false]) { - var dateTime = _parse(input); - num diff; - - var dt1 = _dateTime.millisecondsSinceEpoch; - var dt2 = dateTime.millisecondsSinceEpoch; - - switch (units) { - case Units.MILLISECOND: - diff = dt1 - dt2; - break; - case Units.SECOND: - diff = (dt1 - dt2) / Duration.millisecondsPerSecond; - break; - case Units.MINUTE: - diff = (dt1 - dt2) / Duration.millisecondsPerMinute; - break; - case Units.HOUR: - diff = (dt1 - dt2) / Duration.millisecondsPerHour; - break; - case Units.DAY: - diff = (dt1 - dt2) / Duration.millisecondsPerDay; - break; - case Units.WEEK: - diff = ((dt1 - dt2) / Duration.millisecondsPerDay) / 7; - break; - case Units.MONTH: - diff = _monthDiff(_dateTime, dateTime); - break; - case Units.YEAR: - diff = _monthDiff(_dateTime, dateTime) / 12; - break; - } - if (!asFloat) return _absFloor(diff); - return diff; - } - - num _monthDiff(DateTime a, DateTime b) { - var wholeMonthDiff = ((b.year - a.year) * 12) + (b.month - a.month); - var anchor = _addMonths(a, wholeMonthDiff); - var anchor2; - var adjust; - - if (b.millisecondsSinceEpoch - anchor.millisecondsSinceEpoch < 0) { - anchor2 = _addMonths(a, wholeMonthDiff - 1); - adjust = (b.millisecondsSinceEpoch - anchor.millisecondsSinceEpoch) / - (anchor.millisecondsSinceEpoch - anchor2.millisecondsSinceEpoch); - } else { - anchor2 = _addMonths(a, wholeMonthDiff + 1); - adjust = (b.millisecondsSinceEpoch - anchor.millisecondsSinceEpoch) / - (anchor2.millisecondsSinceEpoch - anchor.millisecondsSinceEpoch); - } - return -(wholeMonthDiff + adjust); - } - - int _absFloor(num number) { - if (number < 0) { - return number.ceil(); - } else { - return number.floor(); - } - } - - int valueOf() { - return _dateTime.millisecondsSinceEpoch; - } - - int unix() { - return (_dateTime.millisecondsSinceEpoch / 1000).round(); - } - -// QUERY - bool isBefore(var input, [Units units = Units.MILLISECOND]) { - var dateTime = _parse(input); - if (units == Units.MILLISECOND) { - return valueOf() < dateTime.millisecondsSinceEpoch; - } - var endOfMs = (clone()..endOf(units)).valueOf(); - return endOfMs < dateTime.millisecondsSinceEpoch; - } - - bool isAfter(var input, [Units units = Units.MILLISECOND]) { - var dateTime = _parse(input); - if (units == Units.MILLISECOND) { - return valueOf() > dateTime.millisecondsSinceEpoch; - } - var startOfMs = (clone()..startOf(units)).valueOf(); - return dateTime.millisecondsSinceEpoch < startOfMs; - } - - bool isSame(var input, [Units units = Units.MILLISECOND]) { - var dateTime = _parse(input); - if (units == Units.MILLISECOND) { - return valueOf() == dateTime.millisecondsSinceEpoch; - } - var startOfMs = (clone()..startOf(units)).valueOf(); - var endOfMs = (clone()..endOf(units)).valueOf(); - var dateTimeMs = dateTime.millisecondsSinceEpoch; - return startOfMs <= dateTimeMs && dateTimeMs <= endOfMs; - } - - bool isSameOrBefore(var input, [Units units = Units.MILLISECOND]) { - var dateTime = _parse(input); - return isSame(dateTime, units) || isBefore(dateTime, units); - } - - bool isSameOrAfter(var input, [Units units = Units.MILLISECOND]) { - var dateTime = _parse(input); - return isSame(dateTime, units) || isAfter(dateTime, units); - } - - bool isBetween(var inputFrom, var inputTo, - [Units units = Units.MILLISECOND]) { - var dateTimeFrom = _parse(inputFrom); - var dateTimeTo = _parse(inputTo); - return isAfter(dateTimeFrom, units) && isBefore(dateTimeTo, units); - } - - bool _isLeapYear(int year) => - (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); - - bool get isLeapYear => _isLeapYear(_dateTime.year); - - static bool isJiffy(var input) => input is Jiffy; - - static bool isDateTime(var input) => input is DateTime; + final dateTime = _manipulator.subtract(this.dateTime, microseconds, + milliseconds, seconds, minutes, hours, days, weeks, months, years); + return _clone(dateTime); + } + + /// Returns a new [Jiffy] instance representing the start of the specified + /// [unit] of time + /// + /// [unit] must be one of the values in [Unit] enumeration. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parse( + /// '1997-09-23 13:37:00', + /// pattern: 'yyyy-MM-dd HH:mm:ss' + /// ); + /// final startOfDay = jiffy.startOf(Unit.DAY); + /// print(startOfDay.format('yyyy-MM-dd HH:mm:ss')); + /// // output: '1997-09-23 00:00:00' + /// ``` + Jiffy startOf(Unit unit) { + final dateTime = + _manipulator.startOf(this.dateTime, unit, _locale.startOfWeek()); + return _clone(dateTime); + } + + /// Returns a new [Jiffy] instance representing the end of the specified + /// [unit] of time + /// + /// [unit] must be one of the values in [Unit] enumeration. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parse( + /// '1997-09-23 13:37:00', + /// pattern: 'yyyy-MM-dd HH:mm:ss' + /// ); + /// final startOfDay = jiffy.endOf(Unit.DAY); + /// print(startOfDay.format('yyyy-MM-dd HH:mm:ss'); + /// // output: '1997-09-23 23:59:59' + /// ``` + Jiffy endOf(Unit unit) { + final dateTime = + _manipulator.endOf(this.dateTime, unit, _locale.startOfWeek()); + return _clone(dateTime); + } + + /// Returns a new instance of [Jiffy] with the same date and time in + /// local time zone. + /// + /// If the current [Jiffy] instance is in UTC time zone, the date and time + /// will be converted to local time zone. Otherwise, the current instance + /// will be returned as is. + Jiffy toLocal() { + final dateTime = Query.isUtc(this.dateTime) + ? _manipulator.toLocal(this.dateTime) + : this.dateTime; + return _clone(dateTime); + } + + /// Returns a new instance of [Jiffy] with the same date and time in + /// UTC time zone. + /// + /// If the current [Jiffy] instance is in local time zone, the date and time + /// will be converted to UTC time zone. Otherwise, the current instance + /// will be returned as is. + Jiffy toUtc() { + final dateTime = Query.isUtc(this.dateTime) + ? this.dateTime + : _manipulator.toUtc(this.dateTime); + return _clone(dateTime); + } + + /// Returns the formatted date and time string based on the provided + /// [pattern]. If the [pattern] is not provided, the method will return + /// the formatted date and time string in the ISO-8601 format. + /// + /// Example: + /// + /// ```dart + /// // Formats the date and time in "dd MMM yyyy" format + /// final jiffy = Jiffy.parseFromList([1997, 9, 23, 11, 30, 22, 123, 456]); + /// final formattedDate = jiffy.format(pattern: 'dd MMM yyyy'); + /// print(formattedDate); + /// // output: '23 Sep 1997' + /// + /// // Formats the date and time in ISO8601 format + /// final jiffy = Jiffy.parseFromList([1997, 9, 23, 11, 30, 22, 123, 456]); + /// final formattedDate = jiffy.format(); // No pattern passed + /// print(formattedDate); + /// // output: '1997-09-23T11:30:22.123456' + /// ``` + String format({String? pattern}) { + return pattern == null + ? _display.formatToISO8601(dateTime) + : _display.format(dateTime, pattern, _locale); + } + + /// Returns the abbreviated weekday. Example: `Tue` + String get E => _defaultDisplay.E(dateTime); + + /// Returns the weekday. Example: `Tuesday` + // ignore: non_constant_identifier_names + String get EEEE => _defaultDisplay.EEEE(dateTime); + + /// Returns the day of month and date. Example: `9/23` + // ignore: non_constant_identifier_names + String get Md => _defaultDisplay.Md(dateTime); + + /// Returns the day of month, abbreviated weekday and date. + /// Example: `Tue, 9/23` + // ignore: non_constant_identifier_names + String get MEd => _defaultDisplay.MEd(dateTime); + + /// Returns the abbreviated month. Example: `Sep` + // ignore: non_constant_identifier_names + String get MMM => _defaultDisplay.MMM(dateTime); + + /// Returns the abbreviated month and date. Example: `Sep 23` + // ignore: non_constant_identifier_names + String get MMMd => _defaultDisplay.MMMd(dateTime); + + /// Returns the abbreviated month, abbreviated weekday and date. + /// Example: `Tue, Sep 23` + // ignore: non_constant_identifier_names + String get MMMEd => _defaultDisplay.MMMEd(dateTime); + + /// Returns the month. Example: `September` + // ignore: non_constant_identifier_names + String get MMMM => _defaultDisplay.MMMM(dateTime); + + /// Returns the month and date. Example: `September 23` + // ignore: non_constant_identifier_names + String get MMMMd => _defaultDisplay.MMMMd(dateTime); + + /// Returns the month, weekday and date. Example: `Tuesday, September 23` + // ignore: non_constant_identifier_names + String get MMMMEEEEd => _defaultDisplay.MMMMEEEEd(dateTime); + + /// Returns the abbreviated quarter. Example: `Q3` + // ignore: non_constant_identifier_names + String get QQQ => _defaultDisplay.QQQ(dateTime); + + /// Returns the quarter. Example: `3rd quarter` + // ignore: non_constant_identifier_names + String get QQQQ => _defaultDisplay.QQQQ(dateTime); + + /// Returns the year and day of month. Example: `9/1997` + String get yM => _defaultDisplay.yM(dateTime); + + /// Returns the year, of month and date. Example: `9/23/1997` + String get yMd => _defaultDisplay.yMd(dateTime); + + /// Returns the year, of month, abbreviated weekday and date. + /// Example: `Tue, 9/23/1997` + String get yMEd => _defaultDisplay.yMEd(dateTime); + + /// Returns the year and abbreviated month. Example: `Sep 1997` + String get yMMM => _defaultDisplay.yMMM(dateTime); + + /// Returns the year and abbreviated month. Example: `Sep 23, 1997` + String get yMMMd => _defaultDisplay.yMMMd(dateTime); + + /// Returns the year, abbreviated month, date, hour and minute. + /// Example: `Sep 23, 1997 12:11 PM` + String get yMMMdjm => _defaultDisplay.yMMMdjm(dateTime); + + /// Returns the year, abbreviated month, abbreviated weekday and date. + /// Example: `Tue, Sep 23, 1997` + String get yMMMEd => _defaultDisplay.yMMMEd(dateTime); + + /// Returns the year, abbreviated month, abbreviated weekday, date, hour + /// and minute. Example: `Tue, Sep 23, 1997 12:11 PM` + String get yMMMEdjm => _defaultDisplay.yMMMEdjm(dateTime); + + /// Returns the year and month. Example: `September 1997` + String get yMMMM => _defaultDisplay.yMMMM(dateTime); + + /// Returns the year, month and date. Example: `September 23, 1997` + String get yMMMMd => _defaultDisplay.yMMMMd(dateTime); + + /// Returns the year, month, date, hour and minute. + /// Example: `September 23, 1997 12:11 PM` + String get yMMMMdjm => _defaultDisplay.yMMMMdjm(dateTime); + + /// Returns the year, month, weekday and date. + /// Example: `Tuesday, September 23, 1997` + String get yMMMMEEEEd => _defaultDisplay.yMMMMEEEEd(dateTime); + + /// Returns the year, month, weekday, date, hour and minute. + /// Example: `Tuesday, September 23, 1997 12:11 PM` + String get yMMMMEEEEdjm => _defaultDisplay.yMMMMEEEEdjm(dateTime); + + /// Returns the year and abbreviated quarter. Example: `Q3 1997` + String get yQQQ => _defaultDisplay.yQQQ(dateTime); + + /// Returns the year and quarter. Example: `3rd quarter 1997` + String get yQQQQ => _defaultDisplay.yQQQQ(dateTime); + + /// Returns 24 hour and minute. Example: `12` + String get H => _defaultDisplay.H(dateTime); + + /// Returns 24 hour and minute. Example: `12:11` + // ignore: non_constant_identifier_names + String get Hm => _defaultDisplay.Hm(dateTime); + + /// Returns 24 hour, minute and second. Example: `12:11:22` + // ignore: non_constant_identifier_names + String get Hms => _defaultDisplay.Hms(dateTime); + + /// Returns 12 hour. Example: `12 PM` + String get j => _defaultDisplay.j(dateTime); + + /// Returns 12 hour and minute. Example: `12:11 PM` + String get jm => _defaultDisplay.jm(dateTime); + + /// Returns 12 hour, minute and seconds. Example: `12:11:22 PM` + String get jms => _defaultDisplay.jms(dateTime); + + /// Returns a string representation of current [Jiffy]'s instance relative + /// from [jiffy]'s date and time. + /// + /// Example: + /// + /// ```dart + /// final jiffy1 = Jiffy.parseFromDateTime(DateTime(2023, 1, 1)); + /// final jiffy2 = Jiffy.parseFromDateTime(DateTime(2023, 2, 1)); + /// print(jiffy1.from(jiffy2)); + /// // output: a month ago + /// ``` + String from(Jiffy jiffy) { + return _display.fromAsRelativeDateTime(dateTime, jiffy.dateTime, _locale); + } + + /// Returns a string representation of current [Jiffy]'s instance relative + /// from current date and time. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromDateTime(DateTime(2023, 1, 1)); + /// print(jiffy.fromNow()); + /// // output: a month ago + /// ``` + String fromNow() => from(Jiffy.now()); + + /// Returns a string representation of current [Jiffy]'s instance relative + /// to [jiffy]'s date and time. + /// + /// Example: + /// + /// ```dart + /// final jiffy1 = Jiffy.parseFromDateTime(DateTime(2023, 1, 1)); + /// final jiffy2 = Jiffy.parseFromDateTime(DateTime(2023, 2, 1)); + /// print(jiffy1.to(jiffy2)); + /// // output: in a month + /// ``` + String to(Jiffy jiffy) { + return _display.toAsRelativeDateTime(dateTime, jiffy.dateTime, _locale); + } + + /// Returns a string representation of current [Jiffy]'s instance relative + /// to current date and time. + /// + /// Example: + /// + /// ```dart + /// final jiffy = Jiffy.parseFromDateTime(DateTime(2023, 1, 1)); + /// print(jiffy.toNow()); + /// // output: in a month + /// ``` + String toNow() => to(Jiffy.now()); + + /// Returns the difference between this [Jiffy] instance and the given + /// [jiffy] instance as a numeric value. + /// + /// The [unit] parameter specifies the unit in which to return the difference. + /// The default value is [Unit.microsecond]. + /// + /// The optional [asFloat] parameter determines whether to return the + /// difference as a floating-point number. The default value is [false]. + /// + /// Example: + /// + /// ```dart + /// final jiffy1 = Jiffy(DateTime(2022, 2, 1, 0, 0, 0)); + /// final jiffy2 = Jiffy(DateTime(2022, 2, 15, 12, 30, 0)); + /// + /// // Calculate the difference between the two Jiffy instances in days + /// final diffInDays = jiffy1.diff(jiffy2, unit: Unit.DAY); + /// + /// print('Difference in days: $diffInDays'); + /// // output: Difference in days: -14 + /// ``` + num diff(Jiffy jiffy, {Unit unit = Unit.microsecond, bool asFloat = true}) { + return _display.diff(dateTime, jiffy.dateTime, unit, asFloat); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance is + /// before the given [jiffy] instance. + /// + /// The [unit] parameter specifies the unit of measurement to use when + /// comparing the two instances. The default value is [Unit.microsecond]. + bool isBefore(Jiffy jiffy, {Unit unit = Unit.microsecond}) { + return _query.isBefore( + dateTime, jiffy.dateTime, unit, _locale.startOfWeek()); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance is + /// after the given [jiffy] instance. + /// + /// The [unit] parameter specifies the unit of measurement to use when + /// comparing the two instances. The default value is [Unit.microsecond]. + bool isAfter(Jiffy jiffy, {Unit unit = Unit.microsecond}) { + return _query.isAfter( + dateTime, jiffy.dateTime, unit, _locale.startOfWeek()); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance is + /// the same as the given [jiffy] instance. + /// + /// The [unit] parameter specifies the unit of measurement to use when + /// comparing the two instances. The default value is [Unit.microsecond]. + bool isSame(Jiffy jiffy, {Unit unit = Unit.microsecond}) { + return _query.isSame(dateTime, jiffy.dateTime, unit, _locale.startOfWeek()); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance is + /// the same as or before the given [jiffy] instance. + /// + /// The [unit] parameter specifies the unit of measurement to use when + /// comparing the two instances. The default value is [Unit.microsecond]. + bool isSameOrBefore(Jiffy jiffy, {Unit unit = Unit.microsecond}) { + return _query.isSameOrBefore( + dateTime, jiffy.dateTime, unit, _locale.startOfWeek()); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance is + /// the same as or after the given [jiffy] instance. + /// + /// The [unit] parameter specifies the unit of measurement to use when + /// comparing the two instances. The default value is [Unit.microsecond]. + bool isSameOrAfter(Jiffy jiffy, {Unit unit = Unit.microsecond}) { + return _query.isSameOrAfter( + dateTime, jiffy.dateTime, unit, _locale.startOfWeek()); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance is + /// between the two given [jiffyFrom] and [jiffyTo] instances. + /// + /// The [unit] parameter specifies the unit of measurement to use when + /// comparing the three instances. The default value is [Unit.microsecond]. + bool isBetween(Jiffy jiffyFrom, Jiffy jiffyTo, + {Unit unit = Unit.microsecond}) { + return _query.isBetween(dateTime, jiffyFrom.dateTime, jiffyTo.dateTime, + unit, _locale.startOfWeek()); + } + + /// Returns a boolean value indicating whether this [Jiffy] instance + /// represents a local date and time. + bool get isLocal => !isUtc; + + /// Returns a boolean value indicating whether this [Jiffy] instance + /// represents a UTC date and time. + bool get isUtc => Query.isUtc(dateTime); + + /// Returns a boolean value indicating whether the [Jiffy] instance + /// provided falls on a leap year. + bool get isLeapYear => Query.isLeapYear(dateTime.year); + + @override + bool operator ==(Object other) { + if (other is Jiffy) return dateTime == other.dateTime; + return false; + } + + @override + int get hashCode => dateTime.hashCode; } diff --git a/lib/src/locale/availableLocales.dart b/lib/src/locale/availableLocales.dart deleted file mode 100644 index 8ab1a96..0000000 --- a/lib/src/locale/availableLocales.dart +++ /dev/null @@ -1,91 +0,0 @@ -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/locale/arLocale.dart'; -import 'package:jiffy/src/locale/deLocale.dart'; -import 'package:jiffy/src/locale/enLocale.dart'; -import 'package:jiffy/src/locale/esLocale.dart'; -import 'package:jiffy/src/locale/faLocale.dart'; -import 'package:jiffy/src/locale/frLocale.dart'; -import 'package:jiffy/src/locale/hiLocale.dart'; -import 'package:jiffy/src/locale/idLocale.dart'; -import 'package:jiffy/src/locale/itLocale.dart'; -import 'package:jiffy/src/locale/jaLocale.dart'; -import 'package:jiffy/src/locale/koLocale.dart'; -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/nbLocale.dart'; -import 'package:jiffy/src/locale/nlLocale.dart'; -import 'package:jiffy/src/locale/plLocale.dart'; -import 'package:jiffy/src/locale/ptLocale.dart'; -import 'package:jiffy/src/locale/ruLocale.dart'; -import 'package:jiffy/src/locale/thLocale.dart'; -import 'package:jiffy/src/locale/ukLocale.dart'; -import 'package:jiffy/src/locale/azLocale.dart'; -import 'package:jiffy/src/locale/svLocale.dart'; -import 'package:jiffy/src/locale/trLocale.dart'; -import 'package:jiffy/src/locale/zhCnLocale.dart'; -import 'package:jiffy/src/locale/zhLocale.dart'; -import 'package:jiffy/src/locale/bnLocale.dart'; - -Map _availableLocales = { - 'en': EnLocale(StartOfWeek.SUNDAY), - 'en_us': EnLocale(StartOfWeek.SUNDAY), - 'en_sg': EnLocale(StartOfWeek.SUNDAY), - 'en_au': EnLocale(StartOfWeek.SUNDAY), - 'en_ca': EnLocale(StartOfWeek.SUNDAY), - 'en_gb': EnLocale(StartOfWeek.MONDAY), - 'en_ie': EnLocale(StartOfWeek.MONDAY), - 'en_il': EnLocale(StartOfWeek.SUNDAY), - 'en_nz': EnLocale(StartOfWeek.SUNDAY), - 'es': EsLocale(StartOfWeek.MONDAY), - 'es_do': EsLocale(StartOfWeek.MONDAY), - 'es_us': EsLocale(StartOfWeek.SUNDAY), - 'fr': FrLocale(StartOfWeek.MONDAY), - 'fr_ch': FrLocale(StartOfWeek.MONDAY), - 'fr_ca': FrLocale(StartOfWeek.SUNDAY), - 'zh': ZhCnLocale(StartOfWeek.SUNDAY), - 'zh_cn': ZhCnLocale(StartOfWeek.SUNDAY), - 'zh_hk': ZhLocale(StartOfWeek.SUNDAY), - 'zh_tw': ZhLocale(StartOfWeek.SUNDAY), - 'de': DeLocale(StartOfWeek.MONDAY), - 'de_de': DeLocale(StartOfWeek.MONDAY), - 'de_at': DeLocale(StartOfWeek.MONDAY), - 'de_ch': DeLocale(StartOfWeek.MONDAY), - 'it': ItLocale(StartOfWeek.MONDAY), - 'it_ch': ItLocale(StartOfWeek.MONDAY), - 'ar': ArLyLocale(true, StartOfWeek.SATURDAY), - 'ar_ly': ArLyLocale(false, StartOfWeek.SATURDAY), - 'ar_dz': ArSaMaDzKwTnLocale(false, StartOfWeek.SUNDAY), - 'ar_kw': ArSaMaDzKwTnLocale(false, StartOfWeek.SUNDAY), - 'ar_sa': ArSaMaDzKwTnLocale(true, StartOfWeek.SUNDAY), - 'ar_ma': ArSaMaDzKwTnLocale(false, StartOfWeek.SATURDAY), - 'ar_tn': ArSaMaDzKwTnLocale(false, StartOfWeek.SATURDAY), - 'az': AzLocale(StartOfWeek.MONDAY), - 'id': IdLocale(StartOfWeek.SUNDAY), - 'ja': JaLocale(StartOfWeek.SUNDAY), - 'ko': KoLocale(StartOfWeek.SUNDAY), - 'ru': RuLocale(StartOfWeek.MONDAY), - 'uk': UkLocale(StartOfWeek.MONDAY), - 'hi': HiLocale(StartOfWeek.SUNDAY), - 'pt': PtLocale(StartOfWeek.MONDAY), - 'pt_br': PtLocale(StartOfWeek.SUNDAY), - 'pl': PlLocale(StartOfWeek.MONDAY), - 'tr': TrLocale(StartOfWeek.MONDAY), - 'sv': SvLocale(StartOfWeek.MONDAY), - 'nb': NbLocale(StartOfWeek.MONDAY), - 'fa': FaLocale(true, StartOfWeek.SATURDAY), - 'bn': BnLocale(StartOfWeek.SUNDAY), - 'nl': NlLocale(StartOfWeek.MONDAY), - 'th': ThLocale(StartOfWeek.SUNDAY) -}; - -Locale getLocale(String locale) { - return _availableLocales[locale.toLowerCase()] ?? - EnLocale(StartOfWeek.SUNDAY); -} - -bool isLocalAvailable(String locale) { - return !_availableLocales.containsKey(locale.toLowerCase()); -} - -List getAllLocales() { - return _availableLocales.keys.toList(); -} diff --git a/lib/src/locale/available_locales.dart b/lib/src/locale/available_locales.dart new file mode 100644 index 0000000..0c4cfcf --- /dev/null +++ b/lib/src/locale/available_locales.dart @@ -0,0 +1,87 @@ +import 'locale.dart'; +import 'locales/ar_locale.dart'; +import 'locales/de_locale.dart'; +import 'locales/en_locale.dart'; +import 'locales/es_locale.dart'; +import 'locales/fa_locale.dart'; +import 'locales/fr_locale.dart'; +import 'locales/hi_locale.dart'; +import 'locales/hu_locale.dart'; +import 'locales/id_locale.dart'; +import 'locales/it_locale.dart'; +import 'locales/ja_locale.dart'; +import 'locales/ko_locale.dart'; +import 'locales/nb_locale.dart'; +import 'locales/nl_locale.dart'; +import 'locales/pl_locale.dart'; +import 'locales/pt_locale.dart'; +import 'locales/ru_locale.dart'; +import 'locales/th_locale.dart'; +import 'locales/uk_locale.dart'; +import 'locales/az_locale.dart'; +import 'locales/sv_locale.dart'; +import 'locales/tr_locale.dart'; +import 'locales/zh_locale.dart'; +import 'locales/bn_locale.dart'; + +Map _availableLocales = { + 'en': EnLocale(), + 'en_us': EnUsLocale(), + 'en_sg': EnSgLocale(), + 'en_au': EnAuLocale(), + 'en_ca': EnCaLocale(), + 'en_gb': EnGbLocale(), + 'en_ie': EnIeLocale(), + 'en_il': EnIlLocale(), + 'en_nz': EnNzLocale(), + 'es': EsLocale(), + 'es_do': EsDoLocale(), + 'es_us': EsUsLocale(), + 'fr': FrLocale(), + 'fr_ch': FrChLocale(), + 'fr_ca': FrCaLocale(), + 'zh': ZhLocale(), + 'zh_cn': ZhCnLocale(), + 'zh_hk': ZhHkLocale(), + 'zh_tw': ZhTwLocale(), + 'de': DeLocale(), + 'de_de': DeDeLocale(), + 'de_at': DeAtLocale(), + 'de_ch': DeChLocale(), + 'it': ItLocale(), + 'it_ch': ItChLocale(), + 'ar': ArLocale(), + 'ar_ly': ArLyLocale(), + 'ar_dz': ArDzLocale(), + 'ar_kw': ArKwLocale(), + 'ar_sa': ArSaLocale(), + 'ar_ma': ArMaLocale(), + 'ar_tn': ArTnLocale(), + 'az': AzLocale(), + 'id': IdLocale(), + 'ja': JaLocale(), + 'ko': KoLocale(), + 'ru': RuLocale(), + 'uk': UkLocale(), + 'hi': HiLocale(), + 'hu': HuLocale(), + 'hu_hu': HuHuLocale(), + 'pt': PtLocale(), + 'pt_br': PtBrLocale(), + 'pl': PlLocale(), + 'tr': TrLocale(), + 'sv': SvLocale(), + 'nb': NbLocale(), + 'fa': FaLocale(), + 'bn': BnLocale(), + 'nl': NlLocale(), + 'th': ThLocale() +}; + +Locale getLocale(String locale) { + return _availableLocales[locale.toLowerCase()] ?? _availableLocales['en_us']!; +} + +bool isLocalAvailable(String locale) { + return _availableLocales.containsKey(locale.toLowerCase()); +} diff --git a/lib/src/locale/enLocale.dart b/lib/src/locale/enLocale.dart deleted file mode 100644 index 4c10a32..0000000 --- a/lib/src/locale/enLocale.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; - -class EnLocale extends Locale { - StartOfWeek strtOfWeek; - EnLocale(this.strtOfWeek); - - @override - RelativeTime relativeTime() => EnRelativeTime(); - - @override - List? ordinals() => ['st', 'nd', 'rd', 'th']; - - @override - StartOfWeek startOfWeek() => strtOfWeek; -} - -class EnRelativeTime extends RelativeTime { - @override - String prefixAgo() => ''; - @override - String prefixFromNow() => 'in'; - @override - String suffixAgo() => 'ago'; - @override - String suffixFromNow() => ''; - @override - String lessThanOneMinute(int seconds) => 'a few seconds'; - @override - String aboutAMinute(int minutes) => 'a minute'; - @override - String minutes(int minutes) => '$minutes minutes'; - @override - String aboutAnHour(int minutes) => 'an hour'; - @override - String hours(int hours) => '$hours hours'; - @override - String aDay(int hours) => 'a day'; - @override - String days(int days) => '$days days'; - @override - String aboutAMonth(int days) => 'a month'; - @override - String months(int months) => '$months months'; - @override - String aboutAYear(int year) => 'a year'; - @override - String years(int years) => '$years years'; - @override - String wordSeparator() => ' '; -} diff --git a/lib/src/locale/locale.dart b/lib/src/locale/locale.dart index 7adc3db..6cd3843 100644 --- a/lib/src/locale/locale.dart +++ b/lib/src/locale/locale.dart @@ -1,77 +1,28 @@ -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; +import '../enums/start_of_week.dart'; +import 'relative_date_time.dart'; +/// An abstract class representing a Locale in Dart. abstract class Locale { - late String code; - - // If a locale does not have ordinals return null - List? ordinals(); - - RelativeTime relativeTime(); - + /// Returns the locale code for this locale. + /// + /// The locale code is a string identifier that uniquely identifies a + /// Locale. Examples include "en-US" for English as used in the + /// United States, or "fr-CA" for French as used in Canada. + String code(); + + /// Returns a list of ordinal suffixes for this locale. + /// + /// Ordinal suffixes are used to format the ordinal number of a day + /// (For example, "st", "nd", "rd", "th"). + List ordinals(); + + /// Returns the day on which the week starts for this locale. StartOfWeek startOfWeek(); - String getRelativeTime(DateTime date1, [DateTime? date2]) { - final relative = relativeTime(); - final _date2 = date2 ?? DateTime.now(); - final _allowFromNow = _date2.isBefore(date1); - var elapsed = _date2.millisecondsSinceEpoch - date1.millisecondsSinceEpoch; - - String prefix, suffix; - - if (_allowFromNow && elapsed < 0) { - elapsed = date1.isBefore(_date2) ? elapsed : elapsed.abs(); - prefix = relative.prefixFromNow(); - suffix = relative.suffixFromNow(); - } else { - prefix = relative.prefixAgo(); - suffix = relative.suffixAgo(); - } - - final num seconds = elapsed / 1000; - final num minutes = seconds / 60; - final num hours = minutes / 60; - final num days = hours / 24; - final num months = days / 30; - final num years = days / 365; - - String result; - if (seconds < 45) { - result = relative.lessThanOneMinute(seconds.round()); - } else if (seconds < 90) { - result = relative.aboutAMinute(minutes.round()); - } else if (minutes < 45) { - result = relative.minutes(minutes.round()); - } else if (minutes < 90) { - result = relative.aboutAnHour(minutes.round()); - } else if (hours < 24) { - result = relative.hours(hours.round()); - } else if (hours < 48) { - result = relative.aDay(hours.round()); - } else if (days < 30) { - result = relative.days(days.round()); - } else if (days < 60) { - result = relative.aboutAMonth(days.round()); - } else if (days < 365) { - result = relative.months(months.round()); - } else if (years < 2) { - result = relative.aboutAYear(months.round()); - } else { - result = relative.years(years.round()); - } - - return [prefix, result, suffix] - .where((str) => str.isNotEmpty) - .join(relative.wordSeparator()); - } - - String ordinal(int day) { - if (ordinals() == null) return ''; - var suffix = ordinals()!.last; - var digit = day % 10; - if ((digit > 0 && digit < 4) && (day < 11 || day > 13)) { - suffix = ordinals()![digit - 1]; - } - return suffix; - } + /// Returns a [RelativeDateTime] instance for this locale. + /// + /// A [RelativeDateTime] instance encapsulates the rules for formatting + /// relative date/time values (For example, "3 hours ago", "in 2 days") for + /// a specific locale. + RelativeDateTime relativeDateTime(); } diff --git a/lib/src/locale/arLocale.dart b/lib/src/locale/locales/ar_locale.dart similarity index 70% rename from lib/src/locale/arLocale.dart rename to lib/src/locale/locales/ar_locale.dart index 1c6b77f..364af8b 100644 --- a/lib/src/locale/arLocale.dart +++ b/lib/src/locale/locales/ar_locale.dart @@ -1,41 +1,88 @@ -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/utils/replace.dart'; +import '../../enums/start_of_week.dart'; +import '../../utils/replace.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; -class ArLyLocale extends Locale { - bool replaceNum; - StartOfWeek strtOfWeek; - ArLyLocale(this.replaceNum, this.strtOfWeek); +class ArLocale extends Locale { + @override + String code() => 'ar'; @override - RelativeTime relativeTime() => ArLyRelativeTime(replaceNum); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.saturday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => ArRelativeTime(true); } -class ArSaMaDzKwTnLocale extends Locale { - bool replaceNum; - StartOfWeek strtOfWeek; - ArSaMaDzKwTnLocale(this.replaceNum, this.strtOfWeek); +class ArLyLocale extends ArLocale { + @override + String code() => 'ar_ly'; + + @override + RelativeDateTime relativeDateTime() => ArRelativeTime(false); +} + +class ArDzLocale extends ArLocale { + @override + String code() => 'ar_dz'; + + @override + StartOfWeek startOfWeek() => StartOfWeek.sunday; + + @override + RelativeDateTime relativeDateTime() => ArSaMaDzKwTnRelativeTime(false); +} + +class ArKwLocale extends ArLocale { + @override + String code() => 'ar_kw'; + + @override + StartOfWeek startOfWeek() => StartOfWeek.sunday; + + @override + RelativeDateTime relativeDateTime() => ArSaMaDzKwTnRelativeTime(false); +} + +class ArSaLocale extends ArLocale { + @override + String code() => 'ar_sa'; + + @override + StartOfWeek startOfWeek() => StartOfWeek.sunday; + + @override + RelativeDateTime relativeDateTime() => ArSaMaDzKwTnRelativeTime(true); +} + +class ArMaLocale extends ArLocale { + @override + String code() => 'ar_ma'; + + @override + StartOfWeek startOfWeek() => StartOfWeek.saturday; + + @override + RelativeDateTime relativeDateTime() => ArSaMaDzKwTnRelativeTime(false); +} +class ArTnLocale extends ArLocale { @override - RelativeTime relativeTime() => ArSaMaDzKwTnRelativeTime(replaceNum); + String code() => 'ar_tn'; @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.saturday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => ArSaMaDzKwTnRelativeTime(false); } -class ArLyRelativeTime extends RelativeTime { +class ArRelativeTime extends RelativeDateTime { bool replaceNum; - ArLyRelativeTime(this.replaceNum); + ArRelativeTime(this.replaceNum); @override String prefixAgo() => 'منذ'; @@ -146,7 +193,7 @@ class ArLyRelativeTime extends RelativeTime { String wordSeparator() => ' '; } -class ArSaMaDzKwTnRelativeTime extends RelativeTime { +class ArSaMaDzKwTnRelativeTime extends RelativeDateTime { bool replaceNum; ArSaMaDzKwTnRelativeTime(this.replaceNum); diff --git a/lib/src/locale/azLocale.dart b/lib/src/locale/locales/az_locale.dart similarity index 84% rename from lib/src/locale/azLocale.dart rename to lib/src/locale/locales/az_locale.dart index 509b55c..0196f42 100644 --- a/lib/src/locale/azLocale.dart +++ b/lib/src/locale/locales/az_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class AzLocale extends Locale { - StartOfWeek strtOfWeek; - AzLocale(this.strtOfWeek); + @override + String code() => 'az'; @override - RelativeTime relativeTime() => AzRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => AzRelativeTime(); } -class AzRelativeTime extends RelativeTime { +class AzRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/bnLocale.dart b/lib/src/locale/locales/bn_locale.dart similarity index 73% rename from lib/src/locale/bnLocale.dart rename to lib/src/locale/locales/bn_locale.dart index f7472e9..803dc79 100644 --- a/lib/src/locale/bnLocale.dart +++ b/lib/src/locale/locales/bn_locale.dart @@ -1,23 +1,23 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/utils/replace.dart'; +import '../../enums/start_of_week.dart'; +import '../../utils/replace.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class BnLocale extends Locale { - StartOfWeek strtOfWeek; - BnLocale(this.strtOfWeek); + @override + String code() => 'bn'; @override - RelativeTime relativeTime() => BnRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.sunday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => BnRelativeTime(); } -class BnRelativeTime extends RelativeTime { +class BnRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/deLocale.dart b/lib/src/locale/locales/de_locale.dart similarity index 61% rename from lib/src/locale/deLocale.dart rename to lib/src/locale/locales/de_locale.dart index ab8cc2b..9a9f807 100644 --- a/lib/src/locale/deLocale.dart +++ b/lib/src/locale/locales/de_locale.dart @@ -1,22 +1,37 @@ -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class DeLocale extends Locale { - StartOfWeek strtOfWeek; - DeLocale(this.strtOfWeek); + @override + String code() => 'de'; + + @override + List ordinals() => List.from(['.', '.', '.', '.'], growable: false); + + @override + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - RelativeTime relativeTime() => DeRelativeTime(); + RelativeDateTime relativeDateTime() => DeRelativeTime(); +} +class DeDeLocale extends DeLocale { @override - List? ordinals() => ['.', '.', '.', '.']; + String code() => 'de_de'; +} + +class DeAtLocale extends DeLocale { + @override + String code() => 'de_at'; +} +class DeChLocale extends DeLocale { @override - StartOfWeek startOfWeek() => strtOfWeek; + String code() => 'de_ch'; } -class DeRelativeTime extends RelativeTime { +class DeRelativeTime extends RelativeDateTime { @override String prefixAgo() => 'vor'; @override diff --git a/lib/src/locale/locales/en_locale.dart b/lib/src/locale/locales/en_locale.dart new file mode 100644 index 0000000..a89ecc7 --- /dev/null +++ b/lib/src/locale/locales/en_locale.dart @@ -0,0 +1,99 @@ +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; + +class EnLocale extends Locale { + @override + String code() => 'en'; + + @override + List ordinals() => + List.from(['st', 'nd', 'rd', 'th'], growable: false); + + @override + StartOfWeek startOfWeek() => StartOfWeek.sunday; + + @override + RelativeDateTime relativeDateTime() => EnRelativeTime(); +} + +class EnUsLocale extends EnLocale { + @override + String code() => 'en_us'; +} + +class EnSgLocale extends EnLocale { + @override + String code() => 'en_sg'; +} + +class EnAuLocale extends EnLocale { + @override + String code() => 'en_au'; +} + +class EnCaLocale extends EnLocale { + @override + String code() => 'en_ca'; +} + +class EnGbLocale extends EnLocale { + @override + String code() => 'en_gb'; + + @override + StartOfWeek startOfWeek() => StartOfWeek.monday; +} + +class EnIeLocale extends EnLocale { + @override + String code() => 'en_ie'; + + @override + StartOfWeek startOfWeek() => StartOfWeek.monday; +} + +class EnIlLocale extends EnLocale { + @override + String code() => 'en_il'; +} + +class EnNzLocale extends EnLocale { + @override + String code() => 'en_nz'; +} + +class EnRelativeTime extends RelativeDateTime { + @override + String prefixAgo() => ''; + @override + String prefixFromNow() => 'in'; + @override + String suffixAgo() => 'ago'; + @override + String suffixFromNow() => ''; + @override + String lessThanOneMinute(int seconds) => 'a few seconds'; + @override + String aboutAMinute(int minutes) => 'a minute'; + @override + String minutes(int minutes) => '$minutes minutes'; + @override + String aboutAnHour(int minutes) => 'an hour'; + @override + String hours(int hours) => '$hours hours'; + @override + String aDay(int hours) => 'a day'; + @override + String days(int days) => '$days days'; + @override + String aboutAMonth(int days) => 'a month'; + @override + String months(int months) => '$months months'; + @override + String aboutAYear(int year) => 'a year'; + @override + String years(int years) => '$years years'; + @override + String wordSeparator() => ' '; +} diff --git a/lib/src/locale/esLocale.dart b/lib/src/locale/locales/es_locale.dart similarity index 61% rename from lib/src/locale/esLocale.dart rename to lib/src/locale/locales/es_locale.dart index c05eb22..4b14a10 100644 --- a/lib/src/locale/esLocale.dart +++ b/lib/src/locale/locales/es_locale.dart @@ -1,22 +1,35 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class EsLocale extends Locale { - StartOfWeek strtOfWeek; - EsLocale(this.strtOfWeek); + @override + String code() => 'es'; + + @override + List ordinals() => List.from(['º', 'º', 'º', 'º'], growable: false); + + @override + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - RelativeTime relativeTime() => EsRelativeTime(); + RelativeDateTime relativeDateTime() => EsRelativeTime(); +} + +class EsDoLocale extends EsLocale { + @override + String code() => 'es_do'; +} +class EsUsLocale extends EsLocale { @override - List? ordinals() => ['º', 'º', 'º', 'º']; + String code() => 'es_us'; @override - StartOfWeek startOfWeek() => strtOfWeek; + StartOfWeek startOfWeek() => StartOfWeek.sunday; } -class EsRelativeTime extends RelativeTime { +class EsRelativeTime extends RelativeDateTime { @override String prefixAgo() => 'hace'; @override diff --git a/lib/src/locale/faLocale.dart b/lib/src/locale/locales/fa_locale.dart similarity index 57% rename from lib/src/locale/faLocale.dart rename to lib/src/locale/locales/fa_locale.dart index 64b5693..51a3ccf 100644 --- a/lib/src/locale/faLocale.dart +++ b/lib/src/locale/locales/fa_locale.dart @@ -1,27 +1,23 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/utils/replace.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../../utils/replace.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class FaLocale extends Locale { - bool replaceNum; - StartOfWeek strtOfWeek; - FaLocale(this.replaceNum, this.strtOfWeek); + @override + String code() => 'fa'; @override - RelativeTime relativeTime() => FaRelativeTime(replaceNum); + List ordinals() => List.from(['م', 'م', 'م', 'م'], growable: false); @override - List? ordinals() => ['م', 'م', 'م', 'م']; + StartOfWeek startOfWeek() => StartOfWeek.saturday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => FaRelativeTime(); } -class FaRelativeTime extends RelativeTime { - bool replaceNum; - FaRelativeTime(this.replaceNum); - +class FaRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override @@ -38,7 +34,7 @@ class FaRelativeTime extends RelativeTime { String minutes(int minutes) { String result; result = '$minutes دقیقه '; - return replaceNum ? replaceToLocaleNum(result, 'fa') : result; + return replaceToLocaleNum(result, 'fa'); } @override @@ -47,7 +43,7 @@ class FaRelativeTime extends RelativeTime { String hours(int hours) { String result; result = '$hours ساعت '; - return replaceNum ? replaceToLocaleNum(result, 'fa') : result; + return replaceToLocaleNum(result, 'fa'); } @override @@ -56,7 +52,7 @@ class FaRelativeTime extends RelativeTime { String days(int days) { String result; result = '$days روز '; - return replaceNum ? replaceToLocaleNum(result, 'fa') : result; + return replaceToLocaleNum(result, 'fa'); } @override @@ -65,7 +61,7 @@ class FaRelativeTime extends RelativeTime { String months(int months) { String result; result = '$months ماه '; - return replaceNum ? replaceToLocaleNum(result, 'fa') : result; + return replaceToLocaleNum(result, 'fa'); } @override @@ -74,7 +70,7 @@ class FaRelativeTime extends RelativeTime { String years(int years) { String result; result = '$years سال '; - return replaceNum ? replaceToLocaleNum(result, 'fa') : result; + return replaceToLocaleNum(result, 'fa'); } @override diff --git a/lib/src/locale/frLocale.dart b/lib/src/locale/locales/fr_locale.dart similarity index 61% rename from lib/src/locale/frLocale.dart rename to lib/src/locale/locales/fr_locale.dart index 2ddaf94..831222f 100644 --- a/lib/src/locale/frLocale.dart +++ b/lib/src/locale/locales/fr_locale.dart @@ -1,22 +1,35 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class FrLocale extends Locale { - StartOfWeek strtOfWeek; - FrLocale(this.strtOfWeek); + @override + String code() => 'fr'; + + @override + List ordinals() => List.from(['er', '', '', ''], growable: false); + + @override + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - RelativeTime relativeTime() => FrRelativeTime(); + RelativeDateTime relativeDateTime() => FrRelativeTime(); +} + +class FrChLocale extends FrLocale { + @override + String code() => 'fr_ch'; +} +class FrCaLocale extends FrLocale { @override - List? ordinals() => ['er', '', '', '']; + String code() => 'fr_ca'; @override - StartOfWeek startOfWeek() => strtOfWeek; + StartOfWeek startOfWeek() => StartOfWeek.sunday; } -class FrRelativeTime extends RelativeTime { +class FrRelativeTime extends RelativeDateTime { @override String prefixAgo() => 'il y a'; @override diff --git a/lib/src/locale/hiLocale.dart b/lib/src/locale/locales/hi_locale.dart similarity index 73% rename from lib/src/locale/hiLocale.dart rename to lib/src/locale/locales/hi_locale.dart index 4a9f796..08d0cd5 100644 --- a/lib/src/locale/hiLocale.dart +++ b/lib/src/locale/locales/hi_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class HiLocale extends Locale { - StartOfWeek strtOfWeek; - HiLocale(this.strtOfWeek); + @override + String code() => 'hi'; @override - RelativeTime relativeTime() => HiRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.sunday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => HiRelativeTime(); } -class HiRelativeTime extends RelativeTime { +class HiRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/locales/hu_locale.dart b/lib/src/locale/locales/hu_locale.dart new file mode 100644 index 0000000..1c54351 --- /dev/null +++ b/lib/src/locale/locales/hu_locale.dart @@ -0,0 +1,57 @@ +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; + +class HuLocale extends Locale { + @override + String code() => 'hu'; + + @override + List ordinals() => List.from(['.', '.', '.', '.'], growable: false); + + @override + StartOfWeek startOfWeek() => StartOfWeek.monday; + + @override + RelativeDateTime relativeDateTime() => HuRelativeTime(); +} + +class HuHuLocale extends HuLocale { + @override + String code() => 'hu_hu'; +} + +class HuRelativeTime extends RelativeDateTime { + @override + String prefixAgo() => ''; + @override + String prefixFromNow() => ''; + @override + String suffixAgo() => 'ezelőtt'; + @override + String suffixFromNow() => 'ezután'; + @override + String lessThanOneMinute(int seconds) => 'néhány másodperccel'; + @override + String aboutAMinute(int minutes) => 'egy perccel'; + @override + String minutes(int minutes) => '$minutes perccel'; + @override + String aboutAnHour(int minutes) => 'egy órával'; + @override + String hours(int hours) => '$hours órával'; + @override + String aDay(int hours) => 'egy nappal'; + @override + String days(int days) => '$days nappal'; + @override + String aboutAMonth(int days) => 'egy hónappal'; + @override + String months(int months) => '$months hónappal'; + @override + String aboutAYear(int year) => 'egy évvel'; + @override + String years(int years) => '$years évvel'; + @override + String wordSeparator() => ' '; +} diff --git a/lib/src/locale/idLocale.dart b/lib/src/locale/locales/id_locale.dart similarity index 71% rename from lib/src/locale/idLocale.dart rename to lib/src/locale/locales/id_locale.dart index e65c42d..b4bffc6 100644 --- a/lib/src/locale/idLocale.dart +++ b/lib/src/locale/locales/id_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class IdLocale extends Locale { - StartOfWeek strtOfWeek; - IdLocale(this.strtOfWeek); + @override + String code() => 'id'; @override - RelativeTime relativeTime() => IdRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.sunday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => IdRelativeTime(); } -class IdRelativeTime extends RelativeTime { +class IdRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/itLocale.dart b/lib/src/locale/locales/it_locale.dart similarity index 67% rename from lib/src/locale/itLocale.dart rename to lib/src/locale/locales/it_locale.dart index bef2b23..3091827 100644 --- a/lib/src/locale/itLocale.dart +++ b/lib/src/locale/locales/it_locale.dart @@ -1,22 +1,27 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class ItLocale extends Locale { - StartOfWeek strtOfWeek; - ItLocale(this.strtOfWeek); + @override + String code() => 'it'; + + @override + List ordinals() => List.from(['º', 'º', 'º', 'º'], growable: false); @override - RelativeTime relativeTime() => ItRelativeTime(); + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - List? ordinals() => ['º', 'º', 'º', 'º']; + RelativeDateTime relativeDateTime() => ItRelativeTime(); +} +class ItChLocale extends ItLocale { @override - StartOfWeek startOfWeek() => strtOfWeek; + String code() => 'it_ch'; } -class ItRelativeTime extends RelativeTime { +class ItRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/jaLocale.dart b/lib/src/locale/locales/ja_locale.dart similarity index 69% rename from lib/src/locale/jaLocale.dart rename to lib/src/locale/locales/ja_locale.dart index 2bd9b9c..8d80e65 100644 --- a/lib/src/locale/jaLocale.dart +++ b/lib/src/locale/locales/ja_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class JaLocale extends Locale { - StartOfWeek strtOfWeek; - JaLocale(this.strtOfWeek); + @override + String code() => 'ja'; @override - RelativeTime relativeTime() => JaRelativeTime(); + List ordinals() => List.from(['日', '日', '日', '日'], growable: false); @override - List? ordinals() => ['日', '日', '日', '日']; + StartOfWeek startOfWeek() => StartOfWeek.sunday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => JaRelativeTime(); } -class JaRelativeTime extends RelativeTime { +class JaRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/koLocale.dart b/lib/src/locale/locales/ko_locale.dart similarity index 69% rename from lib/src/locale/koLocale.dart rename to lib/src/locale/locales/ko_locale.dart index dbfcf4a..9fcad64 100644 --- a/lib/src/locale/koLocale.dart +++ b/lib/src/locale/locales/ko_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class KoLocale extends Locale { - StartOfWeek strtOfWeek; - KoLocale(this.strtOfWeek); + @override + String code() => 'ko'; @override - RelativeTime relativeTime() => KoRelativeTime(); + List ordinals() => List.from(['일', '일', '일', '일'], growable: false); @override - List? ordinals() => ['일', '일', '일', '일']; + StartOfWeek startOfWeek() => StartOfWeek.sunday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => KoRelativeTime(); } -class KoRelativeTime extends RelativeTime { +class KoRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/nbLocale.dart b/lib/src/locale/locales/nb_locale.dart similarity index 70% rename from lib/src/locale/nbLocale.dart rename to lib/src/locale/locales/nb_locale.dart index add2f02..54ee4bc 100644 --- a/lib/src/locale/nbLocale.dart +++ b/lib/src/locale/locales/nb_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class NbLocale extends Locale { - StartOfWeek strtOfWeek; - NbLocale(this.strtOfWeek); + @override + String code() => 'nb'; @override - RelativeTime relativeTime() => NbRelativeTime(); + List ordinals() => List.from(['.', '.', '.', '.'], growable: false); @override - List? ordinals() => ['.', '.', '.', '.']; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => NbRelativeTime(); } -class NbRelativeTime extends RelativeTime { +class NbRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/nlLocale.dart b/lib/src/locale/locales/nl_locale.dart similarity index 62% rename from lib/src/locale/nlLocale.dart rename to lib/src/locale/locales/nl_locale.dart index afe68a6..05df4af 100644 --- a/lib/src/locale/nlLocale.dart +++ b/lib/src/locale/locales/nl_locale.dart @@ -1,32 +1,33 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class NlLocale extends Locale { - StartOfWeek strtOfWeek; - NlLocale(this.strtOfWeek); + @override + String code() => 'nl'; @override - RelativeTime relativeTime() => NlRelativeTime(); + List ordinals() => List.from(['.', '.', '.', '.'], growable: false); @override - List? ordinals() => ['.', '.', '.', '.']; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => NlRelativeTime(); } -class NlRelativeTime extends RelativeTime { +class NlRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override - String prefixFromNow() => 'over'; + String prefixFromNow() => ''; @override String suffixAgo() => 'geleden'; @override String suffixFromNow() => ''; @override - String lessThanOneMinute(int seconds) => 'een paar seconden'; + String lessThanOneMinute(int seconds) => + seconds > 0 ? 'op dit moment' : 'een ogenblik'; @override String aboutAMinute(int minutes) => 'een minuut'; @override diff --git a/lib/src/locale/plLocale.dart b/lib/src/locale/locales/pl_locale.dart similarity index 79% rename from lib/src/locale/plLocale.dart rename to lib/src/locale/locales/pl_locale.dart index c4d8c21..adfc47a 100644 --- a/lib/src/locale/plLocale.dart +++ b/lib/src/locale/locales/pl_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class PlLocale extends Locale { - StartOfWeek strtOfWeek; - PlLocale(this.strtOfWeek); + @override + String code() => 'pl'; @override - RelativeTime relativeTime() => PlRelativeTime(); + List ordinals() => List.from(['.', '.', '.', '.'], growable: false); @override - List? ordinals() => ['.', '.', '.', '.']; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => PlRelativeTime(); } -class PlRelativeTime extends RelativeTime { +class PlRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/ptLocale.dart b/lib/src/locale/locales/pt_locale.dart similarity index 64% rename from lib/src/locale/ptLocale.dart rename to lib/src/locale/locales/pt_locale.dart index 97984ee..a9318d5 100644 --- a/lib/src/locale/ptLocale.dart +++ b/lib/src/locale/locales/pt_locale.dart @@ -1,22 +1,30 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class PtLocale extends Locale { - StartOfWeek strtOfWeek; - PtLocale(this.strtOfWeek); + @override + String code() => 'pt'; + + @override + List ordinals() => List.from(['º', 'º', 'º', 'º'], growable: false); @override - RelativeTime relativeTime() => PtRelativeTime(); + StartOfWeek startOfWeek() => StartOfWeek.monday; + + @override + RelativeDateTime relativeDateTime() => PtRelativeTime(); +} +class PtBrLocale extends PtLocale { @override - List? ordinals() => ['º', 'º', 'º', 'º']; + String code() => 'pt_br'; @override - StartOfWeek startOfWeek() => strtOfWeek; + StartOfWeek startOfWeek() => StartOfWeek.sunday; } -class PtRelativeTime extends RelativeTime { +class PtRelativeTime extends RelativeDateTime { @override String prefixAgo() => 'há'; @override diff --git a/lib/src/locale/ruLocale.dart b/lib/src/locale/locales/ru_locale.dart similarity index 85% rename from lib/src/locale/ruLocale.dart rename to lib/src/locale/locales/ru_locale.dart index d131823..87c8c09 100644 --- a/lib/src/locale/ruLocale.dart +++ b/lib/src/locale/locales/ru_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class RuLocale extends Locale { - StartOfWeek strtOfWeek; - RuLocale(this.strtOfWeek); + @override + String code() => 'ru'; @override - RelativeTime relativeTime() => RuRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => RuRelativeTime(); } -class RuRelativeTime extends RelativeTime { +class RuRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/svLocale.dart b/lib/src/locale/locales/sv_locale.dart similarity index 71% rename from lib/src/locale/svLocale.dart rename to lib/src/locale/locales/sv_locale.dart index 6c2bf1e..d663c8c 100644 --- a/lib/src/locale/svLocale.dart +++ b/lib/src/locale/locales/sv_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class SvLocale extends Locale { - StartOfWeek strtOfWeek; - SvLocale(this.strtOfWeek); + @override + String code() => 'sv'; @override - RelativeTime relativeTime() => SvRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => SvRelativeTime(); } -class SvRelativeTime extends RelativeTime { +class SvRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/thLocale.dart b/lib/src/locale/locales/th_locale.dart similarity index 73% rename from lib/src/locale/thLocale.dart rename to lib/src/locale/locales/th_locale.dart index 0896bcc..c66da3a 100644 --- a/lib/src/locale/thLocale.dart +++ b/lib/src/locale/locales/th_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class ThLocale extends Locale { - StartOfWeek strtOfWeek; - ThLocale(this.strtOfWeek); + @override + String code() => 'th'; @override - RelativeTime relativeTime() => ThRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.sunday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => ThRelativeTime(); } -class ThRelativeTime extends RelativeTime { +class ThRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/trLocale.dart b/lib/src/locale/locales/tr_locale.dart similarity index 71% rename from lib/src/locale/trLocale.dart rename to lib/src/locale/locales/tr_locale.dart index e362ca6..9f8f6a1 100644 --- a/lib/src/locale/trLocale.dart +++ b/lib/src/locale/locales/tr_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class TrLocale extends Locale { - StartOfWeek strtOfWeek; - TrLocale(this.strtOfWeek); + @override + String code() => 'tr'; @override - RelativeTime relativeTime() => TrRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => TrRelativeTime(); } -class TrRelativeTime extends RelativeTime { +class TrRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/ukLocale.dart b/lib/src/locale/locales/uk_locale.dart similarity index 85% rename from lib/src/locale/ukLocale.dart rename to lib/src/locale/locales/uk_locale.dart index e633beb..589fb3b 100644 --- a/lib/src/locale/ukLocale.dart +++ b/lib/src/locale/locales/uk_locale.dart @@ -1,22 +1,22 @@ -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; class UkLocale extends Locale { - StartOfWeek strtOfWeek; - UkLocale(this.strtOfWeek); + @override + String code() => 'uk'; @override - RelativeTime relativeTime() => UkRelativeTime(); + List ordinals() => List.from(['', '', '', ''], growable: false); @override - List? ordinals() => null; + StartOfWeek startOfWeek() => StartOfWeek.monday; @override - StartOfWeek startOfWeek() => strtOfWeek; + RelativeDateTime relativeDateTime() => UkRelativeTime(); } -class UkRelativeTime extends RelativeTime { +class UkRelativeTime extends RelativeDateTime { @override String prefixAgo() => ''; @override diff --git a/lib/src/locale/locales/zh_locale.dart b/lib/src/locale/locales/zh_locale.dart new file mode 100644 index 0000000..2e2e079 --- /dev/null +++ b/lib/src/locale/locales/zh_locale.dart @@ -0,0 +1,105 @@ +import '../../enums/start_of_week.dart'; +import '../locale.dart'; +import '../relative_date_time.dart'; + +class ZhLocale extends Locale { + @override + String code() => 'zh'; + + @override + List ordinals() => List.from(['日', '日', '日', '日'], growable: false); + + @override + StartOfWeek startOfWeek() => StartOfWeek.sunday; + + @override + RelativeDateTime relativeDateTime() => ZhRelativeTime(); +} + +class ZhCnLocale extends ZhLocale { + @override + String code() => 'zh_cn'; + + @override + RelativeDateTime relativeDateTime() => ZhCnRelativeTime(); +} + +class ZhHkLocale extends ZhLocale { + @override + String code() => 'zh_hk'; +} + +class ZhTwLocale extends ZhLocale { + @override + String code() => 'zh_tw'; +} + +class ZhRelativeTime extends RelativeDateTime { + @override + String prefixAgo() => ''; + @override + String prefixFromNow() => ''; + @override + String suffixAgo() => '前'; + @override + String suffixFromNow() => '内'; + @override + String lessThanOneMinute(int seconds) => '幾秒'; + @override + String aboutAMinute(int minutes) => '1 分鐘'; + @override + String minutes(int minutes) => '$minutes 分鐘'; + @override + String aboutAnHour(int minutes) => '1 小時'; + @override + String hours(int hours) => '$hours 小時'; + @override + String aDay(int hours) => '1 天'; + @override + String days(int days) => '$days 天'; + @override + String aboutAMonth(int days) => '1 個月'; + @override + String months(int months) => '$months 個月'; + @override + String aboutAYear(int year) => '1 年'; + @override + String years(int years) => '$years 年'; + @override + String wordSeparator() => ''; +} + +class ZhCnRelativeTime extends RelativeDateTime { + @override + String prefixAgo() => ''; + @override + String prefixFromNow() => ''; + @override + String suffixAgo() => '前'; + @override + String suffixFromNow() => '内'; + @override + String lessThanOneMinute(int seconds) => '几秒'; + @override + String aboutAMinute(int minutes) => '1 分钟'; + @override + String minutes(int minutes) => '$minutes 分钟'; + @override + String aboutAnHour(int minutes) => '1 小时'; + @override + String hours(int hours) => '$hours 小时'; + @override + String aDay(int hours) => '1 天'; + @override + String days(int days) => '$days 天'; + @override + String aboutAMonth(int days) => '1 个月'; + @override + String months(int months) => '$months 个月'; + @override + String aboutAYear(int year) => '1 年'; + @override + String years(int years) => '$years 年'; + @override + String wordSeparator() => ''; +} diff --git a/lib/src/locale/relativeTime.dart b/lib/src/locale/relative_date_time.dart similarity index 93% rename from lib/src/locale/relativeTime.dart rename to lib/src/locale/relative_date_time.dart index edc5f1f..e9fe6df 100644 --- a/lib/src/locale/relativeTime.dart +++ b/lib/src/locale/relative_date_time.dart @@ -1,4 +1,4 @@ -abstract class RelativeTime { +abstract class RelativeDateTime { String prefixAgo(); String prefixFromNow(); String suffixAgo(); diff --git a/lib/src/locale/zhCnLocale.dart b/lib/src/locale/zhCnLocale.dart deleted file mode 100644 index 65323b9..0000000 --- a/lib/src/locale/zhCnLocale.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; - -class ZhCnLocale extends Locale { - StartOfWeek strtOfWeek; - ZhCnLocale(this.strtOfWeek); - - @override - RelativeTime relativeTime() => ZhCnRelativeTime(); - - @override - List? ordinals() => ['日', '日', '日', '日']; - - @override - StartOfWeek startOfWeek() => strtOfWeek; -} - -class ZhCnRelativeTime extends RelativeTime { - @override - String prefixAgo() => ''; - @override - String prefixFromNow() => ''; - @override - String suffixAgo() => '前'; - @override - String suffixFromNow() => '内'; - @override - String lessThanOneMinute(int seconds) => '几秒'; - @override - String aboutAMinute(int minutes) => '1 分钟'; - @override - String minutes(int minutes) => '$minutes 分钟'; - @override - String aboutAnHour(int minutes) => '1 小时'; - @override - String hours(int hours) => '$hours 小时'; - @override - String aDay(int hours) => '1 天'; - @override - String days(int days) => '$days 天'; - @override - String aboutAMonth(int days) => '1 个月'; - @override - String months(int months) => '$months 个月'; - @override - String aboutAYear(int year) => '1 年'; - @override - String years(int years) => '$years 年'; - @override - String wordSeparator() => ''; -} diff --git a/lib/src/locale/zhLocale.dart b/lib/src/locale/zhLocale.dart deleted file mode 100644 index 3b4dc73..0000000 --- a/lib/src/locale/zhLocale.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:jiffy/src/locale/relativeTime.dart'; -import 'package:jiffy/src/locale/locale.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; - -class ZhLocale extends Locale { - StartOfWeek strtOfWeek; - ZhLocale(this.strtOfWeek); - - @override - RelativeTime relativeTime() => ZhRelativeTime(); - - @override - List? ordinals() => ['日', '日', '日', '日']; - - @override - StartOfWeek startOfWeek() => strtOfWeek; -} - -class ZhRelativeTime extends RelativeTime { - @override - String prefixAgo() => ''; - @override - String prefixFromNow() => ''; - @override - String suffixAgo() => '前'; - @override - String suffixFromNow() => '内'; - @override - String lessThanOneMinute(int seconds) => '幾秒'; - @override - String aboutAMinute(int minutes) => '1 分鐘'; - @override - String minutes(int minutes) => '$minutes 分鐘'; - @override - String aboutAnHour(int minutes) => '1 小時'; - @override - String hours(int hours) => '$hours 小時'; - @override - String aDay(int hours) => '1 天'; - @override - String days(int days) => '$days 天'; - @override - String aboutAMonth(int days) => '1 個月'; - @override - String months(int months) => '$months 個月'; - @override - String aboutAYear(int year) => '1 年'; - @override - String years(int years) => '$years 年'; - @override - String wordSeparator() => ''; -} diff --git a/lib/src/manipulator.dart b/lib/src/manipulator.dart new file mode 100644 index 0000000..9d443ee --- /dev/null +++ b/lib/src/manipulator.dart @@ -0,0 +1,317 @@ +import 'dart:math'; + +import 'getter.dart'; +import 'enums/start_of_week.dart'; +import 'enums/unit.dart'; +import 'query.dart'; + +class Manipulator { + final Getter _getter; + + Manipulator(this._getter); + + DateTime addDuration(DateTime dateTime, Duration duration) { + return dateTime.add(duration); + } + + DateTime add( + DateTime dateTime, + int microseconds, + int milliseconds, + int seconds, + int minutes, + int hours, + int days, + int weeks, + int months, + int years) { + var newDateTime = dateTime.add(Duration( + days: days + (weeks * 7), + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds, + )); + newDateTime = _addMonths(newDateTime, months); + newDateTime = _addMonths(newDateTime, years * 12); + return newDateTime; + } + + DateTime subtractDuration(DateTime dateTime, Duration duration) { + return dateTime.subtract(duration); + } + + DateTime subtract( + DateTime dateTime, + int microseconds, + int milliseconds, + int seconds, + int minutes, + int hours, + int days, + int weeks, + int months, + int years) { + var newDateTime = dateTime.subtract(Duration( + days: days + (weeks * 7), + hours: hours, + minutes: minutes, + seconds: seconds, + milliseconds: milliseconds, + microseconds: microseconds, + )); + newDateTime = _addMonths(newDateTime, -months); + newDateTime = _addMonths(newDateTime, -years * 12); + return newDateTime; + } + + DateTime startOf(DateTime dateTime, Unit unit, StartOfWeek startOfWeek) { + DateTime newDateTime; + switch (unit) { + case Unit.microsecond: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: _getter.millisecond(dateTime), + microsecond: _getter.microsecond(dateTime)); + break; + case Unit.millisecond: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: _getter.millisecond(dateTime), + microsecond: 0); + break; + case Unit.second: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: 0, + microsecond: 0); + break; + case Unit.minute: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: 0, + millisecond: 0, + microsecond: 0); + break; + case Unit.hour: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: 0, + second: 0, + millisecond: 0, + microsecond: 0); + break; + case Unit.day: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + microsecond: 0); + break; + case Unit.week: + var newDate = subtractDuration(dateTime, + Duration(days: _getter.dayOfWeek(dateTime, startOfWeek) - 1)); + newDateTime = dateTime.copyWith( + year: _getter.year(newDate), + month: _getter.month(newDate), + day: _getter.date(newDate), + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + microsecond: 0); + break; + case Unit.month: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + microsecond: 0); + break; + case Unit.year: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + microsecond: 0); + break; + } + return newDateTime; + } + + DateTime endOf(DateTime dateTime, Unit unit, StartOfWeek startOfWeek) { + DateTime newDateTime; + switch (unit) { + case Unit.microsecond: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: _getter.millisecond(dateTime), + microsecond: _getter.microsecond(dateTime)); + break; + case Unit.millisecond: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: _getter.millisecond(dateTime), + microsecond: 999); + break; + case Unit.second: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: 999, + microsecond: 999); + break; + case Unit.minute: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: 59, + millisecond: 999, + microsecond: 999); + break; + case Unit.hour: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: _getter.hour(dateTime), + minute: 59, + second: 59, + millisecond: 999, + microsecond: 999); + break; + case Unit.day: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: _getter.date(dateTime), + hour: 23, + minute: 59, + second: 59, + millisecond: 999, + microsecond: 999); + break; + case Unit.week: + var newDate = addDuration( + dateTime, + Duration( + days: DateTime.daysPerWeek - + _getter.dayOfWeek(dateTime, startOfWeek))); + newDateTime = dateTime.copyWith( + year: _getter.year(newDate), + month: _getter.month(newDate), + day: _getter.date(newDate), + hour: 23, + minute: 59, + second: 59, + millisecond: 999, + microsecond: 999); + break; + case Unit.month: + var endMonthDate = Getter.daysInMonthArray[_getter.month(dateTime)]; + if (Query.isLeapYear(_getter.year(dateTime)) && + _getter.month(dateTime) == 2) { + endMonthDate++; + } + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: _getter.month(dateTime), + day: endMonthDate, + hour: 23, + minute: 59, + second: 59, + millisecond: 999, + microsecond: 999); + break; + case Unit.year: + newDateTime = dateTime.copyWith( + year: _getter.year(dateTime), + month: 12, + day: 31, + hour: 23, + minute: 59, + second: 59, + millisecond: 999, + microsecond: 999); + break; + } + return newDateTime; + } + + DateTime toLocal(DateTime dateTime) => dateTime.toLocal(); + + DateTime toUtc(DateTime dateTime) => dateTime.toUtc(); + + DateTime _addMonths(DateTime dateTime, int months) { + final modMonths = months % 12; + var newYear = _getter.year(dateTime) + ((months - modMonths) ~/ 12); + var newMonth = _getter.month(dateTime) + modMonths; + if (newMonth > 12) { + newYear++; + newMonth -= 12; + } + final newDay = min(_getter.date(dateTime), + _getter.daysInMonth(DateTime(newYear, newMonth))); + return dateTime.copyWith( + year: newYear, + month: newMonth, + day: newDay, + hour: _getter.hour(dateTime), + minute: _getter.minute(dateTime), + second: _getter.second(dateTime), + millisecond: _getter.millisecond(dateTime), + microsecond: _getter.microsecond(dateTime)); + } +} diff --git a/lib/src/parser.dart b/lib/src/parser.dart new file mode 100644 index 0000000..f292e53 --- /dev/null +++ b/lib/src/parser.dart @@ -0,0 +1,119 @@ +import 'package:intl/intl.dart'; + +import 'enums/unit.dart'; +import 'getter.dart'; +import 'locale/locale.dart'; +import 'utils/jiffy_exception.dart'; + +class Parser { + final Getter _getter; + + Parser(this._getter); + + DateTime fromString( + String input, String? pattern, Locale locale, bool isUtc) { + if (pattern != null) { + if (pattern.trim().isEmpty) { + throw JiffyException('The provided pattern for input `$input` cannot ' + 'be blank'); + } + final ordinals = locale.ordinals(); + return _parseString(_replaceParseInput(input, ordinals), + _replacePatternInput(pattern)) + .copyWith(isUtc: isUtc); + } + + if (_matchesHyphenStringDateTime(input)) { + return _parseString(input, 'yyyy-MM-dd').copyWith(isUtc: isUtc); + } else if (_matchesSlashStringDateTime(input)) { + return _parseString(input, 'yyyy/MM/dd').copyWith(isUtc: isUtc); + } else if (_matchesDartStringDateTime(input) || + _matchesISOStringDateTime(input)) { + return DateTime.parse(input).copyWith(isUtc: isUtc); + } else { + throw JiffyException( + 'Could not read date time of input `$input`, try using a pattern, ' + 'e.g. input: "12, Oct", pattern: "dd, MMM"'); + } + } + + DateTime fromList(List input, bool isUtc) { + if (input.isEmpty) { + throw JiffyException('The provided datetime list cannot be empty'); + } + final length = input.length; + return DateTime( + input[0], + length > 1 ? input[1] : 1, + length > 2 ? input[2] : 1, + length > 3 ? input[3] : 0, + length > 4 ? input[4] : 0, + length > 5 ? input[5] : 0, + length > 6 ? input[6] : 0, + length > 7 ? input[7] : 0) + .copyWith(isUtc: isUtc); + } + + DateTime fromMap(Map input, bool isUtc) { + if (input.isEmpty) { + throw JiffyException('The provided datetime map cannot be empty'); + } + return DateTime( + input[Unit.year] ?? _getter.year(DateTime.now()), + input[Unit.month] ?? _getter.month(DateTime.now()), + input[Unit.day] ?? _getter.date(DateTime.now()), + input[Unit.hour] ?? _getter.hour(DateTime.now()), + input[Unit.minute] ?? _getter.minute(DateTime.now()), + input[Unit.second] ?? _getter.second(DateTime.now()), + input[Unit.millisecond] ?? _getter.millisecond(DateTime.now()), + input[Unit.microsecond] ?? _getter.microsecond(DateTime.now())) + .copyWith(isUtc: isUtc); + } + + DateTime _parseString(String input, String pattern) { + try { + return DateFormat(pattern).parse(input); + } on FormatException catch (e) { + throw JiffyException('Could not parse input `$input`, failed with the ' + 'following error: ${e.toString()}'); + } + } + + String _replacePatternInput(String pattern) { + return pattern.replaceFirst('do', 'd'); + } + + String _replaceParseInput(String input, List ordinals) { + return input + .replaceFirst(' pm', ' PM') + .replaceFirst(' am', ' AM') + .replaceFirst(_matchesOrdinalDates(input, ordinals), ''); + } + + String _matchesOrdinalDates(String input, List ordinals) { + final matches = + // ignore: prefer_interpolation_to_compose_strings + RegExp(r'\d+\s*(' + ordinals.join('|') + ')').allMatches(input); + return matches.isNotEmpty ? matches.first.group(1) ?? '' : ''; + } + + bool _matchesHyphenStringDateTime(String input) { + return RegExp(r'\d{4}-\d{1,2}-\d{1,2}$').hasMatch(input); + } + + bool _matchesSlashStringDateTime(String input) { + return RegExp(r'\d{4}/\d{1,2}/\d{1,2}$').hasMatch(input); + } + + bool _matchesDartStringDateTime(String input) { + return RegExp( + r'\d{4}-\d{1,2}-\d{1,2} \d{1,2}(:\d{1,2})?(:\d{1,2})?(.\d+)?(Z?)$') + .hasMatch(input); + } + + bool _matchesISOStringDateTime(String input) { + return RegExp( + r'\d{4}-\d{1,2}-\d{1,2}T\d{1,2}(:\d{1,2})?(:\d{1,2})?(.\d+)?(Z?)$') + .hasMatch(input); + } +} diff --git a/lib/src/query.dart b/lib/src/query.dart new file mode 100644 index 0000000..934785e --- /dev/null +++ b/lib/src/query.dart @@ -0,0 +1,94 @@ +import 'enums/start_of_week.dart'; +import 'enums/unit.dart'; +import 'getter.dart'; +import 'manipulator.dart'; + +class Query { + final Getter _getter; + final Manipulator _manipulator; + + Query(this._getter, this._manipulator); + + bool isBefore(DateTime firstDateTime, DateTime secondDateTime, Unit unit, + StartOfWeek startOfWeek) { + final secondDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch(secondDateTime); + + if (unit == Unit.microsecond) { + return _getter.microsecondsSinceEpoch(firstDateTime) < + secondDateTimeMicrosecondsSinceEpoch; + } + + final endOfFirstDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch( + _manipulator.endOf(firstDateTime, unit, startOfWeek)); + + return endOfFirstDateTimeMicrosecondsSinceEpoch < + secondDateTimeMicrosecondsSinceEpoch; + } + + bool isAfter(DateTime firstDateTime, DateTime secondDateTime, Unit unit, + StartOfWeek startOfWeek) { + final secondDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch(secondDateTime); + + if (unit == Unit.microsecond) { + return _getter.microsecondsSinceEpoch(firstDateTime) > + secondDateTimeMicrosecondsSinceEpoch; + } + + final startOfFirstDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch( + _manipulator.startOf(firstDateTime, unit, startOfWeek)); + + return secondDateTimeMicrosecondsSinceEpoch < + startOfFirstDateTimeMicrosecondsSinceEpoch; + } + + bool isSame(DateTime firstDateTime, DateTime secondDateTime, Unit unit, + StartOfWeek startOfWeek) { + final secondDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch(secondDateTime); + + if (unit == Unit.microsecond) { + return _getter.microsecondsSinceEpoch(firstDateTime) == + secondDateTimeMicrosecondsSinceEpoch; + } + + final startOfFirstDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch( + _manipulator.startOf(firstDateTime, unit, startOfWeek)); + final endOfFirstDateTimeMicrosecondsSinceEpoch = + _getter.microsecondsSinceEpoch( + _manipulator.endOf(firstDateTime, unit, startOfWeek)); + + return startOfFirstDateTimeMicrosecondsSinceEpoch <= + secondDateTimeMicrosecondsSinceEpoch && + secondDateTimeMicrosecondsSinceEpoch <= + endOfFirstDateTimeMicrosecondsSinceEpoch; + } + + bool isSameOrBefore(DateTime firstDateTime, DateTime secondDateTime, + Unit unit, StartOfWeek startOfWeek) { + return isSame(firstDateTime, secondDateTime, unit, startOfWeek) || + isBefore(firstDateTime, secondDateTime, unit, startOfWeek); + } + + bool isSameOrAfter(DateTime firstDateTime, DateTime secondDateTime, Unit unit, + StartOfWeek startOfWeek) { + return isSame(firstDateTime, secondDateTime, unit, startOfWeek) || + isAfter(firstDateTime, secondDateTime, unit, startOfWeek); + } + + bool isBetween(DateTime firstDateTime, DateTime secondDateTime, + DateTime thirdDateTime, Unit unit, StartOfWeek startOfWeek) { + return isAfter(firstDateTime, secondDateTime, unit, startOfWeek) && + isBefore(firstDateTime, thirdDateTime, unit, startOfWeek); + } + + static bool isUtc(DateTime dateTime) => dateTime.isUtc; + + static bool isLeapYear(int year) { + return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); + } +} diff --git a/lib/src/utils/exception.dart b/lib/src/utils/exception.dart deleted file mode 100644 index 03e0a9d..0000000 --- a/lib/src/utils/exception.dart +++ /dev/null @@ -1,5 +0,0 @@ -class JiffyException implements Exception { - final String _cause; - JiffyException(this._cause); - String get cause => 'JiffyException: $_cause'; -} diff --git a/lib/src/utils/jiffy_exception.dart b/lib/src/utils/jiffy_exception.dart new file mode 100644 index 0000000..66273d1 --- /dev/null +++ b/lib/src/utils/jiffy_exception.dart @@ -0,0 +1,10 @@ +class JiffyException implements Exception { + final String _message; + + JiffyException(this._message); + + @override + String toString() { + return 'JiffyException: $_message'; + } +} diff --git a/lib/src/utils/normalize_units.dart b/lib/src/utils/normalize_units.dart deleted file mode 100644 index 08acd69..0000000 --- a/lib/src/utils/normalize_units.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'package:jiffy/src/utils/exception.dart'; - -String normalizeUnits(String unit) { - var lowerCaseUnit = unit.toLowerCase(); - if (lowerCaseUnit == 'millisecond' || - lowerCaseUnit == 'milliseconds' || - lowerCaseUnit == 'ms') { - return 'ms'; - } else if (lowerCaseUnit == 'second' || - lowerCaseUnit == 'seconds' || - lowerCaseUnit == 's') { - return 's'; - } else if (lowerCaseUnit == 'minute' || - lowerCaseUnit == 'minutes' || - lowerCaseUnit == 'm') { - return 'm'; - } else if (lowerCaseUnit == 'hour' || - lowerCaseUnit == 'hours' || - lowerCaseUnit == 'h') { - return 'h'; - } else if (lowerCaseUnit == 'day' || - lowerCaseUnit == 'days' || - lowerCaseUnit == 'd') { - return 'd'; - } else if (lowerCaseUnit == 'week' || - lowerCaseUnit == 'weeks' || - lowerCaseUnit == 'w') { - return 'w'; - } else if (lowerCaseUnit == 'month' || lowerCaseUnit == 'months') { - return 'M'; - } else if (lowerCaseUnit == 'year' || - lowerCaseUnit == 'years' || - lowerCaseUnit == 'y') { - return 'y'; - } else { - return '0'; - } -} - -String validateUnits(String unit) { - unit = unit == 'M' ? unit : normalizeUnits(unit); - if (unit == '0') { - throw JiffyException( - 'Invalid unit passed, the following units are available "year", "month", "week", "day", "hour", "minute", "second", "millisecond"') - .cause; - } - return unit; -} diff --git a/lib/src/utils/regex.dart b/lib/src/utils/regex.dart deleted file mode 100644 index e4623f3..0000000 --- a/lib/src/utils/regex.dart +++ /dev/null @@ -1,32 +0,0 @@ -bool matchDartStringDateTime(String input) { - return RegExp( - r'\d{4}-\d{1,2}-\d{1,2} \d{1,2}(:\d{1,2})?(:\d{1,2})?(.\d+)?(Z?)') - .hasMatch(input); -} - -bool matchISOStringDateTime(String input) { - return RegExp( - r'\d{4}-\d{1,2}-\d{1,2}T\d{1,2}(:\d{1,2})?(:\d{1,2})?(.\d+)?(Z?)') - .hasMatch(input); -} - -RegExp matchBasicStringDateTime() { - return RegExp(r'(\d{4})(\d{1,2})(\d{1,2})$'); -} - -bool matchHyphenStringDateTime(String input) { - return RegExp(r'\d{4}-\d{1,2}-\d{1,2}$').hasMatch(input); -} - -bool matchSlashStringDateTime(String input) { - return RegExp(r'\d{4}\/\d{1,2}\/\d{1,2}$').hasMatch(input); -} - -Pattern matchOrdinalDates() { - return RegExp(r'(?<=[0-9])(?:st|nd|rd|th)'); -} - -Pattern matchOrdinalDatePattern() { - return RegExp( - '''(?[^"'\\s]\\w*)|(?:["][^"]+?["])|(?:['][^']+?['])'''); -} diff --git a/lib/src/utils/replace.dart b/lib/src/utils/replace.dart index 6c6680f..6c28ad0 100644 --- a/lib/src/utils/replace.dart +++ b/lib/src/utils/replace.dart @@ -1,5 +1,3 @@ -import 'package:jiffy/src/utils/regex.dart'; - String replaceToLocaleNum(String input, String locale) { var localeNumbers = { 'en': ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], @@ -13,34 +11,3 @@ String replaceToLocaleNum(String input, String locale) { } return input; } - -String replaceParseInput(String input) { - return input - .replaceFirst(' pm', ' PM') - .replaceFirst(' am', ' AM') - .replaceFirst(matchOrdinalDates(), ''); -} - -String replacePatternInput(String input) { - return input.replaceFirst('do', 'd'); -} - -String replaceEscapePattern(String input) { - return input.replaceAll('[', '\'').replaceAll(']', '\''); -} - -String replaceOrdinalDatePattern(String input, String suffix) { - final regex = matchOrdinalDatePattern().allMatches(input); - var pattern = input; - regex.forEach((match) { - if (match.group(1) == 'do') { - pattern = input.replaceRange( - match.start, match.end, 'd${suffix.isNotEmpty ? "'$suffix'" : ''}'); - } - }); - return pattern; -} - -String replaceLocaleHyphen(String input) { - return input.replaceAll(RegExp(r'[-_]'), '').toLowerCase(); -} diff --git a/pubspec.yaml b/pubspec.yaml index 6137b4e..281cd28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,12 +7,12 @@ issue_tracker: https://github.com/jama5262/jiffy/issues documentation: https://github.com/jama5262/jiffy/tree/master/doc environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.15.0 <3.0.0' dependencies: intl: ^0.18.0 dev_dependencies: - pedantic: ^1.10.0 + lints: ^2.0.1 test: ^1.16.5 - coverage: ^1.0.2 + coverage: ^1.6.3 diff --git a/test/jiffy_display_test.dart b/test/jiffy_display_test.dart deleted file mode 100644 index 8044a8d..0000000 --- a/test/jiffy_display_test.dart +++ /dev/null @@ -1,218 +0,0 @@ -import 'package:jiffy/jiffy.dart'; -import 'package:test/test.dart'; - -void main() { - group('Test format and default format datetime methods', () { - test( - 'test Jiffy().format get method with parsing date time should return correct date time string', - () { - expect(Jiffy('20191016').format('MMMM dd, yyyy'), 'October 16, 2019'); - expect(Jiffy('2019-10-16 12:00').format('[Today is] dd MMM'), - 'Today is 16 Oct'); - expect(Jiffy('2019-10-16T00:00:00.000').format('MMMMEEEEd'), - 'Wednesday, October 16'); - expect(Jiffy('2019/10/16').format(), '2019-10-16T00:00:00.000'); - }); - test( - 'test Jiffy().format get method with parsing ordianl date time should return correct date time string', - () { - expect(Jiffy([2019, 10, 1]).format('MMM do yy'), 'Oct 1st 19'); - expect(Jiffy([2019, 10, 2]).format('MMM do yy'), 'Oct 2nd 19'); - expect(Jiffy([2019, 10, 3]).format('MMM do yy'), 'Oct 3rd 19'); - expect(Jiffy([2019, 10, 10]).format('MMM do yy'), 'Oct 10th 19'); - expect(Jiffy([2019, 10, 21]).format('MMM do yy'), 'Oct 21st 19'); - }); - test( - 'test Jiffy().defaultDatetime get method with parsing date time should return correct date time string', - () { - expect(Jiffy([2019, 10, 16]).E, 'Wed'); - expect(Jiffy([2019, 10, 16]).EEEE, 'Wednesday'); - expect(Jiffy([2019, 10, 16]).LLL, 'Oct'); - expect(Jiffy([2019, 10, 16]).LLLL, 'October'); - expect(Jiffy([2019, 10, 16]).Md, '10/16'); - expect(Jiffy([2019, 10, 16]).MEd, 'Wed, 10/16'); - expect(Jiffy([2019, 10, 16]).MMM, 'Oct'); - expect(Jiffy([2019, 10, 16]).MMMd, 'Oct 16'); - expect(Jiffy([2019, 10, 16]).MMMEd, 'Wed, Oct 16'); - expect(Jiffy([2019, 10, 16]).MMMM, 'October'); - expect(Jiffy([2019, 10, 16]).MMMMd, 'October 16'); - expect(Jiffy([2019, 10, 16]).MMMMEEEEd, 'Wednesday, October 16'); - expect(Jiffy([2019, 10, 16]).QQQ, 'Q4'); - expect(Jiffy([2019, 10, 16]).QQQQ, '4th quarter'); - expect(Jiffy([2019, 10, 16]).yM, '10/2019'); - expect(Jiffy([2019, 10, 16]).yMd, '10/16/2019'); - expect(Jiffy([2019, 10, 16]).yMEd, 'Wed, 10/16/2019'); - expect(Jiffy([2019, 10, 16]).yMMM, 'Oct 2019'); - expect(Jiffy([2019, 10, 16]).yMMMd, 'Oct 16, 2019'); - expect(Jiffy([2019, 10, 16]).yMMMdjm, 'Oct 16, 2019 12:00 AM'); - expect(Jiffy([2019, 10, 16]).yMMMEd, 'Wed, Oct 16, 2019'); - expect(Jiffy([2019, 10, 16]).yMMMEdjm, 'Wed, Oct 16, 2019 12:00 AM'); - expect(Jiffy([2019, 10, 16]).yMMMM, 'October 2019'); - expect(Jiffy([2019, 10, 16]).yMMMMd, 'October 16, 2019'); - expect(Jiffy([2019, 10, 16]).yMMMMdjm, 'October 16, 2019 12:00 AM'); - expect(Jiffy([2019, 10, 16]).yMMMMEEEEd, 'Wednesday, October 16, 2019'); - expect(Jiffy([2019, 10, 16]).yMMMMEEEEdjm, - 'Wednesday, October 16, 2019 12:00 AM'); - expect(Jiffy([2019, 10, 16]).yQQQ, 'Q4 2019'); - expect(Jiffy([2019, 10, 16]).yQQQQ, '4th quarter 2019'); - expect(Jiffy('2019, 10, 16 3:30 AM', 'yyyy, MM, dd hh:mm a').Hm, '03:30'); - expect(Jiffy('2019, 10, 16 3:30 am', 'yyyy, MM, dd hh:mm a').Hms, - '03:30:00'); - expect(Jiffy('2019, 10, 16 3:30 pm', 'yyyy, MM, dd hh:mm a').j, '3 PM'); - expect( - Jiffy('2019, 10, 16 3:30 am', 'yyyy, MM, dd hh:mm a').jm, '3:30 AM'); - expect(Jiffy('2019, 10, 16 3:30 PM', 'yyyy, MM, dd hh:mm a').jms, - '3:30:00 PM'); - }); - }); - - group('Test Jiffy.fromNow() and Jiffy.from() datetime methods', () { - test( - 'test Jiffy().fromNow() method with parsing date time should return correct relative date time string', - () { - expect(Jiffy().fromNow(), 'a few seconds ago'); - var jiffy1 = Jiffy()..add(duration: Duration(seconds: 20)); - expect(jiffy1.fromNow(), 'in a few seconds'); - var jiffy2 = Jiffy()..subtract(months: 20); - expect(jiffy2.fromNow(), 'a year ago'); - }); - test( - 'test Jiffy().from() method with parsing date time should return correct relative date time string', - () { - var jiffy1 = Jiffy([2019, 10, 16]); - expect(Jiffy('2019, 10, 20', 'yyyy, MM, dd').from(jiffy1), 'in 4 days'); - var jiffy2 = Jiffy([2019, 10, 16])..add(duration: Duration(days: 10)); - expect(Jiffy('2019, 10, 20', 'yyyy, MM, dd').from(jiffy2), '6 days ago'); - var jiffy3 = Jiffy([2019, 10, 16])..subtract(months: 20); - expect(Jiffy('2019, 10, 20', 'yyyy, MM, dd').from(jiffy3), 'in a year'); - }); - }); - - group('Test Jiffy().diff() datetime', () { - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in seconds', - () { - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(duration: Duration(seconds: 1)), - Units.SECOND), - -1); - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..subtract(duration: Duration(seconds: 25, milliseconds: 200)), - Units.SECOND, - true), - 25.2); - }); - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in minutes', - () { - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(duration: Duration(seconds: 1)), - Units.MINUTE), - 0); - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..subtract(duration: Duration(seconds: 178)), - Units.MINUTE, - true), - 2.966666666666667); - }); - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in hours', - () { - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(duration: Duration(seconds: 1)), - Units.HOUR), - 0); - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(duration: Duration(hours: 12, minutes: 30)), - Units.HOUR, - true), - -12.5); - }); - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in days', - () { - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(duration: Duration(seconds: 1)), - Units.DAY), - 0); - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..subtract(hours: 2), - Units.DAY, - true), - 0.08333333333333333); - }); - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in weeks', - () { - expect( - Jiffy(DateTime(2019, 10, 16, 23)).diff( - Jiffy(DateTime(2019, 10, 16, 23)) - ..add(duration: Duration(seconds: 1)), - Units.WEEK), - 0); - expect( - Jiffy(DateTime(2019, 10, 16, 23)).diff( - Jiffy(DateTime(2019, 10, 16, 23))..add(days: 2, hours: 23), - Units.WEEK, - true), - -0.4226190476190476); - }); - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in months', - () { - expect( - Jiffy([2019, 10, 20, 22]).diff( - Jiffy([2019, 10, 16, 22])..add(duration: Duration(seconds: 1)), - Units.MONTH), - 0); - expect( - Jiffy([2019, 10, 16, 22]).diff( - Jiffy([2019, 10, 16, 22])..add(weeks: 2), Units.MONTH, true), - -0.45161290322580644); - expect( - Jiffy([2019, 10, 16, 22]).diff( - Jiffy([2019, 10, 16, 22])..add(months: 2), Units.MONTH, true), - -2.0); - }); - test( - 'test Jiffy().diff() method with parsing date time should return correct date time in years', - () { - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(duration: Duration(seconds: 1)), - Units.YEAR), - 0); - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(weeks: 2), - Units.YEAR, - true), - -0.03763440860215054); - expect( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a').diff( - Jiffy('2019, 10, 16 10:00:00 pm', 'yyyy, MM, dd h:mm:ss a') - ..add(years: 2), - Units.YEAR, - true), - -2.0); - }); - }); -} diff --git a/test/jiffy_get_test.dart b/test/jiffy_get_test.dart deleted file mode 100644 index bb1511d..0000000 --- a/test/jiffy_get_test.dart +++ /dev/null @@ -1,71 +0,0 @@ -import 'package:jiffy/jiffy.dart'; -import 'package:test/test.dart'; - -void main() { - group('Test Jiffy get datetime methods', () { - test( - 'test Jiffy().seconds get method with parsing date time should return correct date time seconds', - () { - expect(Jiffy().second, DateTime.now().second); - }); - test( - 'test Jiffy().minute get method with parsing date time should return correct date time minute', - () { - expect(Jiffy().minute, DateTime.now().minute); - }); - test( - 'test Jiffy().hour get method with parsing date time should return correct date time hour', - () { - expect(Jiffy().hour, DateTime.now().hour); - }); - test( - 'test Jiffy().date get method with parsing date time should return correct date time date', - () { - expect(Jiffy().date, DateTime.now().day); - }); - test( - 'test Jiffy().day get method with parsing date time should return correct date time day in French locale time', - () async { - await Jiffy.locale('fr'); - expect(Jiffy([2019, 11, 24]).day, 7); - }); - test( - 'test Jiffy().day get method with parsing date time should return correct date time day in English locale time', - () async { - await Jiffy.locale('en'); - expect(Jiffy([2019, 11, 24]).day, 1); - }); - test( - 'test Jiffy().daysInMonth get method with parsing date time should return correct date time day of month', - () { - expect(Jiffy([2016, 1]).daysInMonth, 31); - expect(Jiffy([2016, 2]).daysInMonth, 29); - expect(Jiffy([2017, 2]).daysInMonth, 28); - }); - test( - 'test Jiffy().dayOfYear get method with parsing date time should return correct date time day of year', - () { - expect(Jiffy('2019, 10, 16', 'yyyy, MM, dd').dayOfYear, 289); - }); - test( - 'test Jiffy().week get method with parsing date time should return correct date time week', - () { - expect(Jiffy('2019, 10, 16', 'yyyy, MM, dd').week, 42); - }); - test( - 'test Jiffy().quarter get method with parsing date time should return correct date time quarter', - () { - expect(Jiffy('2019, 10, 16', 'yyyy, MM, dd').quarter, 4); - }); - test( - 'test Jiffy().month get method with parsing date time should return correct date time month', - () { - expect(Jiffy().month, DateTime.now().month); - }); - test( - 'test Jiffy().year get method with parsing date time should return correct date time year', - () { - expect(Jiffy().year, DateTime.now().year); - }); - }); -} diff --git a/test/jiffy_manipulation_test.dart b/test/jiffy_manipulation_test.dart deleted file mode 100644 index 65d377c..0000000 --- a/test/jiffy_manipulation_test.dart +++ /dev/null @@ -1,357 +0,0 @@ -import 'package:jiffy/jiffy.dart'; -import 'package:test/test.dart'; - -void main() { - group('Test Jiffy().add() method adding datetime', () { - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in milliseconds', - () { - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..add(duration: Duration(milliseconds: 1))) - .dateTime - .toString(), - '2019-10-13 00:00:00.001'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in seconds', - () { - expect((Jiffy()..add(duration: Duration(seconds: 1))).second, - DateTime.now().add(Duration(seconds: 1)).second); - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..add(duration: Duration(seconds: 1))) - .dateTime - .toString(), - '2019-10-13 00:00:01.000'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in minutes', - () { - expect((Jiffy()..add(duration: Duration(minutes: 1))).minute, - DateTime.now().add(Duration(minutes: 1)).minute); - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..add(duration: Duration(minutes: 1))) - .dateTime - .toString(), - '2019-10-13 00:01:00.000'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in hours', - () { - expect((Jiffy()..add(duration: Duration(hours: 1))).hour, - DateTime.now().add(Duration(hours: 1)).hour); - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..add(duration: Duration(hours: 1))) - .dateTime - .toString(), - '2019-10-13 01:00:00.000'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in days', - () { - expect((Jiffy()..add(duration: Duration(days: 1))).date, - DateTime.now().add(Duration(days: 1)).day); - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..add(duration: Duration(days: 1))) - .dateTime - .toString(), - '2019-10-14 00:00:00.000'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in weeks', - () { - expect((Jiffy()..add(weeks: 1)).date, - DateTime.now().add(Duration(days: 1 * 7)).day); - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss')..add(weeks: 1)) - .dateTime - .toString(), - '2019-10-20 00:00:00.000'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in months', - () { - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss')..add(months: 1)) - .dateTime - .toString(), - '2019-11-13 00:00:00.000'); - }); - test( - 'test Jiffy().add() method with parsing date time should add and return correct date time in years', - () { - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss')..add(years: 1)) - .dateTime - .toString(), - '2020-10-13 00:00:00.000'); - }); - }); - - group('Test Jiffy subtracting datetime', () { - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in milliseconds', - () { - expect( - (Jiffy('2019-10-13 23:00:00') - ..subtract(duration: Duration(milliseconds: 1))) - .dateTime - .toString(), - '2019-10-13 22:59:59.999'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in seconds', - () { - expect((Jiffy()..subtract(duration: Duration(seconds: 1))).second, - DateTime.now().subtract(Duration(seconds: 1)).second); - expect( - (Jiffy('2019-10-13 12:00:01', 'yyyy-MM-dd hh:mm:ss') - ..subtract(duration: Duration(seconds: 1))) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in minutes', - () { - expect((Jiffy()..subtract(duration: Duration(minutes: 1))).minute, - DateTime.now().subtract(Duration(minutes: 1)).minute); - expect( - (Jiffy('2019-10-13 12:01:00', 'yyyy-MM-dd hh:mm:ss') - ..subtract(duration: Duration(minutes: 1))) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in hours', - () { - expect((Jiffy()..subtract(duration: Duration(hours: 1))).hour, - DateTime.now().subtract(Duration(hours: 1)).hour); - expect( - (Jiffy('2019-10-13 13:00:00', 'yyyy-MM-dd hh:mm:ss') - ..subtract(duration: Duration(hours: 1))) - .dateTime - .toString(), - '2019-10-13 12:00:00.000'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in day', - () { - expect((Jiffy()..subtract(duration: Duration(days: 1))).date, - DateTime.now().subtract(Duration(days: 1)).day); - expect( - (Jiffy('2019-10-14 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..subtract(duration: Duration(days: 1))) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in weeks', - () { - expect((Jiffy()..subtract(weeks: 1)).date, - DateTime.now().subtract(Duration(days: 1 * 7)).day); - expect( - (Jiffy('2019-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..subtract(weeks: 1)) - .dateTime - .toString(), - '2019-10-06 00:00:00.000'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in months', - () { - expect( - (Jiffy('2019-11-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..subtract(months: 1)) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - }); - test( - 'test Jiffy().subtract() method with parsing date time should subtract and return correct date time in years', - () { - expect( - (Jiffy('2020-10-13 12:00:00', 'yyyy-MM-dd hh:mm:ss') - ..subtract(years: 1)) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - }); - }); - - group('Test Jiffy().startOf() datetime', () { - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in seconds', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.SECOND)) - .dateTime - .toString(), - '2019-10-13 13:12:12.000'); - }); - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in minutes', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.MINUTE)) - .dateTime - .toString(), - '2019-10-13 13:12:00.000'); - }); - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in hours', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.HOUR)) - .dateTime - .toString(), - '2019-10-13 13:00:00.000'); - }); - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in days', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.DAY)) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - }); - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in weeks', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.WEEK)) - .dateTime - .toString(), - '2019-10-13 00:00:00.000'); - expect( - (Jiffy('2019-10-10 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.WEEK)) - .dateTime - .toString(), - '2019-10-06 00:00:00.000'); - }); - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in months', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.MONTH)) - .dateTime - .toString(), - '2019-10-01 00:00:00.000'); - }); - test( - 'test Jiffy().startOf() method with parsing date time should add and return correct start of date time in years', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..startOf(Units.YEAR)) - .dateTime - .toString(), - '2019-01-01 00:00:00.000'); - }); - }); - - group('Test Jiffy().endOf() datetime', () { - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in seconds', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.SECOND)) - .dateTime - .toString(), - '2019-10-13 13:12:12.999'); - }); - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in mintes', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.MINUTE)) - .dateTime - .toString(), - '2019-10-13 13:12:59.999'); - }); - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in hours', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.HOUR)) - .dateTime - .toString(), - '2019-10-13 13:59:59.999'); - }); - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in days', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.DAY)) - .dateTime - .toString(), - '2019-10-13 23:59:59.999'); - }); - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in weeks', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.WEEK)) - .dateTime - .toString(), - '2019-10-19 23:59:59.999'); - expect( - (Jiffy('2019-10-10 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.WEEK)) - .dateTime - .toString(), - '2019-10-12 23:59:59.999'); - }); - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in months', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.MONTH)) - .dateTime - .toString(), - '2019-10-31 23:59:59.999'); - expect( - (Jiffy('2019-02-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.MONTH)) - .dateTime - .toString(), - '2019-02-28 23:59:59.999'); - expect( - (Jiffy('2016-02-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.MONTH)) - .dateTime - .toString(), - '2016-02-29 23:59:59.999'); - }); - test( - 'test Jiffy().endOf() method with parsing date time should add and return correct end of date time in years', - () { - expect( - (Jiffy('2019-10-13 13:12:12', 'yyyy-MM-dd hh:mm:ss') - ..endOf(Units.YEAR)) - .dateTime - .toString(), - '2019-12-31 23:59:59.999'); - }); - }); -} diff --git a/test/jiffy_parse_test.dart b/test/jiffy_parse_test.dart deleted file mode 100644 index e06491a..0000000 --- a/test/jiffy_parse_test.dart +++ /dev/null @@ -1,167 +0,0 @@ -import 'package:jiffy/jiffy.dart'; -import 'package:test/test.dart'; - -void main() { - group('Test Jiffy cloning', () { - test('Test with clone() function no manipulation should be equal', () { - var jiffy1 = Jiffy([2021]); - var jiffy2 = jiffy1.clone(); - expect(jiffy1.year, jiffy2.year); - }); - test( - 'Test with clone() function manipulation by adding 10 years should not be equal', - () { - var jiffy1 = Jiffy([2021]); - var jiffy2 = jiffy1.clone(); - jiffy1.add(years: 10); - expect(jiffy1.year, isNot(jiffy2.year)); - }); - test('Test clone from instance no manipulation should be equal', () { - var jiffy1 = Jiffy([2021]); - var jiffy2 = Jiffy(jiffy1); - expect(jiffy1.year, jiffy2.year); - }); - test( - 'Test clone from instance manipulation by adding 10 years should not be equal', - () { - var jiffy1 = Jiffy([2021]); - var jiffy2 = Jiffy(jiffy1); - jiffy1.add(years: 10); - expect(jiffy1.year, isNot(jiffy2.year)); - }); - }); - - group('Test Jiffy datetime instance', () { - test( - 'test Jiffy() instance without parsing time and pattern should set correct datetime', - () { - expect(Jiffy().year, DateTime.now().year); - expect(Jiffy().month, DateTime.now().month); - }); - test( - 'test Jiffy() instance with parsing time and pattern should set correct date time', - () { - expect(Jiffy('2009', 'yyyy').year, 2009); - expect(Jiffy('Oct, 2009', 'MMM, yyyy').year, 2009); - }); - test( - 'test Jiffy() instance with parsing ordinal pattern should return correct ordinal date', - () { - expect( - Jiffy('Oct 1st 19', 'MMM do yy').format('MMM do yy'), 'Oct 1st 19'); - expect( - Jiffy('Oct 2st 19', 'MMM do yy').format('MMM do yy'), 'Oct 2nd 19'); - expect( - Jiffy('Oct 3st 19', 'MMM do yy').format('MMM do yy'), 'Oct 3rd 19'); - expect( - Jiffy('Oct 10st 19', 'MMM do yy').format('MMM do yy'), 'Oct 10th 19'); - expect( - Jiffy('Oct 21st 19', 'MMM do yy').format('MMM do yy'), 'Oct 21st 19'); - }); - test( - 'test Jiffy() instance with parsing empty string pattern should set correct date time', - () { - expect(Jiffy('2009', '').year, 1970); - }); - test( - 'test Jiffy() instance with parsing empty string time and pattern should set correct date time', - () { - expect(Jiffy('', '').year, 1970); - }); - test( - 'test Jiffy() instance with parsing Datetime object should set correct date time', - () { - expect(Jiffy(DateTime(2019)).year, 2019); - }); - test( - 'test Jiffy() instance with parsing Jiffy object should set correct date time', - () { - expect(Jiffy(Jiffy('2009', 'yyyy')).year, 2009); - }); - test( - 'test Jiffy() instance with parsing Map object should set correct date time', - () { - expect(Jiffy({'y': 2009}).year, 2009); - expect(Jiffy({'M': 2}).year, DateTime.now().year); - }); - test( - 'test Jiffy() instance with parsing empty Map object should set correct date time', - () { - expect(Jiffy({}).year, DateTime.now().year); - }); - test( - 'test Jiffy() instance with parsing Array object should set correct date time', - () { - expect(Jiffy([2009, 1]).year, 2009); - }); - test( - 'test Jiffy() instance with parsing empty Array should set correct date time', - () { - expect(Jiffy([]).year, DateTime.now().year); - }); - test( - 'test Jiffy().dateTime get method with parsing time and pattern should return date time string', - () { - expect(Jiffy('Oct, 2009', 'MMM, yyyy').dateTime.toString(), - '2009-10-01 00:00:00.000'); - }); - test( - 'test Jiffy() instance with parsing pattern and empty time should return exception', - () { - try { - Jiffy('', 'yyyy'); - } catch (e) { - expect(e.toString(), 'FormatException: Trying to read yyyy from at 0'); - } - }); - test( - 'test Jiffy() instance with parsing wrong time and pattern should return exception', - () { - try { - Jiffy('Oct', 'yyyy'); - } catch (e) { - expect( - e.toString(), 'FormatException: Trying to read yyyy from Oct at 0'); - } - }); - test( - 'test Jiffy() instance with parsing time and without pattern should return exception', - () { - try { - Jiffy(''); - } catch (e) { - expect(e.toString(), - 'JiffyException: Date time not recognized, a pattern must be passed, e.g. Jiffy("12, Oct", "dd, MMM")'); - } - }); - test( - 'test Jiffy() instance with parsing other than String, List, Map, DateTime or Jiffy itself', - () { - try { - Jiffy(2); - } catch (e) { - expect(e.toString(), - 'JiffyException: Jiffy only accepts String, List, Map, DateTime or Jiffy itself as parameters'); - } - }); - }); - - group('Test Jiffy.unix datetime instance', () { - test( - 'test Jiffy.unix() instance with parsing timestamp in seconds should set date time', - () { - expect(Jiffy.unixFromSecondsSinceEpoch(1570963450).year, - DateTime.fromMillisecondsSinceEpoch(1570963450000).year); - expect(Jiffy.unixFromSecondsSinceEpoch(1570963450).month, - DateTime.fromMillisecondsSinceEpoch(1570963450000).month); - }); - test( - 'test Jiffy.unix() instance with parsing timestamp in milliseconds should set date time', - () { - expect(Jiffy.unixFromMillisecondsSinceEpoch(1570963450000).year, - DateTime.fromMillisecondsSinceEpoch(1570963450000).year); - expect(Jiffy.unixFromMillisecondsSinceEpoch(1570963450000).month, - DateTime.fromMillisecondsSinceEpoch(1570963450000).month); - }); - }); -} diff --git a/test/jiffy_query_test.dart b/test/jiffy_query_test.dart deleted file mode 100644 index 160bd24..0000000 --- a/test/jiffy_query_test.dart +++ /dev/null @@ -1,84 +0,0 @@ -import 'package:jiffy/jiffy.dart'; -import 'package:test/test.dart'; - -void main() { - group('Test Jiffy query date time', () { - test( - 'test Jiffy().isBefore() method with parsing date time should return true or false if date time is before', - () { - var jiffy1 = Jiffy('2010-10-20', 'yyyy-MM-dd'); - var jiffy2 = Jiffy('2010-12-31', 'yyyy-MM-dd'); - var jiffy3 = Jiffy('2011-01-01', 'yyyy-MM-dd'); - expect(jiffy1.isBefore(Jiffy('2010-10-21', 'yyyy-MM-dd')), true); - expect(jiffy1.isBefore(jiffy2, Units.YEAR), false); - expect(jiffy1.isBefore(jiffy3, Units.YEAR), true); - }); - test( - 'test Jiffy().isAfter() method with parsing date time should return true or false if date time is after', - () { - var jiffy1 = Jiffy('2010-10-20', 'yyyy-MM-dd'); - var jiffy2 = Jiffy('2010-01-01', 'yyyy-MM-dd'); - expect(jiffy1.isAfter(Jiffy('2010-10-19', 'yyyy-MM-dd')), true); - expect(jiffy1.isAfter(jiffy2, Units.YEAR), false); - expect(jiffy1.isAfter([2009, 12, 31], Units.YEAR), true); - }); - test( - 'test Jiffy().isSame() method with parsing date time should return true or false if date time is same', - () { - var jiffy1 = Jiffy('2010-10-20', 'yyyy-MM-dd'); - var jiffy2 = Jiffy('2009-12-31', 'yyyy-MM-dd'); - var jiffy3 = Jiffy('2010-01-01', 'yyyy-MM-dd'); - expect(jiffy1.isSame(Jiffy('2010-10-20', 'yyyy-MM-dd')), true); - expect(jiffy1.isSame(jiffy2, Units.YEAR), false); - expect(jiffy1.isSame(jiffy3, Units.YEAR), true); - }); - test( - 'test Jiffy().isSameOrBefore() method with parsing date time should return true or false if date time is same or before', - () { - var jiffy1 = Jiffy('2010-10-20', 'yyyy-MM-dd'); - var jiffy2 = Jiffy('2009-12-31', 'yyyy-MM-dd'); - var jiffy3 = Jiffy('2010-12-31', 'yyyy-MM-dd'); - expect(jiffy1.isSameOrBefore(Jiffy('2010-10-21', 'yyyy-MM-dd')), true); - expect(jiffy1.isSameOrBefore(Jiffy('2010-10-19', 'yyyy-MM-dd')), false); - expect(jiffy1.isSameOrBefore(jiffy2, Units.YEAR), false); - expect(jiffy1.isSameOrBefore(jiffy3, Units.YEAR), true); - }); - test( - 'test Jiffy().isSameOrAfter() method with parsing date time should return true or false if date time is same or after', - () { - var jiffy1 = Jiffy('2010-10-20', 'yyyy-MM-dd'); - var jiffy2 = Jiffy('2011-12-31', 'yyyy-MM-dd'); - var jiffy3 = Jiffy('2010-01-01', 'yyyy-MM-dd'); - expect(jiffy1.isSameOrAfter(Jiffy('2010-10-19', 'yyyy-MM-dd')), true); - expect(jiffy1.isSameOrAfter(Jiffy('2010-10-21', 'yyyy-MM-dd')), false); - expect(jiffy1.isSameOrAfter(jiffy2, Units.YEAR), false); - expect(jiffy1.isSameOrAfter(jiffy3, Units.YEAR), true); - }); - test( - 'test Jiffy().isBetween() method with parsing date time should return true or false if date time is between two date times', - () { - var jiffy1 = Jiffy('2010-10-20'); - var jiffy2 = Jiffy('2010-10-19'); - expect(jiffy1.isBetween(jiffy2, DateTime(2010, 10, 25)), true); - expect(jiffy1.isBetween([2010, 1, 1], '2012-01-01', Units.YEAR), false); - }); - test( - 'test Jiffy().isLeapYear() method with parsing date time should return true or false if date time is leap year', - () { - expect(Jiffy('2010', 'yyyy').isLeapYear, false); - expect(Jiffy('2016', 'yyyy').isLeapYear, true); - }); - test( - 'test Jiffy().isJiffy() method with parsing date time should return true or false if date time is Jiffy object', - () { - expect(Jiffy.isJiffy(DateTime.now()), false); - expect(Jiffy.isJiffy(Jiffy()), true); - }); - test( - 'test Jiffy().isDateTime() method with parsing date time should return true or false if date time is DateTime object', - () { - expect(Jiffy.isDateTime(Jiffy()), false); - expect(Jiffy.isDateTime(DateTime.now()), true); - }); - }); -} diff --git a/test/jiffy_relative_locale_test.dart b/test/jiffy_relative_locale_test.dart deleted file mode 100644 index 91fbd9a..0000000 --- a/test/jiffy_relative_locale_test.dart +++ /dev/null @@ -1,547 +0,0 @@ -import 'package:jiffy/jiffy.dart'; -import 'package:jiffy/src/enums/startOfWeek.dart'; -import 'package:jiffy/src/locale/availableLocales.dart'; -import 'package:test/test.dart'; - -void main() { - group('Test display all locales', () { - test('test show all available locales as List type', () { - var locales = getAllLocales(); - expect(locales, isList); - }); - - test( - 'test show all available locales contains locales en, fr, de, zn_ch, ru, az', - () { - var locales = getAllLocales(); - expect(locales, contains('en')); - expect(locales, contains('fr')); - expect(locales, contains('de')); - expect(locales, contains('zh_cn')); - expect(locales, contains('ru')); - expect(locales, contains('uk')); - expect(locales, contains('az')); - }); - }); - - group('Test locale if available', () { - test('test is unavailable locale exists', () async { - try { - await Jiffy.locale('english'); - } catch (e) { - expect(e.toString(), - 'JiffyException: The locale "english" does not exist in Jiffy, run Jiffy.getAllAvailableLocales() for more locales'); - } - }); - }); - - group('Test for all relative date locales', () { - var jiffy1 = Jiffy(); - var jiffy2 = Jiffy()..add(duration: Duration(seconds: 1)); - var jiffy3 = Jiffy()..subtract(duration: Duration(minutes: 1)); - var jiffy5 = Jiffy()..subtract(duration: Duration(minutes: 10)); - var jiffy6 = Jiffy()..subtract(duration: Duration(hours: 1)); - var jiffy7 = Jiffy()..subtract(duration: Duration(hours: 10)); - var jiffy8 = Jiffy()..subtract(duration: Duration(days: 1)); - var jiffy9 = Jiffy()..subtract(duration: Duration(days: 10)); - var jiffy10 = Jiffy('2019-09-01'); - var jiffy11 = Jiffy()..subtract(months: 10); - var jiffy12 = Jiffy()..subtract(years: 1); - var jiffy13 = Jiffy()..subtract(years: 10); - - test( - 'test Jiffy().locale() method with parsing ar locale should return correct date time in ar locale', - () async { - var locale = await Jiffy.locale('ar'); - expect(jiffy1.fromNow(), 'منذ ثانية واحدة'); - expect(jiffy2.fromNow(), 'بعد ثانية واحدة'); - expect(jiffy3.fromNow(), 'منذ دقيقة واحدة'); - expect(jiffy5.fromNow(), 'منذ ۱۰ دقائق '); - expect(jiffy6.fromNow(), 'منذ ساعة واحدة'); - expect(jiffy7.fromNow(), 'منذ ۱۰ ساعات '); - expect(jiffy8.fromNow(), 'منذ يوم واحد'); - expect(jiffy9.fromNow(), 'منذ ۱۰ ايام '); - expect(jiffy10.from(Jiffy([2019, 10, 1])), 'منذ شهر واحد'); - expect(jiffy11.fromNow(), 'منذ ۱۰ اشهر '); - expect(jiffy12.fromNow(), 'منذ عام واحد'); - expect(jiffy13.fromNow(), 'منذ ۱۰ أعوام '); - expect(locale.startOfWeek(), StartOfWeek.SATURDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing ar-dz/kw/ma/tn locale should return correct date time in ar-dz locale', - () async { - var locale = await Jiffy.locale('ar_dz'); - expect(jiffy1.fromNow(), 'منذ ثوان'); - expect(jiffy2.fromNow(), 'في ثوان'); - expect(jiffy3.fromNow(), 'منذ دقيقة'); - expect(jiffy5.fromNow(), 'منذ 10 دقائق '); - expect(jiffy6.fromNow(), 'منذ ساعة'); - expect(jiffy7.fromNow(), 'منذ 10 ساعات '); - expect(jiffy8.fromNow(), 'منذ يوم'); - expect(jiffy9.fromNow(), 'منذ 10 أيام '); - expect(jiffy10.from(Jiffy('2019-10-01')), 'منذ شهر'); - expect(jiffy11.fromNow(), 'منذ 10 أشهر '); - expect(jiffy12.fromNow(), 'منذ سنة'); - expect(jiffy13.fromNow(), 'منذ 10 سنوات '); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing ar-sa locale should return correct date time in ar-sa locale', - () async { - var locale = await Jiffy.locale('ar_sa'); - expect(jiffy1.fromNow(), 'منذ ثوان'); - expect(jiffy2.fromNow(), 'في ثوان'); - expect(jiffy3.fromNow(), 'منذ دقيقة'); - expect(jiffy5.fromNow(), 'منذ ۱۰ دقائق '); - expect(jiffy6.fromNow(), 'منذ ساعة'); - expect(jiffy7.fromNow(), 'منذ ۱۰ ساعات '); - expect(jiffy8.fromNow(), 'منذ يوم'); - expect(jiffy9.fromNow(), 'منذ ۱۰ أيام '); - expect(jiffy10.from(Jiffy([2019, 10, 1])), 'منذ شهر'); - expect(jiffy11.fromNow(), 'منذ ۱۰ أشهر '); - expect(jiffy12.fromNow(), 'منذ سنة'); - expect(jiffy13.fromNow(), 'منذ ۱۰ سنوات '); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing de/de-at/de-ch locale should return correct date time in de/de-at/de-ch locale', - () async { - var locale = await Jiffy.locale('de'); - expect(jiffy1.fromNow(), 'vor ein paar Sekunden'); - expect(jiffy2.fromNow(), 'in ein paar Sekunden'); - expect(jiffy3.fromNow(), 'vor einer Minute'); - expect(jiffy5.fromNow(), 'vor 10 Minuten'); - expect(jiffy6.fromNow(), 'vor einer Stunde'); - expect(jiffy7.fromNow(), 'vor 10 Stunden'); - expect(jiffy8.fromNow(), 'vor einem Tag'); - expect(jiffy9.fromNow(), 'vor 10 Tagen'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'vor einem Monat'); - expect(jiffy11.fromNow(), 'vor 10 Monaten'); - expect(jiffy12.fromNow(), 'vor einem Jahr'); - expect(jiffy13.fromNow(), 'vor 10 Jahren'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['.', '.', '.', '.']); - }); - test( - 'test Jiffy.locale() method with parsing en locale should return correct date time in en locale', - () async { - var locale = await Jiffy.locale('en'); - expect(jiffy1.fromNow(), 'a few seconds ago'); - expect(jiffy2.fromNow(), 'in a few seconds'); - expect(jiffy3.fromNow(), 'a minute ago'); - expect(jiffy5.fromNow(), '10 minutes ago'); - expect(jiffy6.fromNow(), 'an hour ago'); - expect(jiffy7.fromNow(), '10 hours ago'); - expect(jiffy8.fromNow(), 'a day ago'); - expect(jiffy9.fromNow(), '10 days ago'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'a month ago'); - expect(jiffy11.fromNow(), '10 months ago'); - expect(jiffy12.fromNow(), 'a year ago'); - expect(jiffy13.fromNow(), '10 years ago'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), ['st', 'nd', 'rd', 'th']); - }); - test( - 'test Jiffy.locale() method with parsing id locale should return correct date time in id locale', - () async { - var locale = await Jiffy.locale('id'); - expect(jiffy1.fromNow(), 'beberapa detik yang lalu'); - expect(jiffy2.fromNow(), 'dalam beberapa detik'); - expect(jiffy3.fromNow(), 'satu menit yang lalu'); - expect(jiffy5.fromNow(), '10 menit yang lalu'); - expect(jiffy6.fromNow(), 'satu jam yang lalu'); - expect(jiffy7.fromNow(), '10 jam yang lalu'); - expect(jiffy8.fromNow(), 'satu hari yang lalu'); - expect(jiffy9.fromNow(), '10 hari yang lalu'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'satu bulan yang lalu'); - expect(jiffy11.fromNow(), '10 bulan yang lalu'); - expect(jiffy12.fromNow(), 'satu tahun yang lalu'); - expect(jiffy13.fromNow(), '10 tahun yang lalu'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing es locale should return correct date time in es locale', - () async { - var locale = await Jiffy.locale('es'); - expect(jiffy1.fromNow(), 'hace un momento'); - expect(jiffy2.fromNow(), 'en un momento'); - expect(jiffy3.fromNow(), 'hace un minuto'); - expect(jiffy5.fromNow(), 'hace 10 minutos'); - expect(jiffy6.fromNow(), 'hace una hora'); - expect(jiffy7.fromNow(), 'hace 10 horas'); - expect(jiffy8.fromNow(), 'hace un día'); - expect(jiffy9.fromNow(), 'hace 10 días'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'hace un mes'); - expect(jiffy11.fromNow(), 'hace 10 meses'); - expect(jiffy12.fromNow(), 'hace un año'); - expect(jiffy13.fromNow(), 'hace 10 años'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['º', 'º', 'º', 'º']); - }); - test( - 'test Jiffy.locale() method with parsing fr locale should return correct date time in fr locale', - () async { - var locale = await Jiffy.locale('fr'); - expect(jiffy1.fromNow(), 'il y a quelques secondes'); - expect(jiffy2.fromNow(), 'dans quelques secondes'); - expect(jiffy3.fromNow(), 'il y a une minute'); - expect(jiffy5.fromNow(), 'il y a 10 minutes'); - expect(jiffy6.fromNow(), 'il y a une heure'); - expect(jiffy7.fromNow(), 'il y a 10 heures'); - expect(jiffy8.fromNow(), 'il y a un jour'); - expect(jiffy9.fromNow(), 'il y a 10 jours'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'il y a un mois'); - expect(jiffy11.fromNow(), 'il y a 10 mois'); - expect(jiffy12.fromNow(), 'il y a un an'); - expect(jiffy13.fromNow(), 'il y a 10 ans'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['er', '', '', '']); - }); - test( - 'test Jiffy.locale() method with parsing hi locale should return correct date time in hi locale', - () async { - var locale = await Jiffy.locale('hi'); - expect(jiffy1.fromNow(), 'कुछ ही क्षण पहले'); - expect(jiffy2.fromNow(), 'कुछ ही क्षण में'); - expect(jiffy3.fromNow(), 'एक मिनट पहले'); - expect(jiffy5.fromNow(), '10 मिनट पहले'); - expect(jiffy6.fromNow(), 'एक घंटा पहले'); - expect(jiffy7.fromNow(), '10 घंटे पहले'); - expect(jiffy8.fromNow(), 'एक दिन पहले'); - expect(jiffy9.fromNow(), '10 दिन पहले'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'एक महीने पहले'); - expect(jiffy11.fromNow(), '10 महीने पहले'); - expect(jiffy12.fromNow(), 'एक वर्ष पहले'); - expect(jiffy13.fromNow(), '10 वर्ष पहले'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing it locale should return correct date time in it locale', - () async { - var locale = await Jiffy.locale('it'); - expect(jiffy1.fromNow(), 'alcuni secondi fa'); - expect(jiffy2.fromNow(), 'tra alcuni secondi'); - expect(jiffy3.fromNow(), 'un minuto fa'); - expect(jiffy5.fromNow(), '10 minuti fa'); - expect(jiffy6.fromNow(), 'un\'ora fa'); - expect(jiffy7.fromNow(), '10 ore fa'); - expect(jiffy8.fromNow(), 'un giorno fa'); - expect(jiffy9.fromNow(), '10 giorni fa'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'un mese fa'); - expect(jiffy11.fromNow(), '10 mesi fa'); - expect(jiffy12.fromNow(), 'un anno fa'); - expect(jiffy13.fromNow(), '10 anni fa'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['º', 'º', 'º', 'º']); - }); - test( - 'test Jiffy.locale() method with parsing ja locale should return correct date time in ja locale', - () async { - var locale = await Jiffy.locale('ja'); - expect(jiffy1.fromNow(), '数秒前'); - expect(jiffy2.fromNow(), '数秒後'); - expect(jiffy3.fromNow(), '1分前'); - expect(jiffy5.fromNow(), '10分前'); - expect(jiffy6.fromNow(), '1時間前'); - expect(jiffy7.fromNow(), '10時間前'); - expect(jiffy8.fromNow(), '1日前'); - expect(jiffy9.fromNow(), '10日前'); - expect(jiffy10.from(Jiffy('2019-10-01')), '1ヶ月前'); - expect(jiffy11.fromNow(), '10ヶ月前'); - expect(jiffy12.fromNow(), '1年前'); - expect(jiffy13.fromNow(), '10年前'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), ['日', '日', '日', '日']); - }); - test( - 'test Jiffy.locale() method with parsing ko locale should return correct date time in ko locale', - () async { - var locale = await Jiffy.locale('ko'); - expect(jiffy1.fromNow(), '몇 초 전'); - expect(jiffy2.fromNow(), '몇 초 후'); - expect(jiffy3.fromNow(), '1분 전'); - expect(jiffy5.fromNow(), '10분 전'); - expect(jiffy6.fromNow(), '한 시간 전'); - expect(jiffy7.fromNow(), '10시간 전'); - expect(jiffy8.fromNow(), '하루 전'); - expect(jiffy9.fromNow(), '10일 전'); - expect(jiffy10.from(Jiffy('2019-10-01')), '한 달 전'); - expect(jiffy11.fromNow(), '10달 전'); - expect(jiffy12.fromNow(), '일 년 전'); - expect(jiffy13.fromNow(), '10년 전'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), ['일', '일', '일', '일']); - }); - test( - 'test Jiffy.locale() method with parsing pt locale should return correct date time in pt locale', - () async { - var locale = await Jiffy.locale('pt'); - expect(jiffy1.fromNow(), 'há segundos'); - expect(jiffy2.fromNow(), 'em segundos'); - expect(jiffy3.fromNow(), 'há um minuto'); - expect(jiffy5.fromNow(), 'há 10 minutos'); - expect(jiffy6.fromNow(), 'há uma hora'); - expect(jiffy7.fromNow(), 'há 10 horas'); - expect(jiffy8.fromNow(), 'há um dia'); - expect(jiffy9.fromNow(), 'há 10 dias'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'há um mês'); - expect(jiffy11.fromNow(), 'há 10 meses'); - expect(jiffy12.fromNow(), 'há um ano'); - expect(jiffy13.fromNow(), 'há 10 anos'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['º', 'º', 'º', 'º']); - }); - test( - 'test Jiffy.locale() method with parsing ru locale should return correct date time in ru locale', - () async { - var locale = await Jiffy.locale('ru'); - expect(jiffy1.fromNow(), 'несколько секунд назад'); - expect(jiffy2.fromNow(), 'через несколько секунд'); - expect(jiffy3.fromNow(), 'минуту назад'); - expect(jiffy5.fromNow(), '10 минут назад'); - expect(jiffy6.fromNow(), 'час назад'); - expect(jiffy7.fromNow(), '10 часов назад'); - expect(jiffy8.fromNow(), 'день назад'); - expect(jiffy9.fromNow(), '10 дней назад'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'месяц назад'); - expect(jiffy11.fromNow(), '10 месяцев назад'); - expect(jiffy12.fromNow(), 'год назад'); - expect(jiffy13.fromNow(), '10 лет назад'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing uk locale should return correct date time in uk locale', - () async { - var locale = await Jiffy.locale('uk'); - expect(jiffy1.fromNow(), 'декілька секунд тому'); - expect(jiffy2.fromNow(), 'через декілька секунд'); - expect(jiffy3.fromNow(), 'хвилину тому'); - expect(jiffy5.fromNow(), '10 хвилин тому'); - expect(jiffy6.fromNow(), 'годину тому'); - expect(jiffy7.fromNow(), '10 годин тому'); - expect(jiffy8.fromNow(), 'день тому'); - expect(jiffy9.fromNow(), '10 днів тому'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'місяць тому'); - expect(jiffy11.fromNow(), '10 місяців тому'); - expect(jiffy12.fromNow(), 'рік тому'); - expect(jiffy13.fromNow(), '10 років тому'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing az locale should return correct date time in az locale', - () async { - var locale = await Jiffy.locale('az'); - expect(jiffy1.fromNow(), 'bir neçə saniyə geri'); - expect(jiffy2.fromNow(), 'bir neçə saniyə sonra'); - expect(jiffy3.fromNow(), 'dəqiqə geri'); - expect(jiffy5.fromNow(), '10 dəqiqə geri'); - expect(jiffy6.fromNow(), 'saat geri'); - expect(jiffy7.fromNow(), '10 saat geri'); - expect(jiffy8.fromNow(), 'gün geri'); - expect(jiffy9.fromNow(), '10 gün geri'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'ay geri'); - expect(jiffy11.fromNow(), '10 ay geri'); - expect(jiffy12.fromNow(), 'il geri'); - expect(jiffy13.fromNow(), '10 il geri'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing zh-cn locale should return correct date time in zh-cn locale', - () async { - var locale = await Jiffy.locale('zh'); - expect(jiffy1.fromNow(), '几秒前'); - expect(jiffy2.fromNow(), '几秒内'); - expect(jiffy3.fromNow(), '1 分钟前'); - expect(jiffy5.fromNow(), '10 分钟前'); - expect(jiffy6.fromNow(), '1 小时前'); - expect(jiffy7.fromNow(), '10 小时前'); - expect(jiffy8.fromNow(), '1 天前'); - expect(jiffy9.fromNow(), '10 天前'); - expect(jiffy10.from(Jiffy('2019-10-01')), '1 个月前'); - expect(jiffy11.fromNow(), '10 个月前'); - expect(jiffy12.fromNow(), '1 年前'); - expect(jiffy13.fromNow(), '10 年前'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), ['日', '日', '日', '日']); - }); - test( - 'test Jiffy.locale() method with parsing zh-hk/tw locale should return correct date time in zh-hk/tw locale', - () async { - var locale = await Jiffy.locale('zh_hk'); - expect(jiffy1.fromNow(), '幾秒前'); - expect(jiffy2.fromNow(), '幾秒内'); - expect(jiffy3.fromNow(), '1 分鐘前'); - expect(jiffy5.fromNow(), '10 分鐘前'); - expect(jiffy6.fromNow(), '1 小時前'); - expect(jiffy7.fromNow(), '10 小時前'); - expect(jiffy8.fromNow(), '1 天前'); - expect(jiffy9.fromNow(), '10 天前'); - expect(jiffy10.from(Jiffy('2019-10-01')), '1 個月前'); - expect(jiffy11.fromNow(), '10 個月前'); - expect(jiffy12.fromNow(), '1 年前'); - expect(jiffy13.fromNow(), '10 年前'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), ['日', '日', '日', '日']); - }); - test( - 'test Jiffy.locale() method with parsing pl locale should return correct date time in pl locale', - () async { - var locale = await Jiffy.locale('pl'); - expect(jiffy1.fromNow(), 'kilka sekund temu'); - expect(jiffy2.fromNow(), 'za kilka sekund'); - expect(jiffy3.fromNow(), 'minutę temu'); - expect(jiffy5.fromNow(), '10 minut temu'); - expect(jiffy6.fromNow(), 'godzinę temu'); - expect(jiffy7.fromNow(), '10 godzin temu'); - expect(jiffy8.fromNow(), '1 dzień temu'); - expect(jiffy9.fromNow(), '10 dni temu'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'miesiąc temu'); - expect(jiffy11.fromNow(), '10 miesięcy temu'); - expect(jiffy12.fromNow(), 'rok temu'); - expect(jiffy13.fromNow(), '10 lat temu'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['.', '.', '.', '.']); - }); - test( - 'test Jiffy.locale() method with parsing tr locale should return correct date time in tr locale', - () async { - var locale = await Jiffy.locale('tr'); - expect(jiffy1.fromNow(), 'birkaç saniye önce'); - expect(jiffy2.fromNow(), 'birkaç saniye içinde'); - expect(jiffy3.fromNow(), 'bir dakika önce'); - expect(jiffy5.fromNow(), '10 dakika önce'); - expect(jiffy6.fromNow(), 'bir saat önce'); - expect(jiffy7.fromNow(), '10 saat önce'); - expect(jiffy8.fromNow(), 'bir gün önce'); - expect(jiffy9.fromNow(), '10 gün önce'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'bir ay önce'); - expect(jiffy11.fromNow(), '10 ay önce'); - expect(jiffy12.fromNow(), 'bir yıl önce'); - expect(jiffy13.fromNow(), '10 yıl önce'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing sv locale should return correct date time in sv locale', - () async { - var locale = await Jiffy.locale('sv'); - expect(jiffy1.fromNow(), 'några sekunder sedan'); - expect(jiffy2.fromNow(), 'om några sekunder'); - expect(jiffy3.fromNow(), 'en minut sedan'); - expect(jiffy5.fromNow(), '10 minuter sedan'); - expect(jiffy6.fromNow(), 'en timme sedan'); - expect(jiffy7.fromNow(), '10 timmar sedan'); - expect(jiffy8.fromNow(), 'en dag sedan'); - expect(jiffy9.fromNow(), '10 dagar sedan'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'en månad sedan'); - expect(jiffy11.fromNow(), '10 månader sedan'); - expect(jiffy12.fromNow(), 'ett år sedan'); - expect(jiffy13.fromNow(), '10 år sedan'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing nb locale should return correct date time in nb locale', - () async { - var locale = await Jiffy.locale('nb'); - expect(jiffy1.fromNow(), 'noen sekunder siden'); - expect(jiffy2.fromNow(), 'om noen sekunder'); - expect(jiffy3.fromNow(), 'ett minutt siden'); - expect(jiffy5.fromNow(), '10 minutter siden'); - expect(jiffy6.fromNow(), 'en time siden'); - expect(jiffy7.fromNow(), '10 timer siden'); - expect(jiffy8.fromNow(), 'en dag siden'); - expect(jiffy9.fromNow(), '10 dager siden'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'en måned siden'); - expect(jiffy11.fromNow(), '10 måneder siden'); - expect(jiffy12.fromNow(), 'ett år siden'); - expect(jiffy13.fromNow(), '10 år siden'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['.', '.', '.', '.']); - }); - test( - 'test Jiffy.locale() method with parsing fa locale should return correct date time in fa locale', - () async { - var locale = await Jiffy.locale('fa'); - expect(jiffy1.fromNow(), 'چند ثانیه پیش'); - expect(jiffy2.fromNow(), 'چند ثانیه بعد'); - expect(jiffy3.fromNow(), 'یک دقیقه پیش'); - expect(jiffy5.fromNow(), '۱۰ دقیقه پیش'); - expect(jiffy6.fromNow(), 'یک ساعت پیش'); - expect(jiffy7.fromNow(), '۱۰ ساعت پیش'); - expect(jiffy8.fromNow(), 'یک روز پیش'); - expect(jiffy9.fromNow(), '۱۰ روز پیش'); - expect(jiffy10.from(Jiffy([2019, 10, 1])), 'یک ماه پیش'); - expect(jiffy11.fromNow(), '۱۰ ماه پیش'); - expect(jiffy12.fromNow(), 'یک سال پیش'); - expect(jiffy13.fromNow(), '۱۰ سال پیش'); - expect(locale.startOfWeek(), StartOfWeek.SATURDAY); - expect(locale.ordinals(), ['م', 'م', 'م', 'م']); - }); - test( - 'test Jiffy.locale() method with parsing bn locale should return correct date time in bn locale', - () async { - var locale = await Jiffy.locale('bn'); - expect(jiffy1.fromNow(), 'কিছু মুহূর্ত আগে'); - expect(jiffy2.fromNow(), 'কিছু মুহূর্ত পরে'); - expect(jiffy3.fromNow(), 'এক মিনিট আগে'); - expect(jiffy5.fromNow(), '১০ মিনিট আগে'); - expect(jiffy6.fromNow(), 'এক ঘন্টা আগে'); - expect(jiffy7.fromNow(), '১০ ঘন্টা আগে'); - expect(jiffy8.fromNow(), 'এক দিন আগে'); - expect(jiffy9.fromNow(), '১০ দিন আগে'); - expect(jiffy10.from(Jiffy([2019, 10, 01])), 'এক মাস আগে'); - expect(jiffy11.fromNow(), '১০ মাস আগে'); - expect(jiffy12.fromNow(), 'এক বছর আগে'); - expect(jiffy13.fromNow(), '১০ বছর আগে'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), null); - }); - test( - 'test Jiffy.locale() method with parsing nl locale should return correct date time in nl locale', - () async { - var locale = await Jiffy.locale('nl'); - expect(jiffy1.fromNow(), 'een paar seconden geleden'); - expect(jiffy2.fromNow(), 'over een paar seconden'); - expect(jiffy3.fromNow(), 'een minuut geleden'); - expect(jiffy5.fromNow(), '10 minuten geleden'); - expect(jiffy6.fromNow(), 'een uur geleden'); - expect(jiffy7.fromNow(), '10 uur geleden'); - expect(jiffy8.fromNow(), 'een dag geleden'); - expect(jiffy9.fromNow(), '10 dagen geleden'); - expect(jiffy10.from(Jiffy('2019-10-01')), 'een maand geleden'); - expect(jiffy11.fromNow(), '10 maanden geleden'); - expect(jiffy12.fromNow(), 'een jaar geleden'); - expect(jiffy13.fromNow(), '10 jaar geleden'); - expect(locale.startOfWeek(), StartOfWeek.MONDAY); - expect(locale.ordinals(), ['.', '.', '.', '.']); - }); - test( - 'test Jiffy.locale() method with parsing th locale should return correct date time in th locale', - () async { - var locale = await Jiffy.locale('th'); - expect(jiffy1.fromNow(), 'ไม่กี่วินาทีที่แล้ว'); - expect(jiffy2.fromNow(), 'อีกไม่กี่วินาที'); - expect(jiffy3.fromNow(), '1 นาทีที่แล้ว'); - expect(jiffy5.fromNow(), '10 นาทีที่แล้ว'); - expect(jiffy6.fromNow(), '1 ชั่วโมงที่แล้ว'); - expect(jiffy7.fromNow(), '10 ชั่วโมงที่แล้ว'); - expect(jiffy8.fromNow(), '1 วันที่แล้ว'); - expect(jiffy9.fromNow(), '10 วันที่แล้ว'); - expect(jiffy10.from(Jiffy([2019, 10, 01])), '1 เดือนที่แล้ว'); - expect(jiffy11.fromNow(), '10 เดือนที่แล้ว'); - expect(jiffy12.fromNow(), '1 ปีที่แล้ว'); - expect(jiffy13.fromNow(), '10 ปีที่แล้ว'); - expect(locale.startOfWeek(), StartOfWeek.SUNDAY); - expect(locale.ordinals(), null); - }); - }); -} diff --git a/test/src/default_display_test.dart b/test/src/default_display_test.dart new file mode 100644 index 0000000..9939a00 --- /dev/null +++ b/test/src/default_display_test.dart @@ -0,0 +1,194 @@ +import 'package:jiffy/src/default_display.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + final underTest = DefaultDisplay(); + + group('Test displaying default datetime', () { + for (var testData in defaultDisplayTestData(underTest)) { + test('Should successfully display default datetime', () { + // Setup + final dateTime = (testData['dateTime'] as DateTime); + + // Execute + final actualDateTimeDisplay = + (testData['function'] as Function(DateTime)).call(dateTime); + + // Verify + expect(actualDateTimeDisplay, testData['expectedDateTimeDisplay']); + }); + } + }); +} + +List> defaultDisplayTestData( + DefaultDisplay defaultDisplay) { + return [ + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.E(dateTime), + 'expectedDateTimeDisplay': 'Tue' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.EEEE(dateTime), + 'expectedDateTimeDisplay': 'Tuesday' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.Md(dateTime), + 'expectedDateTimeDisplay': '9/23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MEd(dateTime), + 'expectedDateTimeDisplay': 'Tue, 9/23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MMM(dateTime), + 'expectedDateTimeDisplay': 'Sep' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MMMd(dateTime), + 'expectedDateTimeDisplay': 'Sep 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MMMEd(dateTime), + 'expectedDateTimeDisplay': 'Tue, Sep 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MMMM(dateTime), + 'expectedDateTimeDisplay': 'September' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MMMMd(dateTime), + 'expectedDateTimeDisplay': 'September 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.MMMMEEEEd(dateTime), + 'expectedDateTimeDisplay': 'Tuesday, September 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.QQQ(dateTime), + 'expectedDateTimeDisplay': 'Q3' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.QQQQ(dateTime), + 'expectedDateTimeDisplay': '3rd quarter' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yM(dateTime), + 'expectedDateTimeDisplay': '9/1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMd(dateTime), + 'expectedDateTimeDisplay': '9/23/1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMEd(dateTime), + 'expectedDateTimeDisplay': 'Tue, 9/23/1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMM(dateTime), + 'expectedDateTimeDisplay': 'Sep 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMd(dateTime), + 'expectedDateTimeDisplay': 'Sep 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMdjm(dateTime), + 'expectedDateTimeDisplay': 'Sep 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMEd(dateTime), + 'expectedDateTimeDisplay': 'Tue, Sep 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMEdjm(dateTime), + 'expectedDateTimeDisplay': 'Tue, Sep 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMM(dateTime), + 'expectedDateTimeDisplay': 'September 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMMd(dateTime), + 'expectedDateTimeDisplay': 'September 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMMdjm(dateTime), + 'expectedDateTimeDisplay': 'September 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMMEEEEd(dateTime), + 'expectedDateTimeDisplay': 'Tuesday, September 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yMMMMEEEEdjm(dateTime), + 'expectedDateTimeDisplay': 'Tuesday, September 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yQQQ(dateTime), + 'expectedDateTimeDisplay': 'Q3 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.yQQQQ(dateTime), + 'expectedDateTimeDisplay': '3rd quarter 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.H(dateTime), + 'expectedDateTimeDisplay': '12' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.Hm(dateTime), + 'expectedDateTimeDisplay': '12:11' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.Hms(dateTime), + 'expectedDateTimeDisplay': '12:11:22' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.j(dateTime), + 'expectedDateTimeDisplay': '12 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.jm(dateTime), + 'expectedDateTimeDisplay': '12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (DateTime dateTime) => defaultDisplay.jms(dateTime), + 'expectedDateTimeDisplay': '12:11:22 PM' + }, + ]; +} diff --git a/test/src/display_test.dart b/test/src/display_test.dart new file mode 100644 index 0000000..1a053d4 --- /dev/null +++ b/test/src/display_test.dart @@ -0,0 +1,829 @@ +import 'package:jiffy/src/display.dart'; +import 'package:jiffy/src/enums/unit.dart'; +import 'package:jiffy/src/getter.dart'; +import 'package:jiffy/src/locale/locales/en_locale.dart'; +import 'package:jiffy/src/manipulator.dart'; +import 'package:jiffy/src/query.dart'; +import 'package:jiffy/src/utils/jiffy_exception.dart'; +import 'package:test/test.dart'; + +void main() { + final getter = Getter(); + final manipulator = Manipulator(getter); + final query = Query(getter, manipulator); + + final underTest = Display(getter, manipulator, query); + + test('Should successfully format datetime is iso when pattern not provided', + () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + + final expectedFormat = '1997-09-23T12:11:22.123456'; + + // Execute + final actualFormat = underTest.formatToISO8601(dateTime); + + // Verify + expect(actualFormat, expectedFormat); + }); + + group('Test format with pattern', () { + for (var testData in formatWithPatternDateTimeTestData()) { + test('Should successfully format datetime when pattern is provided', () { + // Setup + final locale = EnLocale(); + + // Execute + final actualFormat = + underTest.format(testData['dateTime'], testData['pattern'], locale); + + // Verify + expect(actualFormat, testData['expectedFormat']); + }); + } + + for (var testData in formatWithEscapedPatternDateTimeTestData()) { + test('Should successfully format datetime with escaped pattern', () { + // Setup + final locale = EnLocale(); + + // Execute + final actualFormat = + underTest.format(testData['dateTime'], testData['pattern'], locale); + + // Verify + expect(actualFormat, testData['expectedFormat']); + }); + } + + for (var testData in formatWithOrdinalPatternDateTimeTestData()) { + test('Should successfully format datetime with ordinal pattern', () { + // Setup + final locale = EnLocale(); + + // Execute + final actualFormat = + underTest.format(testData['dateTime'], testData['pattern'], locale); + + // Verify + expect(actualFormat, testData['expectedFormat']); + }); + } + + test('Should throw JiffyException if provided pattern in blank', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final pattern = ''; + final locale = EnLocale(); + + final expectedExceptionMessage = 'The provided pattern for datetime ' + '`$dateTime` cannot be blank'; + + // Execute and Verify + expect( + () => underTest.format(dateTime, pattern, locale), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + + test('Should throw JiffyException if provided pattern is invalid', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final pattern = 'invalid-pattern'; + final locale = EnLocale(); + + final expectedExceptionMessage = + 'The pattern `$pattern` might be invalid'; + + // Execute and Verify + expect( + () => underTest.format(dateTime, pattern, locale), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + }); + + group('Test from as relative between two datetime', () { + for (var testData in fromAsRelativeDateTimeTestData()) { + test('Should successfully get from as relative datetime', () { + final locale = EnLocale(); + + final actualFromAsRelativeDateTime = underTest.fromAsRelativeDateTime( + testData['firstDateTime'], testData['secondDateTime'], locale); + + expect(actualFromAsRelativeDateTime, + testData['expectedFromAsRelativeDateTime']); + }); + } + + for (var testData in toAsRelativeDateTimeTestData()) { + test('Should successfully get to as relative datetime', () { + final locale = EnLocale(); + + final actualToAsRelativeDateTime = underTest.toAsRelativeDateTime( + testData['firstDateTime'], testData['secondDateTime'], locale); + + expect(actualToAsRelativeDateTime, + testData['expectedToAsRelativeDateTime']); + }); + } + }); + + group('Test diff between two datetime', () { + for (var testData in diffDateTimeTestData()) { + test('Should successfully get difference between two datetime', () { + // Setup + final asFloat = true; + + // Execute + final actualDifference = underTest.diff(testData['firstDateTime'], + testData['secondDateTime'], testData['unit'], asFloat); + + // Verify + expect(actualDifference, testData['expectedDifference']); + }); + } + + test('Should successfully get difference when float is disabled', () { + // Setup + final firstDateTime = DateTime(2022, 12, 5); + final secondDateTime = DateTime(2022, 12, 8); + final unit = Unit.week; + final asFloat = false; + + final expectedDifference = -0.42857142857142855; + + // Execute + final actualDifference = + underTest.diff(firstDateTime, secondDateTime, unit, asFloat); + + // Verify + expect(actualDifference, expectedDifference); + }); + }); +} + +List> formatWithPatternDateTimeTestData() { + return [ + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'pattern': 'yyyy MMM dd hh:mm:ss', + 'expectedFormat': '1997 Sep 23 12:11:22' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'pattern': 'yyyy MMM, dd hh:mm a', + 'expectedFormat': '1997 Sep, 23 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 11, 11, 22, 123, 456), + 'pattern': 'yyyy MMM dd hh:mm a', + 'expectedFormat': '1997 Sep 23 11:11 AM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 11, 11, 22, 123, 456), + 'pattern': 'do MMMM', + 'expectedFormat': '23rd September' + }, + { + 'dateTime': DateTime(1997, 9, 23, 11, 11, 22, 123, 456), + 'pattern': 'EEEE', + 'expectedFormat': 'Tuesday' + } + ]; +} + +List> formatWithEscapedPatternDateTimeTestData() { + return [ + { + 'dateTime': DateTime(1969, 7, 20, 20, 18, 04), + 'pattern': '[The moon landing was on] do MMMM, yyyy', + 'expectedFormat': 'The moon landing was on 20th July, 1969' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'pattern': '[Today\'s date is] do [in the month of] MMMM', + 'expectedFormat': 'Today\'s date is 23rd in the month of September' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'pattern': '[It\'s] hh [o\'clock]', + 'expectedFormat': 'It\'s 12 o\'clock' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'pattern': "[It's] hh [o'clock]", + 'expectedFormat': "It's 12 o'clock" + } + ]; +} + +List> formatWithOrdinalPatternDateTimeTestData() { + return [ + { + 'dateTime': DateTime(2022, 1, 1), + 'pattern': 'do', + 'expectedFormat': '1st' + }, + { + 'dateTime': DateTime(2022, 1, 12), + 'pattern': 'do', + 'expectedFormat': '12th' + }, + { + 'dateTime': DateTime(2022, 1, 21), + 'pattern': 'do', + 'expectedFormat': '21st' + }, + { + 'dateTime': DateTime(2022, 1, 2), + 'pattern': 'do', + 'expectedFormat': '2nd' + }, + { + 'dateTime': DateTime(2022, 1, 3), + 'pattern': 'do', + 'expectedFormat': '3rd' + }, + { + 'dateTime': DateTime(2022, 1, 4), + 'pattern': 'do', + 'expectedFormat': '4th' + }, + { + 'dateTime': DateTime(2022, 1, 11), + 'pattern': 'do', + 'expectedFormat': '11th' + } + ]; +} + +List> toAsRelativeDateTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 457), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 457), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'expectedToAsRelativeDateTime': 'a few seconds ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 124), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 124), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'expectedToAsRelativeDateTime': 'a few seconds ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedToAsRelativeDateTime': 'a minute ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedToAsRelativeDateTime': 'in a minute' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedToAsRelativeDateTime': 'a few seconds ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 40), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedToAsRelativeDateTime': '40 minutes ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 40), + 'expectedToAsRelativeDateTime': 'in 40 minutes' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedToAsRelativeDateTime': 'an hour ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedToAsRelativeDateTime': 'in an hour' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 12), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11), + 'expectedToAsRelativeDateTime': 'a minute ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 10), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11), + 'expectedToAsRelativeDateTime': 'in a minute' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 23), + 'secondDateTime': DateTime(1997, 10, 23, 0), + 'expectedToAsRelativeDateTime': '23 hours ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 0), + 'secondDateTime': DateTime(1997, 10, 23, 23), + 'expectedToAsRelativeDateTime': 'in 23 hours' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 13), + 'secondDateTime': DateTime(1997, 10, 23, 12), + 'expectedToAsRelativeDateTime': 'an hour ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12), + 'secondDateTime': DateTime(1997, 10, 23, 12), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 11), + 'secondDateTime': DateTime(1997, 10, 23, 12), + 'expectedToAsRelativeDateTime': 'in an hour' + }, + { + 'firstDateTime': DateTime(1997, 10, 24), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedToAsRelativeDateTime': 'a day ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 24), + 'expectedToAsRelativeDateTime': 'in a day' + }, + { + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 24), + 'expectedToAsRelativeDateTime': 'in 4 days' + }, + { + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedToAsRelativeDateTime': '3 days ago' + }, + { + 'firstDateTime': DateTime(1997, 11), + 'secondDateTime': DateTime(1997, 10), + 'expectedToAsRelativeDateTime': 'a month ago' + }, + { + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 10), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 11), + 'expectedToAsRelativeDateTime': 'in a month' + }, + { + 'firstDateTime': DateTime(1997, 8), + 'secondDateTime': DateTime(1997, 11), + 'expectedToAsRelativeDateTime': 'in 3 months' + }, + { + 'firstDateTime': DateTime(1997, 11), + 'secondDateTime': DateTime(1997, 8), + 'expectedToAsRelativeDateTime': '3 months ago' + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedToAsRelativeDateTime': 'a year ago' + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'expectedToAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedToAsRelativeDateTime': 'in a year' + }, + { + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedToAsRelativeDateTime': 'in 3 years' + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedToAsRelativeDateTime': '3 years ago' + } + ]; +} + +List> fromAsRelativeDateTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 457), + 'expectedFromAsRelativeDateTime': 'a few seconds ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 457), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123, 456), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 124), + 'expectedFromAsRelativeDateTime': 'a few seconds ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22, 124), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22, 123), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedFromAsRelativeDateTime': 'in a minute' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedFromAsRelativeDateTime': 'a minute ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedFromAsRelativeDateTime': 'a few seconds ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 40), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedFromAsRelativeDateTime': 'in 40 minutes' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 40), + 'expectedFromAsRelativeDateTime': '40 minutes ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedFromAsRelativeDateTime': 'in an hour' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedFromAsRelativeDateTime': 'an hour ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 12), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11), + 'expectedFromAsRelativeDateTime': 'in a minute' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 11), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12, 10), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11), + 'expectedFromAsRelativeDateTime': 'a minute ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 23), + 'secondDateTime': DateTime(1997, 10, 23, 0), + 'expectedFromAsRelativeDateTime': 'in 23 hours' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 0), + 'secondDateTime': DateTime(1997, 10, 23, 23), + 'expectedFromAsRelativeDateTime': '23 hours ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 13), + 'secondDateTime': DateTime(1997, 10, 23, 12), + 'expectedFromAsRelativeDateTime': 'in an hour' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 12), + 'secondDateTime': DateTime(1997, 10, 23, 12), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23, 11), + 'secondDateTime': DateTime(1997, 10, 23, 12), + 'expectedFromAsRelativeDateTime': 'an hour ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 24), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedFromAsRelativeDateTime': 'in a day' + }, + { + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 24), + 'expectedFromAsRelativeDateTime': 'a day ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 24), + 'expectedFromAsRelativeDateTime': '4 days ago' + }, + { + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedFromAsRelativeDateTime': 'in 3 days' + }, + { + 'firstDateTime': DateTime(1997, 11), + 'secondDateTime': DateTime(1997, 10), + 'expectedFromAsRelativeDateTime': 'in a month' + }, + { + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 10), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 11), + 'expectedFromAsRelativeDateTime': 'a month ago' + }, + { + 'firstDateTime': DateTime(1997, 8), + 'secondDateTime': DateTime(1997, 11), + 'expectedFromAsRelativeDateTime': '3 months ago' + }, + { + 'firstDateTime': DateTime(1997, 11), + 'secondDateTime': DateTime(1997, 8), + 'expectedFromAsRelativeDateTime': 'in 3 months' + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedFromAsRelativeDateTime': 'in a year' + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'expectedFromAsRelativeDateTime': 'in a few seconds' + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedFromAsRelativeDateTime': 'a year ago' + }, + { + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedFromAsRelativeDateTime': '3 years ago' + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedFromAsRelativeDateTime': 'in 3 years' + } + ]; +} + +List> diffDateTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 10), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 24), + 'unit': Unit.microsecond, + 'expectedDifference': -14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 24), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 10), + 'unit': Unit.microsecond, + 'expectedDifference': 14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 10), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 24), + 'unit': Unit.millisecond, + 'expectedDifference': -14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 24), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 10), + 'unit': Unit.millisecond, + 'expectedDifference': 14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 10), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 24), + 'unit': Unit.second, + 'expectedDifference': -14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 24), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 10), + 'unit': Unit.second, + 'expectedDifference': 14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 10), + 'secondDateTime': DateTime(1997, 9, 23, 12, 24), + 'unit': Unit.minute, + 'expectedDifference': -14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 24), + 'secondDateTime': DateTime(1997, 9, 23, 12, 10), + 'unit': Unit.minute, + 'expectedDifference': 14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 10), + 'secondDateTime': DateTime(1997, 9, 23, 24), + 'unit': Unit.hour, + 'expectedDifference': -14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 24), + 'secondDateTime': DateTime(1997, 9, 23, 10), + 'unit': Unit.hour, + 'expectedDifference': 14 + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(1997, 9, 10), + 'secondDateTime': DateTime(1997, 9, 24), + 'unit': Unit.day, + 'expectedDifference': -14 + }, + { + 'firstDateTime': DateTime(1997, 9, 24), + 'secondDateTime': DateTime(1997, 9, 10), + 'unit': Unit.day, + 'expectedDifference': 14 + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 20), + 'unit': Unit.week, + 'expectedDifference': -2 + }, + { + 'firstDateTime': DateTime(2022, 12, 22), + 'secondDateTime': DateTime(2022, 12, 6), + 'unit': Unit.week, + 'expectedDifference': 2 + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 8), + 'unit': Unit.week, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(2022, 5), + 'secondDateTime': DateTime(2022, 7), + 'unit': Unit.month, + 'expectedDifference': -2 + }, + { + 'firstDateTime': DateTime(2022, 7), + 'secondDateTime': DateTime(2022, 5), + 'unit': Unit.month, + 'expectedDifference': 2 + }, + { + 'firstDateTime': DateTime(2022, 5), + 'secondDateTime': DateTime(2022, 5), + 'unit': Unit.month, + 'expectedDifference': 0 + }, + { + 'firstDateTime': DateTime(2016, 2, 29), + 'secondDateTime': DateTime(2016, 1, 30), + 'unit': Unit.month, + 'expectedDifference': 1 + }, + { + 'firstDateTime': DateTime(2016, 2, 29), + 'secondDateTime': DateTime(2016, 1, 31), + 'unit': Unit.month, + 'expectedDifference': 1 + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1999), + 'unit': Unit.year, + 'expectedDifference': -2 + }, + { + 'firstDateTime': DateTime(1999), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedDifference': 2 + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedDifference': 0 + }, + ]; +} diff --git a/test/src/getter_test.dart b/test/src/getter_test.dart new file mode 100644 index 0000000..945d776 --- /dev/null +++ b/test/src/getter_test.dart @@ -0,0 +1,298 @@ +import 'package:jiffy/src/getter.dart'; +import 'package:jiffy/src/enums/start_of_week.dart'; +import 'package:test/test.dart'; + +void main() { + final underTest = Getter(); + + group('Test basic datetime getters', () { + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + + test('Should successfully get date time', () { + // Setup + final expectedDateTime = dateTime; + + // Expected + final actualDateTime = underTest.dateTime(dateTime); + + // Verify + expect(actualDateTime, expectedDateTime); + }); + + test('Should successfully get microsecond', () { + // Setup + final expectedMicrosecond = dateTime.microsecond; + + // Execute + final actualMicrosecond = underTest.microsecond(dateTime); + + // Verify + expect(actualMicrosecond, expectedMicrosecond); + }); + + test('Should successfully get microsecondsSinceEpoch', () { + // Setup + final expectedMicrosecondsSinceEpoch = dateTime.microsecondsSinceEpoch; + + // Execute + final actualMicrosecondsSinceEpoch = + underTest.microsecondsSinceEpoch(dateTime); + + // Verify + expect(actualMicrosecondsSinceEpoch, expectedMicrosecondsSinceEpoch); + }); + + test('Should successfully get millisecond', () { + // Setup + final expectedMillisecond = dateTime.millisecond; + + // Execute + final actualMillisecond = underTest.millisecond(dateTime); + + // Verify + expect(actualMillisecond, expectedMillisecond); + }); + + test('Should successfully get millisecondsSinceEpoch', () { + // Setup + final expectedMillisecondsSinceEpoch = dateTime.millisecondsSinceEpoch; + + // Execute + final actualMillisecondsSinceEpoch = + underTest.millisecondsSinceEpoch(dateTime); + + // Verify + expect(actualMillisecondsSinceEpoch, expectedMillisecondsSinceEpoch); + }); + + test('Should successfully get second', () { + // Setup + final expectedSecond = dateTime.second; + + // Execute + final actualSecond = underTest.second(dateTime); + + // Verify + expect(actualSecond, expectedSecond); + }); + + test('Should successfully get minute', () { + // Setup + final expectedMinute = dateTime.minute; + + // Execute + final actualMinute = underTest.minute(dateTime); + + // Verify + expect(actualMinute, expectedMinute); + }); + + test('Should successfully get hour', () { + // Setup + final expectedHour = dateTime.hour; + + // Execute + final actualHour = underTest.hour(dateTime); + + // Verify + expect(actualHour, expectedHour); + }); + + test('Should successfully get date', () { + // Setup + final expectedDate = dateTime.day; + + // Execute + final actualDate = underTest.date(dateTime); + + // Verify + expect(actualDate, expectedDate); + }); + + test('Should successfully get month', () { + // Setup + final expectedMonth = dateTime.month; + + // Execute + final actualMonth = underTest.month(dateTime); + + // Verify + expect(actualMonth, expectedMonth); + }); + + test('Should successfully get year', () { + // Setup + final expectedYear = dateTime.year; + + // Execute + final actualYear = underTest.year(dateTime); + + // Verify + expect(actualYear, expectedYear); + }); + }); + + group('Test getting datetime of', () { + for (var testData in dayOfWeekTestData()) { + test('Should successfully get day of week for locales', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualDayOfWeek = + underTest.dayOfWeek(testData['dateTime'], startOfWeek); + + // Verify + expect(actualDayOfWeek, testData['expectedDayOfWeek']); + }); + } + + for (var testData in dayOfWeekWithStartOfWeekTestData()) { + test('Should successfully get day of week for locales', () { + // Execute + final actualDayOfWeek = + underTest.dayOfWeek(testData['dateTime'], testData['startOfWeek']); + + // Verify + expect(actualDayOfWeek, testData['expectedDayOfWeek']); + }); + } + + for (var testData in dayOfYearTestData()) { + test('Should successfully get day of year', () { + // Execute + final actualDayOfYear = underTest.dayOfYear(testData['dateTime']); + + // Verify + expect(actualDayOfYear, testData['expectedDayOfYear']); + }); + } + + for (var testData in weekOfYearTestData()) { + test('Should successfully get week of year', () { + // Execute + final actualWeekOfYear = + underTest.weekOfYear(testData['dateTime'], testData['startOfWeek']); + + // Verify + expect(actualWeekOfYear, testData['expectedWeekOfYear']); + }); + } + + for (var testData in quarterOfYearTestData()) { + test('Should successfully get quarter of year', () { + // Execute + final actualQuarterOfYear = + underTest.quarterOfYear(testData['dateTime']); + + // Verify + expect(actualQuarterOfYear, testData['expectedQuarterOfYear']); + }); + } + }); + + for (var testData in daysInMonthTestData()) { + test('Should successfully get days in a month', () { + // Execute + final actualDayInMonth = underTest.daysInMonth(testData['dateTime']); + + // Verify + expect(actualDayInMonth, testData['expectedDayInMonth']); + }); + } + + test('Should successfully get all days in month', () { + // Setup + final underTest = Getter.daysInMonthArray; + + // Verify + expect(underTest.length, 13); + }); +} + +List> dayOfWeekTestData() { + return [ + {'dateTime': DateTime(2022, 12, 5), 'expectedDayOfWeek': 1}, + {'dateTime': DateTime(2022, 12, 6), 'expectedDayOfWeek': 2}, + {'dateTime': DateTime(2022, 12, 7), 'expectedDayOfWeek': 3}, + {'dateTime': DateTime(2022, 12, 8), 'expectedDayOfWeek': 4}, + {'dateTime': DateTime(2022, 12, 9), 'expectedDayOfWeek': 5}, + {'dateTime': DateTime(2022, 12, 10), 'expectedDayOfWeek': 6}, + {'dateTime': DateTime(2022, 12, 11), 'expectedDayOfWeek': 7} + ]; +} + +List> dayOfWeekWithStartOfWeekTestData() { + return [ + { + 'dateTime': DateTime(2022, 12, 5), + 'startOfWeek': StartOfWeek.monday, + 'expectedDayOfWeek': 1 + }, + { + 'dateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDayOfWeek': 1 + }, + { + 'dateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDayOfWeek': 1 + } + ]; +} + +List> dayOfYearTestData() { + return [ + {'dateTime': DateTime(1997, 9, 23), 'expectedDayOfYear': 266}, + {'dateTime': DateTime(2020, 3, 1), 'expectedDayOfYear': 61}, + {'dateTime': DateTime(2022, 12, 25), 'expectedDayOfYear': 359} + ]; +} + +List> weekOfYearTestData() { + return [ + { + 'dateTime': DateTime(1997, 9, 23), + 'startOfWeek': StartOfWeek.monday, + 'expectedWeekOfYear': 39 + }, + { + 'dateTime': DateTime(2020, 3, 1), + 'startOfWeek': StartOfWeek.sunday, + 'expectedWeekOfYear': 10 + }, + { + 'dateTime': DateTime(2022, 12, 25), + 'startOfWeek': StartOfWeek.saturday, + 'expectedWeekOfYear': 52 + } + ]; +} + +List> quarterOfYearTestData() { + return [ + {'dateTime': DateTime(2022, 1, 1), 'expectedQuarterOfYear': 1}, + {'dateTime': DateTime(2022, 4, 1), 'expectedQuarterOfYear': 2}, + {'dateTime': DateTime(2022, 7, 1), 'expectedQuarterOfYear': 3}, + {'dateTime': DateTime(2022, 10, 1), 'expectedQuarterOfYear': 4} + ]; +} + +List> daysInMonthTestData() { + return [ + {'dateTime': DateTime(2022, 1), 'expectedDayInMonth': 31}, + {'dateTime': DateTime(2022, 2), 'expectedDayInMonth': 28}, + {'dateTime': DateTime(2020, 2), 'expectedDayInMonth': 29}, + {'dateTime': DateTime(2022, 3), 'expectedDayInMonth': 31}, + {'dateTime': DateTime(2022, 4), 'expectedDayInMonth': 30}, + {'dateTime': DateTime(2022, 5), 'expectedDayInMonth': 31}, + {'dateTime': DateTime(2022, 6), 'expectedDayInMonth': 30}, + {'dateTime': DateTime(2022, 7), 'expectedDayInMonth': 31}, + {'dateTime': DateTime(2022, 8), 'expectedDayInMonth': 31}, + {'dateTime': DateTime(2022, 9), 'expectedDayInMonth': 30}, + {'dateTime': DateTime(2022, 10), 'expectedDayInMonth': 31}, + {'dateTime': DateTime(2022, 11), 'expectedDayInMonth': 30}, + {'dateTime': DateTime(2022, 12), 'expectedDayInMonth': 31}, + ]; +} diff --git a/test/src/jiffy_test.dart b/test/src/jiffy_test.dart new file mode 100644 index 0000000..e82c7ad --- /dev/null +++ b/test/src/jiffy_test.dart @@ -0,0 +1,1552 @@ +import 'package:jiffy/jiffy.dart'; +import 'package:jiffy/src/locale/locales/ar_locale.dart'; +import 'package:jiffy/src/locale/locales/az_locale.dart'; +import 'package:jiffy/src/locale/locales/bn_locale.dart'; +import 'package:jiffy/src/locale/locales/de_locale.dart'; +import 'package:jiffy/src/locale/locales/en_locale.dart'; +import 'package:jiffy/src/locale/locales/es_locale.dart'; +import 'package:jiffy/src/locale/locales/fa_locale.dart'; +import 'package:jiffy/src/locale/locales/fr_locale.dart'; +import 'package:jiffy/src/locale/locales/hi_locale.dart'; +import 'package:jiffy/src/locale/locales/hu_locale.dart'; +import 'package:jiffy/src/locale/locales/id_locale.dart'; +import 'package:jiffy/src/locale/locales/it_locale.dart'; +import 'package:jiffy/src/locale/locales/ja_locale.dart'; +import 'package:jiffy/src/locale/locales/ko_locale.dart'; +import 'package:jiffy/src/locale/locales/nb_locale.dart'; +import 'package:jiffy/src/locale/locales/nl_locale.dart'; +import 'package:jiffy/src/locale/locales/pl_locale.dart'; +import 'package:jiffy/src/locale/locales/pt_locale.dart'; +import 'package:jiffy/src/locale/locales/ru_locale.dart'; +import 'package:jiffy/src/locale/locales/sv_locale.dart'; +import 'package:jiffy/src/locale/locales/th_locale.dart'; +import 'package:jiffy/src/locale/locales/tr_locale.dart'; +import 'package:jiffy/src/locale/locales/uk_locale.dart'; +import 'package:jiffy/src/locale/locales/zh_locale.dart'; +import 'package:jiffy/src/utils/jiffy_exception.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group('Test parsing and creating a Jiffy instance', () { + test('Should successfully parse from string', () { + // Setup + final dateTime = '1997-09-23'; + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parse(dateTime); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully parse from string using pattern', () { + // Setup + final dateTime = '23 Sep 97'; + final pattern = 'dd MMM yy'; + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parse(dateTime, pattern: pattern); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully parse from string is it is utc', () { + // Setup + final dateTime = '23 Sep 97'; + final pattern = 'dd MMM yy'; + final expectedDateTime = DateTime.utc(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parse(dateTime, pattern: pattern, isUtc: true); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + expect(actualJiffy.isUtc, expectedDateTime.isUtc); + }); + + test('Should successfully parse from DateTime', () { + // Setup + final dateTime = DateTime(1997, 9, 23); + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromDateTime(dateTime); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully parse from Jiffy', () { + // Setup + final jiffy = Jiffy.parseFromDateTime(DateTime(1997, 9, 23)); + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromJiffy(jiffy); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully parse from List', () { + // Setup + final list = [1997, 9, 23]; + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromList(list); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully parse from List if it is utc', () { + // Setup + final list = [1997, 9, 23]; + final expectedDateTime = DateTime.utc(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromList(list, isUtc: true); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + expect(actualJiffy.isUtc, expectedDateTime.isUtc); + }); + + test('Should successfully parse from Map', () { + // Setup + final map = {Unit.year: 1997, Unit.month: 9, Unit.day: 23}; + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromMap(map); + + // Verify + expect(actualJiffy.year, expectedDateTime.year); + expect(actualJiffy.month, expectedDateTime.month); + expect(actualJiffy.date, expectedDateTime.day); + }); + + test('Should successfully parse from Map if it is utc', () { + // Setup + final map = {Unit.year: 1997, Unit.month: 9, Unit.day: 23}; + final expectedDateTime = DateTime.utc(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromMap(map, isUtc: true); + + // Verify + expect(actualJiffy.year, expectedDateTime.year); + expect(actualJiffy.month, expectedDateTime.month); + expect(actualJiffy.date, expectedDateTime.day); + expect(actualJiffy.isUtc, expectedDateTime.isUtc); + }); + + test('Should successfully parse from Microseconds since epoch', () { + // Setup + final microsecondsSinceEpoch = + DateTime(1997, 9, 23).microsecondsSinceEpoch; + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = + Jiffy.parseFromMicrosecondsSinceEpoch(microsecondsSinceEpoch); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully parse from Microseconds since epoch if it is utc', + () { + // Setup + final microsecondsSinceEpoch = + DateTime.utc(1997, 9, 23).microsecondsSinceEpoch; + final expectedDateTime = DateTime.utc(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromMicrosecondsSinceEpoch( + microsecondsSinceEpoch, + isUtc: true); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + expect(actualJiffy.isUtc, expectedDateTime.isUtc); + }); + + test('Should successfully parse from Milliseconds since epoch', () { + // Setup + final millisecondsSinceEpoch = + DateTime(1997, 9, 23).millisecondsSinceEpoch; + final expectedDateTime = DateTime(1997, 9, 23); + + // Execute + final actualJiffy = + Jiffy.parseFromMillisecondsSinceEpoch(millisecondsSinceEpoch); + + // Verify + expect(actualJiffy.millisecondsSinceEpoch, + expectedDateTime.millisecondsSinceEpoch); + }); + + test('Should successfully parse from Milliseconds since epoch if it is utc', + () { + // Setup + final millisecondsSinceEpoch = + DateTime.utc(1997, 9, 23).millisecondsSinceEpoch; + final expectedDateTime = DateTime.utc(1997, 9, 23); + + // Execute + final actualJiffy = Jiffy.parseFromMillisecondsSinceEpoch( + millisecondsSinceEpoch, + isUtc: true); + + // Verify + expect(actualJiffy.millisecondsSinceEpoch, + expectedDateTime.millisecondsSinceEpoch); + expect(actualJiffy.isUtc, expectedDateTime.isUtc); + }); + + test('Should successfully get date time now', () { + // Setup + final expectedDateTime = DateTime.now(); + + // Execute + final actualJiffy = Jiffy.now(); + + // Verify + expect(actualJiffy.year, expectedDateTime.year); + expect(actualJiffy.month, expectedDateTime.month); + expect(actualJiffy.date, expectedDateTime.day); + }); + }); + + group('Test getting and setting locales', () { + test('Should successfully get locale', () async { + // Setup + await Jiffy.setLocale('ja'); + final jiffy = Jiffy.now(); + + final expectedLocaleCode = 'ja'; + + // Execute + final actualLocaleCode = jiffy.localeCode; + + // Verify + expect(actualLocaleCode, expectedLocaleCode); + }); + + test('Should successfully get start of week', () async { + // Setup + await Jiffy.setLocale('ja'); + final jiffy = Jiffy.now(); + + final expectedStartOfWeek = StartOfWeek.sunday; + + // Execute + final actualLocaleStartOfWeek = jiffy.localeStartOfWeek; + + // Verify + expect(actualLocaleStartOfWeek, expectedStartOfWeek); + }); + + for (var testData in localeTestData()) { + test('Should successfully set expectedLocale', () async { + // Execute + await Jiffy.setLocale(testData['localeCode']); + final jiffy = Jiffy.now(); + + // Verify + final actualLocaleCode = jiffy.localeCode; + expect(actualLocaleCode, testData['expectedLocale'].code()); + }); + } + + test('Should throw Jiffy exception if locale is not supported', () async { + // Setup + final unknownLocaleCode = 'unknown_locale'; + final expectedExceptionMessage = 'The locale `$unknownLocaleCode` is not ' + 'supported, please check here for a list of supported locales'; + + // Execute and Verify + expect( + () async => await Jiffy.setLocale(unknownLocaleCode), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + }); + + group('Test cloning Jiffy instance', () { + test('Should successfully clone a Jiffy instance', () { + // Setup + final jiffy = Jiffy.now(); + + // Execute + final newJiffy = jiffy.clone(); + + // Verify + expect(identical(newJiffy, jiffy), false); + expect(newJiffy.microsecondsSinceEpoch, jiffy.microsecondsSinceEpoch); + }); + }); + + group('Test date time getters', () { + final dateTime = DateTime.now(); + final jiffy = Jiffy.parseFromDateTime(dateTime); + + test('Should successfully get date time', () { + // Setup + final expectedDateTime = dateTime; + + // Expected + final actualDateTime = jiffy.dateTime; + + // Verify + expect(actualDateTime, expectedDateTime); + }); + + test('Should successfully get microsecond', () { + // Setup + final expectedMicrosecond = dateTime.microsecond; + + // Execute + final actualMicrosecond = jiffy.microsecond; + + // Verify + expect(actualMicrosecond, expectedMicrosecond); + }); + + test('Should successfully get microsecondsSinceEpoch', () { + // Setup + final expectedMicrosecondsSinceEpoch = dateTime.microsecondsSinceEpoch; + + // Execute + final actualMicrosecondsSinceEpoch = jiffy.microsecondsSinceEpoch; + + // Verify + expect(actualMicrosecondsSinceEpoch, expectedMicrosecondsSinceEpoch); + }); + + test('Should successfully get millisecond', () { + // Setup + final expectedMillisecond = dateTime.millisecond; + + // Execute + final actualMillisecond = jiffy.millisecond; + + // Verify + expect(actualMillisecond, expectedMillisecond); + }); + + test('Should successfully get millisecondsSinceEpoch', () { + // Setup + final expectedMillisecondsSinceEpoch = dateTime.millisecondsSinceEpoch; + + // Execute + final actualMillisecondsSinceEpoch = jiffy.millisecondsSinceEpoch; + + // Verify + expect(actualMillisecondsSinceEpoch, expectedMillisecondsSinceEpoch); + }); + + test('Should successfully get second', () { + // Setup + final expectedSecond = dateTime.second; + + // Execute + final actualSecond = jiffy.second; + + // Verify + expect(actualSecond, expectedSecond); + }); + + test('Should successfully get minute', () { + // Setup + final expectedMinute = dateTime.minute; + + // Execute + final actualMinute = jiffy.minute; + + // Verify + expect(actualMinute, expectedMinute); + }); + + test('Should successfully get hour', () { + // Setup + final expectedHour = dateTime.hour; + + // Execute + final actualHour = jiffy.hour; + + // Verify + expect(actualHour, expectedHour); + }); + + test('Should successfully get date', () { + // Setup + final expectedDate = dateTime.day; + + // Execute + final actualDate = jiffy.date; + + // Verify + expect(actualDate, expectedDate); + }); + + test('Should successfully get day of week', () async { + // Setup + await Jiffy.setLocale('en_us'); + final jiffy = Jiffy.parseFromList([2022, 12, 5]); + + final expectedDayOfWeek = 2; + + // Execute + final actualDayOfWeek = jiffy.dayOfWeek; + + // Verify + expect(actualDayOfWeek, expectedDayOfWeek); + }); + + test('Should successfully get days in month', () { + // Setup + final jiffy = Jiffy.parseFromList([1997, 9]); + + final expectedDaysInMonth = 30; + + // Execute + final actualDaysInMonth = jiffy.daysInMonth; + + // Verify + expect(actualDaysInMonth, expectedDaysInMonth); + }); + + test('Should successfully get day of year', () { + // Setup + final jiffy = Jiffy.parseFromList([1997, 9, 23]); + + final expectedDayOfYear = 266; + + // Execute + final actualDayOfYear = jiffy.dayOfYear; + + // Verify + expect(actualDayOfYear, expectedDayOfYear); + }); + + test('Should successfully get week of year', () { + // Setup + final jiffy = Jiffy.parseFromList([1997, 9, 23]); + + final expectedWeek = 39; + + // Execute + final actualWeek = jiffy.weekOfYear; + + // Verify + expect(actualWeek, expectedWeek); + }); + + test('Should successfully get month', () { + // Setup + final expectedMonth = dateTime.month; + + // Execute + final actualMonth = jiffy.month; + + // Verify + expect(actualMonth, expectedMonth); + }); + + test('Should successfully get quarter', () { + // Setup + final jiffy = Jiffy.parseFromList([1997, 9]); + + final expectedQuarter = 3; + + // Execute + final actualDayOfQuarter = jiffy.quarter; + + // Verify + expect(actualDayOfQuarter, expectedQuarter); + }); + + test('Should successfully get year', () { + // Setup + final expectedYear = dateTime.year; + + // Execute + final actualYear = jiffy.year; + + // Verify + expect(actualYear, expectedYear); + }); + }); + + group('Test date time manipulation', () { + group('Test add and subtract', () { + test('Should successfully add date time using duration', () { + // Setup + final underTest = + Jiffy.parseFromList([1997, 9, 23, 12, 11, 22, 123, 456]); + final duration = Duration( + microseconds: 100, + milliseconds: 200, + seconds: 3, + minutes: 4, + hours: 2, + days: 3); + + final expectedJiffy = + Jiffy.parseFromList([1997, 9, 26, 14, 15, 25, 323, 556]); + + // Execute + final actualJiffy = underTest.addDuration(duration); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedJiffy.microsecondsSinceEpoch); + }); + + test('Should successfully add date time', () { + // Setup + final underTest = + Jiffy.parseFromList([1997, 9, 23, 12, 11, 22, 123, 456]); + final microseconds = 100; + final milliseconds = 200; + final seconds = 3; + final minutes = 4; + final hours = 2; + final days = 3; + final weeks = 1; + final months = 4; + final years = 2; + + final expectedJiffy = + Jiffy.parseFromList([2000, 2, 3, 14, 15, 25, 323, 556]); + + // Execute + final actualJiffy = underTest.add( + microseconds: microseconds, + milliseconds: milliseconds, + seconds: seconds, + minutes: minutes, + hours: hours, + days: days, + weeks: weeks, + months: months, + years: years); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedJiffy.microsecondsSinceEpoch); + }); + + test('Should successfully subtract date time using duration', () { + // Setup + final underTest = + Jiffy.parseFromList([1997, 9, 23, 12, 11, 22, 123, 456]); + final duration = Duration( + microseconds: 100, + milliseconds: 100, + seconds: 3, + minutes: 4, + hours: 2, + days: 3); + + final expectedJiffy = + Jiffy.parseFromList([1997, 9, 20, 10, 7, 19, 23, 356]); + + // Execute + final actualJiffy = underTest.subtractDuration(duration); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedJiffy.microsecondsSinceEpoch); + }); + + test('Should successfully subtract date time', () { + // Setup + final underTest = + Jiffy.parseFromList([1997, 9, 23, 12, 11, 22, 123, 456]); + final microseconds = 100; + final milliseconds = 100; + final seconds = 3; + final minutes = 4; + final hours = 2; + final days = 3; + final weeks = 1; + final months = 4; + final years = 2; + + final expectedJiffy = + Jiffy.parseFromList([1995, 5, 13, 10, 7, 19, 23, 356]); + + // Execute + final actualJiffy = underTest.subtract( + microseconds: microseconds, + milliseconds: milliseconds, + seconds: seconds, + minutes: minutes, + hours: hours, + days: days, + weeks: weeks, + months: months, + years: years); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedJiffy.microsecondsSinceEpoch); + }); + }); + + group('Test startOf and endOf', () { + test('Should successfully get startOf date time', () { + // Setup + final underTest = Jiffy.parseFromList([1997, 9, 23, 11, 30, 22]); + + final expectedJiffy = Jiffy.parseFromList([1997, 9, 23, 0, 0, 0, 0, 0]); + + // Execute + final actualJiffy = underTest.startOf(Unit.day); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedJiffy.microsecondsSinceEpoch); + }); + + test('Should successfully get endOf date time', () { + // Setup + final underTest = Jiffy.parseFromList([1997, 9, 23, 11, 30, 22]); + + final expectedJiffy = + Jiffy.parseFromList([1997, 9, 23, 23, 59, 59, 999, 999]); + + // Execute + final actualJiffy = underTest.endOf(Unit.day); + + // Verify + expect(actualJiffy.microsecondsSinceEpoch, + expectedJiffy.microsecondsSinceEpoch); + }); + }); + + group('Test toLocal and toUtc', () { + test('Should successfully convert utc date time to local', () { + // Setup + final underTest = Jiffy.now().toUtc(); + + final expectedIsLocal = true; + + // Execute + final actualJiffy = underTest.toLocal(); + + // Verify + expect(actualJiffy.isLocal, expectedIsLocal); + }); + + test('Should successfully return local if already local', () { + // Setup + final underTest = Jiffy.now().toLocal(); + + final expectedIsLocal = true; + + // Execute + final actualJiffy = underTest.toLocal(); + + // Verify + expect(actualJiffy.isLocal, expectedIsLocal); + }); + + test('Should successfully convert local date time to utc', () { + // Setup + final underTest = Jiffy.now().toLocal(); + + final expectedIsUtc = true; + + // Execute + final actualJiffy = underTest.toUtc(); + + // Verify + expect(actualJiffy.isUtc, expectedIsUtc); + }); + + test('Should successfully return utc if already utc', () { + // Setup + final underTest = Jiffy.now().toUtc(); + + final expectedIsUtc = true; + + // Execute + final actualJiffy = underTest.toUtc(); + + // Verify + expect(actualJiffy.isUtc, expectedIsUtc); + }); + }); + }); + + group('Test date time displaying', () { + group('Test date time format', () { + test('Should successfully format to ISO8601 if pattern is not passed', + () { + // Setup + final underTest = + Jiffy.parseFromList([1997, 9, 23, 11, 30, 22, 345, 222]); + + final expectedFormat = '1997-09-23T11:30:22.345222'; + + // Execute + final actualFormat = underTest.format(); + + // Verify + expect(actualFormat, expectedFormat); + }); + + test('Should successfully format based on pattern', () { + // Setup + final underTest = + Jiffy.parseFromList([1997, 9, 23, 11, 30, 22, 345, 222]); + final pattern = 'yyyy, do MMM [at] HH:mm a'; + + final expectedFormat = '1997, 23rd Sep at 11:30 AM'; + + // Execute + final actualFormat = underTest.format(pattern: pattern); + + // Verify + expect(actualFormat, expectedFormat); + }); + }); + + group('Test date time default format', () { + for (var testData in defaultDisplayDateTimeFormatsTestData()) { + test('Should successfully display date time using prebuilt formats', + () { + // Setup + final jiffy = + Jiffy.parseFromDateTime((testData['dateTime'] as DateTime)); + + // Execute + final actualFormat = + (testData['function'] as Function(Jiffy)).call(jiffy); + + // Verify + expect(actualFormat, testData['expectedFormat']); + }); + } + }); + + group('Test displaying relative date time', () { + test('Should successfully get relative date time from', () { + // Setup + final underTest = Jiffy.parseFromList([1997]); + final jiffyFrom = Jiffy.parseFromList([2022]); + + final expectedRelativeDateTime = '25 years ago'; + + // Execute + final actualRelativeDateTime = underTest.from(jiffyFrom); + + // Verify + expect(actualRelativeDateTime, expectedRelativeDateTime); + }); + + test('Should successfully get relative date time fromNow', () { + // Setup + final underTest = Jiffy.now().subtract(years: 25); + + final expectedRelativeDateTime = '25 years ago'; + + // Execute + final actualRelativeDateTime = underTest.fromNow(); + + // Verify + expect(actualRelativeDateTime, expectedRelativeDateTime); + }); + + test('Should successfully get relative date time to', () { + // Setup + final underTest = Jiffy.parseFromList([1997]); + final jiffyTo = Jiffy.parseFromList([2022]); + + final expectedRelativeDateTime = 'in 25 years'; + + // Execute + final actualRelativeDateTime = underTest.to(jiffyTo); + + // Verify + expect(actualRelativeDateTime, expectedRelativeDateTime); + }); + + test('Should successfully get relative date time toNow', () { + // Setup + final underTest = Jiffy.now().subtract(years: 25); + + final expectedRelativeDateTime = 'in 25 years'; + + // Execute + final actualRelativeDateTime = underTest.toNow(); + + // Verify + expect(actualRelativeDateTime, expectedRelativeDateTime); + }); + }); + + group('Test displaying diff', () { + test('Should successfully get diff between two date times', () { + // Setup + final underTest = Jiffy.parseFromList([1997, 9, 23]); + final jiffyFrom = Jiffy.parseFromList([2022]); + + final expectedDifference = -291.2903225806452; + + // Execute + final actualDifference = + underTest.diff(jiffyFrom, unit: Unit.month, asFloat: false); + + // Verify + expect(actualDifference, expectedDifference); + }); + + test('Should successfully get diff between two date times as float', () { + // Setup + final underTest = Jiffy.parseFromList([1997, 9, 23]); + final jiffyFrom = Jiffy.parseFromList([2022]); + + final expectedDifference = -291; + + // Execute + final actualDifference = + underTest.diff(jiffyFrom, unit: Unit.month, asFloat: true); + + // Verify + expect(actualDifference, expectedDifference); + }); + }); + }); + + group('Test date time querying', () { + for (var testData in isBeforeTestData()) { + test('Should successfully check if date time is before another', () { + // Setup + final firstJiffy = testData['firstJiffy'] as Jiffy; + final secondJiffy = testData['secondJiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = firstJiffy.isBefore(secondJiffy); + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isAfterTestData()) { + test('Should successfully check if date time is after another', () { + // Setup + final firstJiffy = testData['firstJiffy'] as Jiffy; + final secondJiffy = testData['secondJiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = firstJiffy.isAfter(secondJiffy); + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isSameTestData()) { + test('Should successfully check if date time is same', () { + // Setup + final firstJiffy = testData['firstJiffy'] as Jiffy; + final secondJiffy = testData['secondJiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = firstJiffy.isSame(secondJiffy); + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isSameOrBeforeTestData()) { + test('Should successfully check if date time is same or before', () { + // Setup + final firstJiffy = testData['firstJiffy'] as Jiffy; + final secondJiffy = testData['secondJiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = firstJiffy.isSameOrBefore(secondJiffy); + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isSameOrAfterTestData()) { + test('Should successfully check if date time is same or after', () { + // Setup + final firstJiffy = testData['firstJiffy'] as Jiffy; + final secondJiffy = testData['secondJiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = firstJiffy.isSameOrAfter(secondJiffy); + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isBetweenTestData()) { + test('Should successfully check if date time is same or after', () { + // Setup + final firstJiffy = testData['firstJiffy'] as Jiffy; + final secondJiffy = testData['secondJiffy'] as Jiffy; + final thirdJiffy = testData['thirdJiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = firstJiffy.isBetween(secondJiffy, thirdJiffy); + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isJiffyLocalTestData()) { + test('Should successfully check if jiffy is local', () { + // Setup + final jiffy = testData['jiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = jiffy.isLocal; + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isJiffyUtcTestData()) { + test('Should successfully check if jiffy is utc', () { + // Setup + final jiffy = testData['jiffy'] as Jiffy; + + final expected = testData['expected']; + + // Execute + final actual = jiffy.isUtc; + + // Verify + expect(actual, expected); + }); + } + + for (var testData in isLeapYearTestData()) { + test('Should successfully check if jiffy year is leap year', () { + // Setup + final jiffy = testData['jiffy'] as Jiffy; + + final expected = testData['expectedIsLeapYear']; + + // Execute + final actualIsLeapYear = jiffy.isLeapYear; + + // Verify + expect(actualIsLeapYear, expected); + }); + } + }); + + group('Test equality and hashcode', () { + for (var testData in equalityTestData()) { + test("Should successfully test the equality of two Jiffy instances", () { + // Setup + final jiffy1 = testData['jiffy1']; + final jiffy2 = testData['jiffy2']; + + final expectedEquality = testData['expectedEquality']; + + // Execute + final actualEquality = jiffy1 == jiffy2; + + // Verify + expect(actualEquality, expectedEquality); + }); + } + + test('Should successfully return true with valid hashcode consistency', () { + // Setup + final jiffy1 = Jiffy.parseFromList([1997, 9, 23]); + final jiffy2 = Jiffy.parseFromList([1997, 9, 23]); + + // Execute and Verify + expect(jiffy1.hashCode, equals(jiffy2.hashCode)); + }); + + test('Should successfully return false with invalid hashcode consistency', + () { + // Setup + final jiffy1 = Jiffy.parseFromList([1997, 9, 23]); + final jiffy2 = Jiffy.parseFromList([1997, 9, 24]); + + // Execute and Verify + expect(jiffy1.hashCode, isNot(jiffy2.hashCode)); + }); + }); +} + +List> localeTestData() { + return [ + { + 'localeCode': 'en', + 'expectedLocale': EnLocale(), + }, + { + 'localeCode': 'en_us', + 'expectedLocale': EnUsLocale(), + }, + { + 'localeCode': 'en_sg', + 'expectedLocale': EnSgLocale(), + }, + { + 'localeCode': 'en_au', + 'expectedLocale': EnAuLocale(), + }, + { + 'localeCode': 'en_ca', + 'expectedLocale': EnCaLocale(), + }, + { + 'localeCode': 'en_gb', + 'expectedLocale': EnGbLocale(), + }, + { + 'localeCode': 'en_ie', + 'expectedLocale': EnIeLocale(), + }, + { + 'localeCode': 'en_il', + 'expectedLocale': EnIlLocale(), + }, + { + 'localeCode': 'en_nz', + 'expectedLocale': EnNzLocale(), + }, + { + 'localeCode': 'es', + 'expectedLocale': EsLocale(), + }, + { + 'localeCode': 'es_do', + 'expectedLocale': EsDoLocale(), + }, + { + 'localeCode': 'es_us', + 'expectedLocale': EsUsLocale(), + }, + { + 'localeCode': 'fr', + 'expectedLocale': FrLocale(), + }, + { + 'localeCode': 'fr_ch', + 'expectedLocale': FrChLocale(), + }, + { + 'localeCode': 'fr_ca', + 'expectedLocale': FrCaLocale(), + }, + { + 'localeCode': 'zh', + 'expectedLocale': ZhLocale(), + }, + { + 'localeCode': 'zh_cn', + 'expectedLocale': ZhCnLocale(), + }, + { + 'localeCode': 'zh_hk', + 'expectedLocale': ZhHkLocale(), + }, + { + 'localeCode': 'zh_tw', + 'expectedLocale': ZhTwLocale(), + }, + { + 'localeCode': 'de', + 'expectedLocale': DeLocale(), + }, + { + 'localeCode': 'de_de', + 'expectedLocale': DeDeLocale(), + }, + { + 'localeCode': 'de_at', + 'expectedLocale': DeAtLocale(), + }, + { + 'localeCode': 'de_ch', + 'expectedLocale': DeChLocale(), + }, + { + 'localeCode': 'it', + 'expectedLocale': ItLocale(), + }, + { + 'localeCode': 'it_ch', + 'expectedLocale': ItChLocale(), + }, + { + 'localeCode': 'ar', + 'expectedLocale': ArLocale(), + }, + { + 'localeCode': 'ar_ly', + 'expectedLocale': ArLyLocale(), + }, + { + 'localeCode': 'ar_dz', + 'expectedLocale': ArDzLocale(), + }, + { + 'localeCode': 'ar_kw', + 'expectedLocale': ArKwLocale(), + }, + { + 'localeCode': 'ar_sa', + 'expectedLocale': ArSaLocale(), + }, + { + 'localeCode': 'ar_ma', + 'expectedLocale': ArMaLocale(), + }, + { + 'localeCode': 'ar_tn', + 'expectedLocale': ArTnLocale(), + }, + { + 'localeCode': 'az', + 'expectedLocale': AzLocale(), + }, + { + 'localeCode': 'id', + 'expectedLocale': IdLocale(), + }, + { + 'localeCode': 'ja', + 'expectedLocale': JaLocale(), + }, + { + 'localeCode': 'ko', + 'expectedLocale': KoLocale(), + }, + { + 'localeCode': 'ru', + 'expectedLocale': RuLocale(), + }, + { + 'localeCode': 'uk', + 'expectedLocale': UkLocale(), + }, + { + 'localeCode': 'hi', + 'expectedLocale': HiLocale(), + }, + { + 'localeCode': 'hu', + 'expectedLocale': HuLocale(), + }, + { + 'localeCode': 'hu_hu', + 'expectedLocale': HuHuLocale(), + }, + { + 'localeCode': 'pt', + 'expectedLocale': PtLocale(), + }, + { + 'localeCode': 'pt_br', + 'expectedLocale': PtBrLocale(), + }, + { + 'localeCode': 'pl', + 'expectedLocale': PlLocale(), + }, + { + 'localeCode': 'tr', + 'expectedLocale': TrLocale(), + }, + { + 'localeCode': 'sv', + 'expectedLocale': SvLocale(), + }, + { + 'localeCode': 'nb', + 'expectedLocale': NbLocale(), + }, + { + 'localeCode': 'fa', + 'expectedLocale': FaLocale(), + }, + { + 'localeCode': 'bn', + 'expectedLocale': BnLocale(), + }, + { + 'localeCode': 'nl', + 'expectedLocale': NlLocale(), + }, + { + 'localeCode': 'th', + 'expectedLocale': ThLocale(), + }, + ]; +} + +List> defaultDisplayDateTimeFormatsTestData() { + return [ + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.E, + 'expectedFormat': 'Tue' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.EEEE, + 'expectedFormat': 'Tuesday' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.Md, + 'expectedFormat': '9/23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MEd, + 'expectedFormat': 'Tue, 9/23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MMM, + 'expectedFormat': 'Sep' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MMMd, + 'expectedFormat': 'Sep 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MMMEd, + 'expectedFormat': 'Tue, Sep 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MMMM, + 'expectedFormat': 'September' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MMMMd, + 'expectedFormat': 'September 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.MMMMEEEEd, + 'expectedFormat': 'Tuesday, September 23' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.QQQ, + 'expectedFormat': 'Q3' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.QQQQ, + 'expectedFormat': '3rd quarter' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yM, + 'expectedFormat': '9/1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMd, + 'expectedFormat': '9/23/1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMEd, + 'expectedFormat': 'Tue, 9/23/1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMM, + 'expectedFormat': 'Sep 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMd, + 'expectedFormat': 'Sep 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMdjm, + 'expectedFormat': 'Sep 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMEd, + 'expectedFormat': 'Tue, Sep 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMEdjm, + 'expectedFormat': 'Tue, Sep 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMM, + 'expectedFormat': 'September 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMMd, + 'expectedFormat': 'September 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMMdjm, + 'expectedFormat': 'September 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMMEEEEd, + 'expectedFormat': 'Tuesday, September 23, 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yMMMMEEEEdjm, + 'expectedFormat': 'Tuesday, September 23, 1997 12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yQQQ, + 'expectedFormat': 'Q3 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.yQQQQ, + 'expectedFormat': '3rd quarter 1997' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.H, + 'expectedFormat': '12' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.Hm, + 'expectedFormat': '12:11' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.Hms, + 'expectedFormat': '12:11:22' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.j, + 'expectedFormat': '12 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.jm, + 'expectedFormat': '12:11 PM' + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'function': (Jiffy jiffy) => jiffy.jms, + 'expectedFormat': '12:11:22 PM' + }, + ]; +} + +List> isBeforeTestData() { + final jiffy = Jiffy.now(); + return [ + {'firstJiffy': jiffy, 'secondJiffy': jiffy.add(days: 5), 'expected': true}, + { + 'firstJiffy': jiffy, + 'secondJiffy': jiffy.subtract(days: 5), + 'expected': false + } + ]; +} + +List> isAfterTestData() { + final jiffy = Jiffy.now(); + return [ + {'firstJiffy': jiffy, 'secondJiffy': jiffy.add(days: 5), 'expected': false}, + { + 'firstJiffy': jiffy, + 'secondJiffy': jiffy.subtract(days: 5), + 'expected': true + } + ]; +} + +List> isSameTestData() { + final jiffy = Jiffy.now(); + return [ + {'firstJiffy': jiffy, 'secondJiffy': jiffy.clone(), 'expected': true}, + {'firstJiffy': jiffy, 'secondJiffy': jiffy.add(days: 5), 'expected': false}, + { + 'firstJiffy': jiffy, + 'secondJiffy': jiffy.subtract(days: 5), + 'expected': false + } + ]; +} + +List> isSameOrBeforeTestData() { + final jiffy = Jiffy.now(); + return [ + {'firstJiffy': jiffy, 'secondJiffy': jiffy.clone(), 'expected': true}, + {'firstJiffy': jiffy, 'secondJiffy': jiffy.add(days: 5), 'expected': true}, + { + 'firstJiffy': jiffy, + 'secondJiffy': jiffy.subtract(days: 5), + 'expected': false + } + ]; +} + +List> isSameOrAfterTestData() { + final jiffy = Jiffy.now(); + return [ + {'firstJiffy': jiffy, 'secondJiffy': jiffy.clone(), 'expected': true}, + {'firstJiffy': jiffy, 'secondJiffy': jiffy.add(days: 5), 'expected': false}, + { + 'firstJiffy': jiffy, + 'secondJiffy': jiffy.subtract(days: 5), + 'expected': true + } + ]; +} + +List> isBetweenTestData() { + final jiffy = Jiffy.now(); + return [ + { + 'firstJiffy': jiffy, + 'secondJiffy': jiffy.subtract(days: 5), + 'thirdJiffy': jiffy.add(days: 5), + 'expected': true + }, + { + 'firstJiffy': jiffy.subtract(days: 5), + 'secondJiffy': jiffy.subtract(days: 5), + 'thirdJiffy': jiffy.add(days: 5), + 'expected': false + }, + { + 'firstJiffy': jiffy.add(days: 5), + 'secondJiffy': jiffy.subtract(days: 5), + 'thirdJiffy': jiffy.add(days: 5), + 'expected': false + }, + { + 'firstJiffy': jiffy.subtract(days: 6), + 'secondJiffy': jiffy.subtract(days: 5), + 'thirdJiffy': jiffy.add(days: 5), + 'expected': false + }, + { + 'firstJiffy': jiffy.add(days: 6), + 'secondJiffy': jiffy.subtract(days: 5), + 'thirdJiffy': jiffy.add(days: 5), + 'expected': false + } + ]; +} + +List> isJiffyLocalTestData() { + return [ + {'jiffy': Jiffy.now().toLocal(), 'expected': true}, + {'jiffy': Jiffy.now().toUtc(), 'expected': false}, + ]; +} + +List> isJiffyUtcTestData() { + return [ + {'jiffy': Jiffy.now().toLocal(), 'expected': false}, + {'jiffy': Jiffy.now().toUtc(), 'expected': true}, + ]; +} + +List> isLeapYearTestData() { + return [ + { + 'jiffy': Jiffy.parseFromList([1997]), + 'expectedIsLeapYear': false + }, + { + 'jiffy': Jiffy.parseFromList([2022]), + 'expectedIsLeapYear': false + }, + { + 'jiffy': Jiffy.parseFromList([2020]), + 'expectedIsLeapYear': true + }, + { + 'jiffy': Jiffy.parseFromList([2018]), + 'expectedIsLeapYear': false + }, + { + 'jiffy': Jiffy.parseFromList([2016]), + 'expectedIsLeapYear': true + }, + ]; +} + +List> equalityTestData() { + return [ + { + 'jiffy1': Jiffy.parseFromList([1997, 9, 23]), + 'jiffy2': Jiffy.parseFromList([1997, 9, 23]), + 'expectedEquality': true + }, + { + 'jiffy1': Jiffy.parseFromList([1997, 9, 23]), + 'jiffy2': Jiffy.parseFromList([1997, 9, 24]), + 'expectedEquality': false + } + ]; +} diff --git a/test/src/locale/locales/locales_test.dart b/test/src/locale/locales/locales_test.dart new file mode 100644 index 0000000..e97ffbe --- /dev/null +++ b/test/src/locale/locales/locales_test.dart @@ -0,0 +1,4077 @@ +import 'package:jiffy/src/display.dart'; +import 'package:jiffy/src/enums/start_of_week.dart'; +import 'package:jiffy/src/getter.dart'; +import 'package:jiffy/src/locale/locale.dart'; +import 'package:jiffy/src/locale/locales/ar_locale.dart'; +import 'package:jiffy/src/locale/locales/az_locale.dart'; +import 'package:jiffy/src/locale/locales/bn_locale.dart'; +import 'package:jiffy/src/locale/locales/de_locale.dart'; +import 'package:jiffy/src/locale/locales/en_locale.dart'; +import 'package:jiffy/src/locale/locales/es_locale.dart'; +import 'package:jiffy/src/locale/locales/fa_locale.dart'; +import 'package:jiffy/src/locale/locales/fr_locale.dart'; +import 'package:jiffy/src/locale/locales/hi_locale.dart'; +import 'package:jiffy/src/locale/locales/hu_locale.dart'; +import 'package:jiffy/src/locale/locales/id_locale.dart'; +import 'package:jiffy/src/locale/locales/it_locale.dart'; +import 'package:jiffy/src/locale/locales/ja_locale.dart'; +import 'package:jiffy/src/locale/locales/ko_locale.dart'; +import 'package:jiffy/src/locale/locales/nb_locale.dart'; +import 'package:jiffy/src/locale/locales/nl_locale.dart'; +import 'package:jiffy/src/locale/locales/pl_locale.dart'; +import 'package:jiffy/src/locale/locales/pt_locale.dart'; +import 'package:jiffy/src/locale/locales/ru_locale.dart'; +import 'package:jiffy/src/locale/locales/sv_locale.dart'; +import 'package:jiffy/src/locale/locales/th_locale.dart'; +import 'package:jiffy/src/locale/locales/tr_locale.dart'; +import 'package:jiffy/src/locale/locales/uk_locale.dart'; +import 'package:jiffy/src/locale/locales/zh_locale.dart'; +import 'package:jiffy/src/manipulator.dart'; +import 'package:jiffy/src/query.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group('Test locale properties', () { + for (var testData in localesTestData()) { + test('Should successfully check locale properties are correct', () { + // Setup + final locale = testData['locale'] as Locale; + + // Verify + expect(locale.code(), testData['code']); + expect(locale.ordinals().length, 4); + expect(locale.ordinals(), testData['ordinals']); + expect(locale.startOfWeek(), testData['startOfWeek']); + expect(locale.relativeDateTime().runtimeType, + testData['relativeTime'].runtimeType); + }); + } + }); + + group('Test locale relative date time', () { + final getter = Getter(); + final manipulator = Manipulator(getter); + final query = Query(getter, manipulator); + final display = Display(getter, manipulator, query); + + for (var testData in localesRelativeDateTimeTestData()) { + test('Should successfully return correct relative date time', () { + // Execute + final actualRelativeDateTime = display.toAsRelativeDateTime( + testData['firstDateTime'], + testData['secondDateTime'], + testData['locale']); + + // Verify + expect(actualRelativeDateTime, testData['expectedRelativeDateTime']); + }); + } + }); +} + +List> localesTestData() { + return [ + { + 'locale': EnLocale(), + 'code': 'en', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnUsLocale(), + 'code': 'en_us', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnSgLocale(), + 'code': 'en_sg', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnAuLocale(), + 'code': 'en_au', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnCaLocale(), + 'code': 'en_ca', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnGbLocale(), + 'code': 'en_gb', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnIeLocale(), + 'code': 'en_ie', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnIlLocale(), + 'code': 'en_il', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EnNzLocale(), + 'code': 'en_nz', + 'ordinals': ['st', 'nd', 'rd', 'th'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EnRelativeTime() + }, + { + 'locale': EsLocale(), + 'code': 'es', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': EsRelativeTime() + }, + { + 'locale': EsDoLocale(), + 'code': 'es_do', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': EsRelativeTime() + }, + { + 'locale': EsUsLocale(), + 'code': 'es_us', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': EsRelativeTime() + }, + { + 'locale': FrLocale(), + 'code': 'fr', + 'ordinals': ['er', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': FrRelativeTime() + }, + { + 'locale': FrChLocale(), + 'code': 'fr_ch', + 'ordinals': ['er', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': FrRelativeTime() + }, + { + 'locale': FrCaLocale(), + 'code': 'fr_ca', + 'ordinals': ['er', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': FrRelativeTime() + }, + { + 'locale': ZhLocale(), + 'code': 'zh', + 'ordinals': ['日', '日', '日', '日'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ZhRelativeTime() + }, + { + 'locale': ZhCnLocale(), + 'code': 'zh_cn', + 'ordinals': ['日', '日', '日', '日'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ZhCnRelativeTime() + }, + { + 'locale': ZhHkLocale(), + 'code': 'zh_hk', + 'ordinals': ['日', '日', '日', '日'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ZhRelativeTime() + }, + { + 'locale': ZhTwLocale(), + 'code': 'zh_tw', + 'ordinals': ['日', '日', '日', '日'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ZhRelativeTime() + }, + { + 'locale': DeLocale(), + 'code': 'de', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': DeRelativeTime() + }, + { + 'locale': DeDeLocale(), + 'code': 'de_de', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': DeRelativeTime() + }, + { + 'locale': DeAtLocale(), + 'code': 'de_at', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': DeRelativeTime() + }, + { + 'locale': DeChLocale(), + 'code': 'de_ch', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': DeRelativeTime() + }, + { + 'locale': ItLocale(), + 'code': 'it', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': ItRelativeTime() + }, + { + 'locale': ItChLocale(), + 'code': 'it_ch', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': ItRelativeTime() + }, + { + 'locale': ArLocale(), + 'code': 'ar', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.saturday, + 'relativeTime': ArRelativeTime(true) + }, + { + 'locale': ArLyLocale(), + 'code': 'ar_ly', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.saturday, + 'relativeTime': ArRelativeTime(false) + }, + { + 'locale': ArDzLocale(), + 'code': 'ar_dz', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ArSaMaDzKwTnRelativeTime(false) + }, + { + 'locale': ArKwLocale(), + 'code': 'ar_kw', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ArSaMaDzKwTnRelativeTime(false) + }, + { + 'locale': ArSaLocale(), + 'code': 'ar_sa', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ArSaMaDzKwTnRelativeTime(true) + }, + { + 'locale': ArMaLocale(), + 'code': 'ar_ma', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.saturday, + 'relativeTime': ArSaMaDzKwTnRelativeTime(false) + }, + { + 'locale': ArTnLocale(), + 'code': 'ar_tn', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.saturday, + 'relativeTime': ArSaMaDzKwTnRelativeTime(false) + }, + { + 'locale': AzLocale(), + 'code': 'az', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': AzRelativeTime() + }, + { + 'locale': IdLocale(), + 'code': 'id', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': IdRelativeTime() + }, + { + 'locale': JaLocale(), + 'code': 'ja', + 'ordinals': ['日', '日', '日', '日'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': JaRelativeTime() + }, + { + 'locale': KoLocale(), + 'code': 'ko', + 'ordinals': ['일', '일', '일', '일'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': KoRelativeTime() + }, + { + 'locale': RuLocale(), + 'code': 'ru', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': RuRelativeTime() + }, + { + 'locale': UkLocale(), + 'code': 'uk', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': UkRelativeTime() + }, + { + 'locale': HiLocale(), + 'code': 'hi', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': HiRelativeTime() + }, + { + 'locale': HuLocale(), + 'code': 'hu', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': HuRelativeTime() + }, + { + 'locale': HuHuLocale(), + 'code': 'hu_hu', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': HuRelativeTime() + }, + { + 'locale': PtLocale(), + 'code': 'pt', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': PtRelativeTime() + }, + { + 'locale': PtBrLocale(), + 'code': 'pt_br', + 'ordinals': ['º', 'º', 'º', 'º'], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': PtRelativeTime() + }, + { + 'locale': PlLocale(), + 'code': 'pl', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': PlRelativeTime() + }, + { + 'locale': TrLocale(), + 'code': 'tr', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': TrRelativeTime() + }, + { + 'locale': SvLocale(), + 'code': 'sv', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': SvRelativeTime() + }, + { + 'locale': NbLocale(), + 'code': 'nb', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': NbRelativeTime() + }, + { + 'locale': FaLocale(), + 'code': 'fa', + 'ordinals': ['م', 'م', 'م', 'م'], + 'startOfWeek': StartOfWeek.saturday, + 'relativeTime': FaRelativeTime() + }, + { + 'locale': BnLocale(), + 'code': 'bn', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': BnRelativeTime() + }, + { + 'locale': NlLocale(), + 'code': 'nl', + 'ordinals': ['.', '.', '.', '.'], + 'startOfWeek': StartOfWeek.monday, + 'relativeTime': NlRelativeTime() + }, + { + 'locale': ThLocale(), + 'code': 'th', + 'ordinals': ['', '', '', ''], + 'startOfWeek': StartOfWeek.sunday, + 'relativeTime': ThRelativeTime() + }, + ]; +} + +List> localesRelativeDateTimeTestData() { + return [ + // EnLocale + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'in a few seconds', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'in a few seconds', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'a few seconds ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'in a minute', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'a minute ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'in 2 minutes', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 minutes ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'in an hour', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'an hour ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'in 2 hours', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 hours ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'in a day', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'a day ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'in 3 days', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 days ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'in a month', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'a month ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'in 2 months', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 months ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'in a year', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'a year ago', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'in 3 years', + }, + { + 'locale': EnLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 years ago', + }, + + // EsLocale + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'en un momento', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'en un momento', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'hace un momento', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'en un minuto', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'hace un minuto', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'en 2 minutos', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': 'hace 2 minutos', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'en una hora', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'hace una hora', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'en 2 horas', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': 'hace 2 horas', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'en un día', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'hace un día', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'en 3 días', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': 'hace 3 días', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'en un mes', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'hace un mes', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'en 2 meses', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': 'hace 2 meses', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'en un año', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'hace un año', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'en 3 años', + }, + { + 'locale': EsLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': 'hace 3 años', + }, + + // FrLocale + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'dans quelques secondes', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'dans quelques secondes', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'il y a quelques secondes', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'dans une minute', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'il y a une minute', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'dans 2 minutes', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': 'il y a 2 minutes', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'dans une heure', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'il y a une heure', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'dans 2 heures', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': 'il y a 2 heures', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'dans un jour', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'il y a un jour', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'dans 3 jours', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': 'il y a 3 jours', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'dans un mois', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'il y a un mois', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'dans 2 mois', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': 'il y a 2 mois', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'dans un an', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'il y a un an', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'dans 3 ans', + }, + { + 'locale': FrLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': 'il y a 3 ans', + }, + + // ZhLocale + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '幾秒内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': '幾秒内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '幾秒前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': '1 分鐘内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': '1 分鐘前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 分鐘内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 分鐘前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': '1 小時内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': '1 小時前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 小時内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 小時前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '1 天内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': '1 天前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 天内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 天前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': '1 個月内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': '1 個月前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 個月内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 個月前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '1 年内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': '1 年前', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 年内', + }, + { + 'locale': ZhLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 年前', + }, + + // ZhCnLocale + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '几秒内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': '几秒内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '几秒前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': '1 分钟内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': '1 分钟前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 分钟内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 分钟前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': '1 小时内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': '1 小时前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 小时内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 小时前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '1 天内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': '1 天前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 天内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 天前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': '1 个月内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': '1 个月前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 个月内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 个月前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '1 年内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': '1 年前', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 年内', + }, + { + 'locale': ZhCnLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 年前', + }, + + // DeLocale + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'in ein paar Sekunden', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'in ein paar Sekunden', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'vor ein paar Sekunden', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'in einer Minute', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'vor einer Minute', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'in 2 Minuten', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': 'vor 2 Minuten', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'in einer Stunde', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'vor einer Stunde', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'in 2 Stunden', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': 'vor 2 Stunden', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'in einem Tag', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'vor einem Tag', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'in 3 Tagen', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': 'vor 3 Tagen', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'in einem Monat', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'vor einem Monat', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'in 2 Monaten', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': 'vor 2 Monaten', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'in einem Jahr', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'vor einem Jahr', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'in 3 Jahren', + }, + { + 'locale': DeLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': 'vor 3 Jahren', + }, + + // ItLocale + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'tra alcuni secondi', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'tra alcuni secondi', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'alcuni secondi fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'tra un minuto', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'un minuto fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'tra 2 minuti', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 minuti fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'tra un\'ora', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'un\'ora fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'tra 2 ore', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 ore fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'tra un giorno', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'un giorno fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'tra 3 giorni', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 giorni fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'tra un mese', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'un mese fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'tra 2 mesi', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 mesi fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'tra un anno', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'un anno fa', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'tra 3 anni', + }, + { + 'locale': ItLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 anni fa', + }, + + // ArLocale + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'بعد ثانية واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'بعد ثانية واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'منذ ثانية واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'بعد دقيقة واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'منذ دقيقة واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'بعد دقيقتين', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': 'منذ دقيقتين', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'بعد ساعة واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'منذ ساعة واحدة', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'بعد ساعتين', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': 'منذ ساعتين', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'بعد يوم واحد', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'منذ يوم واحد', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'بعد ۳ ايام ', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': 'منذ ۳ ايام ', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'بعد شهر واحد', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'منذ شهر واحد', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'بعد شهرين', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': 'منذ شهرين', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'بعد عام واحد', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'منذ عام واحد', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'بعد ۳ أعوام ', + }, + { + 'locale': ArLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': 'منذ ۳ أعوام ', + }, + + // ArSaLocale + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'في ثوان', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'في ثوان', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'منذ ثوان', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'في دقيقة', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'منذ دقيقة', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'في ۲ دقائق ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': 'منذ ۲ دقائق ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'في ساعة', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'منذ ساعة', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'في ۲ ساعات ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': 'منذ ۲ ساعات ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'في يوم', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'منذ يوم', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'في ۳ أيام ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': 'منذ ۳ أيام ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'في شهر', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'منذ شهر', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'في ۲ أشهر ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': 'منذ ۲ أشهر ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'في سنة', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'منذ سنة', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'في ۳ سنوات ', + }, + { + 'locale': ArSaLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': 'منذ ۳ سنوات ', + }, + + // AzLocale + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'bir neçə saniyə sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'bir neçə saniyə sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'bir neçə saniyə geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'dəqiqə sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'dəqiqə geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 dəqiqə sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 dəqiqə geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'saat sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'saat geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 saat sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 saat geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'gün sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'gün geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 gün sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 gün geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'ay sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'ay geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 ay sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 ay geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'il sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'il geri', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 il sonra', + }, + { + 'locale': AzLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 il geri', + }, + + // IdLocale + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'dalam beberapa detik', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'dalam beberapa detik', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'beberapa detik yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'dalam satu menit', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'satu menit yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'dalam 2 menit', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 menit yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'dalam satu jam', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'satu jam yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'dalam 2 jam', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 jam yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'dalam satu hari', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'satu hari yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'dalam 3 hari', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 hari yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'dalam satu bulan', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'satu bulan yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'dalam 2 bulan', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 bulan yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'dalam satu tahun', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'satu tahun yang lalu', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'dalam 3 tahun', + }, + { + 'locale': IdLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 tahun yang lalu', + }, + + // JaLocale + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '数秒後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': '数秒後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '数秒前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': '1分後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': '1分前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2分後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2分前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': '1時間後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': '1時間前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2時間後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2時間前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '1日後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': '1日前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3日後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3日前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': '1ヶ月後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': '1ヶ月前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2ヶ月後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2ヶ月前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '1年後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': '1年前', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3年後', + }, + { + 'locale': JaLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3年前', + }, + + // KoLocale + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '몇 초 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': '몇 초 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': '몇 초 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': '1분 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': '1분 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2분 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2분 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': '한 시간 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': '한 시간 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2시간 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2시간 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '하루 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': '하루 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3일 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3일 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': '한 달 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': '한 달 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2달 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2달 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '일 년 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': '일 년 전', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3년 후', + }, + { + 'locale': KoLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3년 전', + }, + + // RuLocale + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'через несколько секунд', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'через несколько секунд', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'несколько секунд назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'через минуту', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'минуту назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'через 2 минуты', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 минуты назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'через час', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'час назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'через 2 часа', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 часа назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'через день', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'день назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'через 3 дня', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 дня назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'через месяц', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'месяц назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'через 2 месяца', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 месяца назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'через год', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'год назад', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'через 3 года', + }, + { + 'locale': RuLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 года назад', + }, + + // UkLocale + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'через декілька секунд', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'через декілька секунд', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'декілька секунд тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'через хвилину', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'хвилину тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'через 2 хвилини', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 хвилини тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'через годину', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'годину тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'через 2 години', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 години тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'через день', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'день тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'через 3 дні', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 дні тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'через місяць', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'місяць тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'через 2 місяці', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 місяці тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'через рік', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'рік тому', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'через 3 роки', + }, + { + 'locale': UkLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 роки тому', + }, + + // HiLocale + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'कुछ ही क्षण में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'कुछ ही क्षण में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'कुछ ही क्षण पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'एक मिनट में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'एक मिनट पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 मिनट में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 मिनट पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'एक घंटा में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'एक घंटा पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 घंटे में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 घंटे पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'एक दिन में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'एक दिन पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 दिन में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 दिन पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'एक महीने में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'एक महीने पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 महीने में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 महीने पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'एक वर्ष में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'एक वर्ष पहले', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 वर्ष में', + }, + { + 'locale': HiLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 वर्ष पहले', + }, + + // HuLocale + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'néhány másodperccel ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'néhány másodperccel ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'néhány másodperccel ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'egy perccel ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'egy perccel ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 perccel ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 perccel ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'egy órával ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'egy órával ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 órával ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 órával ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'egy nappal ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'egy nappal ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 nappal ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 nappal ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'egy hónappal ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'egy hónappal ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 hónappal ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 hónappal ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'egy évvel ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'egy évvel ezelőtt', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 évvel ezután', + }, + { + 'locale': HuLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 évvel ezelőtt', + }, + + // PtLocale + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'em segundos', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'em segundos', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'há segundos', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'em um minuto', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'há um minuto', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'em 2 minutos', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': 'há 2 minutos', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'em uma hora', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'há uma hora', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'em 2 horas', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': 'há 2 horas', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'em um dia', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'há um dia', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'em 3 dias', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': 'há 3 dias', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'em um mês', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'há um mês', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'em 2 meses', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': 'há 2 meses', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'em um ano', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'há um ano', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'em 3 anos', + }, + { + 'locale': PtLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': 'há 3 anos', + }, + + // PlLocale + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'za kilka sekund', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'za kilka sekund', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'kilka sekund temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'za minutę', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'minutę temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'za 2 minuty', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 minuty temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'za godzinę', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'godzinę temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'za 2 godziny', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 godziny temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'za 1 dzień', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': '1 dzień temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'za 3 dni', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 dni temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'za miesiąc', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'miesiąc temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'za 2 miesiące', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 miesiące temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'za rok', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'rok temu', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'za 3 lata', + }, + { + 'locale': PlLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 lata temu', + }, + + // TrLocale + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'birkaç saniye içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'birkaç saniye içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'birkaç saniye önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'bir dakika içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'bir dakika önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 dakika içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 dakika önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'bir saat içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'bir saat önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 saat içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 saat önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'bir gün içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'bir gün önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 gün içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 gün önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'bir ay içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'bir ay önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 ay içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 ay önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'bir yıl içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'bir yıl önce', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 yıl içinde', + }, + { + 'locale': TrLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 yıl önce', + }, + + // SvLocale + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'om några sekunder', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'om några sekunder', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'några sekunder sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'om en minut', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'en minut sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'om 2 minuter', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 minuter sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'om en timme', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'en timme sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'om 2 timmar', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 timmar sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'om en dag', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'en dag sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'om 3 dagar', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 dagar sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'om en månad', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'en månad sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'om 2 månader', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 månader sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'om ett år', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'ett år sedan', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'om 3 år', + }, + { + 'locale': SvLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 år sedan', + }, + + // NbLocale + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'om noen sekunder', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'om noen sekunder', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'noen sekunder siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'om ett minutt', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'ett minutt siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'om 2 minutter', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 minutter siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'om en time', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'en time siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'om 2 timer', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 timer siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'om en dag', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'en dag siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'om 3 dager', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 dager siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'om en måned', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'en måned siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'om 2 måneder', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 måneder siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'om ett år', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'ett år siden', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'om 3 år', + }, + { + 'locale': NbLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 år siden', + }, + + // FaLocale + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'چند ثانیه بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'چند ثانیه بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'چند ثانیه پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'یک دقیقه بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'یک دقیقه پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '۲ دقیقه بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '۲ دقیقه پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'یک ساعت بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'یک ساعت پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '۲ ساعت بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '۲ ساعت پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'یک روز بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'یک روز پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '۳ روز بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '۳ روز پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'یک ماه بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'یک ماه پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '۲ ماه بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '۲ ماه پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'یک سال بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'یک سال پیش', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '۳ سال بعد', + }, + { + 'locale': FaLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '۳ سال پیش', + }, + + // BnLocale + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'কিছু মুহূর্ত পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'কিছু মুহূর্ত পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'কিছু মুহূর্ত আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'এক মিনিট পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'এক মিনিট আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '২ মিনিট পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '২ মিনিট আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'এক ঘন্টা পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'এক ঘন্টা আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '২ ঘন্টা পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '২ ঘন্টা আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'এক দিন পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'এক দিন আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '৩ দিন পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '৩ দিন আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'এক মাস পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'এক মাস আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '২ মাস পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '২ মাস আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'এক বছর পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'এক বছর আগে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '৩ বছর পরে', + }, + { + 'locale': BnLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '৩ বছর আগে', + }, + + // NlLocale + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'een ogenblik', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'op dit moment', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'op dit moment geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'een minuut', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': 'een minuut geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': '2 minuten', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 minuten geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'een uur', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': 'een uur geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': '2 uur', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 uur geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'een dag', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': 'een dag geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': '3 dagen', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 dagen geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'een maand', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': 'een maand geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': '2 maanden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 maanden geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'een jaar', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': 'een jaar geleden', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': '3 jaar', + }, + { + 'locale': NlLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 jaar geleden', + }, + + // ThLocale + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'อีกไม่กี่วินาที', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'expectedRelativeDateTime': 'อีกไม่กี่วินาที', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22), + 'expectedRelativeDateTime': 'ไม่กี่วินาทีที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'expectedRelativeDateTime': 'อีก1 นาที', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 11, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0), + 'expectedRelativeDateTime': '1 นาทีที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 1), + 'secondDateTime': DateTime(1997, 10, 23, 12, 3), + 'expectedRelativeDateTime': 'อีก2 นาที', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 3), + 'secondDateTime': DateTime(1997, 10, 23, 12, 1), + 'expectedRelativeDateTime': '2 นาทีที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 0), + 'secondDateTime': DateTime(1997, 10, 23, 12, 45), + 'expectedRelativeDateTime': 'อีก1 ชั่วโมง', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 12, 45), + 'secondDateTime': DateTime(1997, 10, 23, 12, 0), + 'expectedRelativeDateTime': '1 ชั่วโมงที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 1), + 'secondDateTime': DateTime(1997, 10, 23, 3), + 'expectedRelativeDateTime': 'อีก2 ชั่วโมง', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23, 3), + 'secondDateTime': DateTime(1997, 10, 23, 1), + 'expectedRelativeDateTime': '2 ชั่วโมงที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 22), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'อีก1 วัน', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 22), + 'expectedRelativeDateTime': '1 วันที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 20), + 'secondDateTime': DateTime(1997, 10, 23), + 'expectedRelativeDateTime': 'อีก3 วัน', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 23), + 'secondDateTime': DateTime(1997, 10, 20), + 'expectedRelativeDateTime': '3 วันที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10, 1), + 'secondDateTime': DateTime(1997, 11, 1), + 'expectedRelativeDateTime': 'อีก1 เดือน', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 11, 1), + 'secondDateTime': DateTime(1997, 10, 1), + 'expectedRelativeDateTime': '1 เดือนที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 10), + 'secondDateTime': DateTime(1997, 12), + 'expectedRelativeDateTime': 'อีก2 เดือน', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997, 12), + 'secondDateTime': DateTime(1997, 10), + 'expectedRelativeDateTime': '2 เดือนที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'อีก1 ปี', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'expectedRelativeDateTime': '1 ปีที่แล้ว', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1995), + 'secondDateTime': DateTime(1998), + 'expectedRelativeDateTime': 'อีก3 ปี', + }, + { + 'locale': ThLocale(), + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1995), + 'expectedRelativeDateTime': '3 ปีที่แล้ว', + }, + ]; +} diff --git a/test/src/manipulator_test.dart b/test/src/manipulator_test.dart new file mode 100644 index 0000000..abcc8d8 --- /dev/null +++ b/test/src/manipulator_test.dart @@ -0,0 +1,444 @@ +import 'package:jiffy/src/getter.dart'; +import 'package:jiffy/src/enums/start_of_week.dart'; +import 'package:jiffy/src/enums/unit.dart'; +import 'package:jiffy/src/manipulator.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + final getter = Getter(); + final underTest = Manipulator(getter); + + group('Test adding and subtracting datetime using Durations', () { + test('Should successfully add datetime using durations', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final duration = Duration( + microseconds: 100, + milliseconds: 200, + seconds: 3, + minutes: 4, + hours: 2, + days: 3); + + final expectedDateTime = DateTime(1997, 9, 26, 14, 15, 25, 323, 556); + + // Execute + final actualDateTime = underTest.addDuration(dateTime, duration); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully add datetime when duration is set to zero', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final duration = Duration.zero; + + // Execute + final actualDateTime = underTest.addDuration(dateTime, duration); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + dateTime.microsecondsSinceEpoch); + }); + + test('Should successfully subtract datetime using durations', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final duration = Duration( + microseconds: 100, + milliseconds: 100, + seconds: 3, + minutes: 4, + hours: 2, + days: 3); + + final expectedDateTime = DateTime(1997, 9, 20, 10, 7, 19, 23, 356); + + // Execute + final actualDateTime = underTest.subtractDuration(dateTime, duration); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully subtract datetime when duration is set to zero', + () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final duration = Duration.zero; + + // Execute + final actualDateTime = underTest.subtractDuration(dateTime, duration); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + dateTime.microsecondsSinceEpoch); + }); + }); + + group('Test adding and subtracting datetime using values', () { + test('Should successfully add datetime', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final microseconds = 100; + final milliseconds = 200; + final seconds = 3; + final minutes = 4; + final hours = 2; + final days = 3; + final weeks = 1; + final months = 4; + final years = 2; + + final expectedDateTime = DateTime(2000, 2, 3, 14, 15, 25, 323, 556); + + // Execute + final actualDateTime = underTest.add(dateTime, microseconds, milliseconds, + seconds, minutes, hours, days, weeks, months, years); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully subtract datetime', () { + // Setup + final dateTime = DateTime(1997, 9, 23, 12, 11, 22, 123, 456); + final microseconds = 100; + final milliseconds = 100; + final seconds = 3; + final minutes = 4; + final hours = 2; + final days = 3; + final weeks = 1; + final months = 4; + final years = 2; + + final expectedDateTime = DateTime(1995, 5, 13, 10, 7, 19, 23, 356); + + // Execute + final actualDateTime = underTest.subtract(dateTime, microseconds, + milliseconds, seconds, minutes, hours, days, weeks, months, years); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + expectedDateTime.microsecondsSinceEpoch); + }); + }); + + // test adding and subtracting weeks + + group('Test startOf datetime', () { + for (var testData in startOfDateTimeTestData()) { + test('Should successfully get start of datetime', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualDateTime = underTest.startOf( + testData['dateTime'], testData['unit'], startOfWeek); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + testData['expectedDateTime'].microsecondsSinceEpoch); + }); + } + + for (var testData in startOfWeekWithLocaleDateTimeTestData()) { + test('Should successfully get start of week base in local datetime', () { + // Setup + final unit = Unit.week; + + // Execute + final actualDateTime = underTest.startOf( + testData['dateTime'], unit, testData['startOfWeek']); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + testData['expectedDateTime'].microsecondsSinceEpoch); + }); + } + }); + + group('Test endOf datetime', () { + for (var testData in endOfDateTimeTestData()) { + test('Should successfully get end of datetime', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualDateTime = underTest.endOf( + testData['dateTime'], testData['unit'], startOfWeek); + + // Verify + expect(actualDateTime.microsecondsSinceEpoch, + testData['expectedDateTime'].microsecondsSinceEpoch); + }); + } + + for (var testData in endOfWeekWithLocaleDateTimeTestData()) { + test('Should successfully get end of week base in local datetime', () { + // Setup + final unit = Unit.week; + + // Execute + final actualDateTime = underTest.endOf( + testData['dateTime'], unit, testData['startOfWeek']); + + // Verify + expect(actualDateTime, testData['expectedDateTime']); + }); + } + }); + + group('Test toLocal and toUtc', () { + test('Should successfully convert utc datetime to local', () { + // Setup + final utcDateTime = DateTime(1997, 9, 23); + + final expectedLocalDateTime = utcDateTime.toLocal(); + + // Execute + final actualDateTime = underTest.toLocal(utcDateTime); + + // Verify + expect(actualDateTime.isUtc, expectedLocalDateTime.isUtc); + expect(actualDateTime.microsecondsSinceEpoch, + expectedLocalDateTime.microsecondsSinceEpoch); + }); + + test('Should successfully convert local datetime to utc', () { + // Setup + final localDateTime = DateTime(1997, 9, 23); + + final expectedUTCDateTime = localDateTime.toUtc(); + + // Execute + final actualDateTime = underTest.toUtc(localDateTime); + + // Verify + expect(actualDateTime.isUtc, expectedUTCDateTime.isUtc); + expect(actualDateTime.microsecondsSinceEpoch, + expectedUTCDateTime.microsecondsSinceEpoch); + }); + }); +} + +List> startOfDateTimeTestData() { + return [ + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.microsecond, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.millisecond, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.second, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 22, 0, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.minute, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 0, 0, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.hour, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 0, 0, 0, 0, 0), + 'unit': Unit.day, + 'expectedDateTime': DateTime(1997, 9, 23, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.week, + 'expectedDateTime': DateTime(1997, 9, 22, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.month, + 'expectedDateTime': DateTime(1997, 9, 1, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.year, + 'expectedDateTime': DateTime(1997, 1, 1, 0, 0, 0, 0, 0) + } + ]; +} + +List> startOfWeekWithLocaleDateTimeTestData() { + return [ + { + 'dateTime': DateTime(2022, 12, 6, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 12, 5, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 12, 5, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 12, 5, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 2, 28, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 2, 28, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 3, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 2, 28, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 12, 6, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDateTime': DateTime(2022, 12, 4, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 12, 4, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDateTime': DateTime(2022, 12, 4, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 3, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDateTime': DateTime(2022, 2, 27, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 12, 6, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDateTime': DateTime(2022, 12, 3, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 12, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDateTime': DateTime(2022, 12, 3, 0, 0, 0, 0, 0) + }, + { + 'dateTime': DateTime(2022, 3, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDateTime': DateTime(2022, 2, 26, 0, 0, 0, 0, 0) + }, + ]; +} + +List> endOfDateTimeTestData() { + return [ + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.microsecond, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.millisecond, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.second, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 22, 999, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.minute, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 11, 59, 999, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.hour, + 'expectedDateTime': DateTime(1997, 9, 23, 12, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.day, + 'expectedDateTime': DateTime(1997, 9, 23, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.week, + 'expectedDateTime': DateTime(1997, 9, 28, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.month, + 'expectedDateTime': DateTime(1997, 9, 30, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2020, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.month, + 'expectedDateTime': DateTime(2020, 9, 30, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2020, 2, 23, 12, 11, 22, 123, 456), + 'unit': Unit.month, + 'expectedDateTime': DateTime(2020, 2, 29, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 456), + 'unit': Unit.year, + 'expectedDateTime': DateTime(1997, 12, 31, 23, 59, 59, 999, 999), + } + ]; +} + +List> endOfWeekWithLocaleDateTimeTestData() { + return [ + { + 'dateTime': DateTime(2022, 12, 6, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 12, 11, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 12, 5, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 12, 11, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 3, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.monday, + 'expectedDateTime': DateTime(2022, 3, 6, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 12, 6, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDateTime': DateTime(2022, 12, 10, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 12, 4, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDateTime': DateTime(2022, 12, 10, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 3, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.sunday, + 'expectedDateTime': DateTime(2022, 3, 5, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 12, 6, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDateTime': DateTime(2022, 12, 9, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 12, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDateTime': DateTime(2022, 12, 9, 23, 59, 59, 999, 999) + }, + { + 'dateTime': DateTime(2022, 3, 3, 12, 11, 22, 123, 456), + 'startOfWeek': StartOfWeek.saturday, + 'expectedDateTime': DateTime(2022, 3, 4, 23, 59, 59, 999, 999) + }, + ]; +} diff --git a/test/src/parser_test.dart b/test/src/parser_test.dart new file mode 100644 index 0000000..06a00e5 --- /dev/null +++ b/test/src/parser_test.dart @@ -0,0 +1,329 @@ +import 'package:jiffy/src/enums/unit.dart'; +import 'package:jiffy/src/getter.dart'; +import 'package:jiffy/src/locale/locales/en_locale.dart'; +import 'package:jiffy/src/parser.dart'; +import 'package:jiffy/src/utils/jiffy_exception.dart'; +import 'package:test/test.dart'; + +void main() { + final getter = Getter(); + final underTest = Parser(getter); + + final locale = EnLocale(); + + group('Test parsing datetime from string', () { + for (var testData in fromStringWithPatternTestData()) { + test('Should successfully parse datetime from pattern', () { + // Execute + final actualDateTime = underTest.fromString( + testData['input'], testData['pattern'], locale, false); + + // Verify + expect(actualDateTime, testData['expected']); + }); + } + + for (var testData in fromStringWithPatternAMAndPMTestData()) { + test('Should successfully parse datetime if pattern contains am pm', () { + // Execute + final actualDateTime = underTest.fromString( + testData['input'], testData['pattern'], locale, false); + + // Verify + expect(actualDateTime, testData['expected']); + }); + } + + test('Should throw JiffyException if pattern is provided and is empty', () { + // Setup + final input = '2022-12-25'; + final pattern = ''; + + final expectedExceptionMessage = 'The provided pattern for input ' + '`$input` cannot be blank'; + + // Execute and Verify + expect( + () => underTest.fromString(input, pattern, locale, false), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + + test('Should throw JiffyException if datetime cannot be parsed', () { + // Setup + final input = '2022-12-25'; + final pattern = 'invalid-pattern'; + + final expectedExceptionMessage = 'JiffyException: Could not parse input ' + '`$input`, failed with the following error:'; + + // Execute and Verify + expect( + () => underTest.fromString(input, pattern, locale, false), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + + for (var testData in fromStringWithBasicDateTimeTestData()) { + test('Should successfully parse basic datetime format', () { + // Setup + final pattern = null; + + // Execute + final actualDateTime = + underTest.fromString(testData['input'], pattern, locale, false); + + // Verify + expect(actualDateTime, testData['expected']); + }); + } + + for (var testData in fromStringWithDateTimeAndISOTestData()) { + test('Should successfully parse DateTime and ISO datetime format', () { + // Setup + final pattern = null; + + // Execute + final actualDateTime = + underTest.fromString(testData['input'], pattern, locale, false); + + // Verify + expect(actualDateTime, testData['expected']); + }); + } + + test('Should throw JiffyException if input datetime cannot be parsed', () { + // Setup + final input = 'invalid-input-date-time'; + final pattern = null; + + final expectedExceptionMessage = 'Could not read date time of input' + ' `$input`, try using a pattern, e.g. ' + 'input: "12, Oct", pattern: "dd, MMM"'; + + // Execute and Verify + expect( + () => underTest.fromString(input, pattern, locale, false), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + + test('Should successfully pass date time if it is in Utc', () { + // Setup + final input = '1997 Sep 23th'; + final pattern = 'yyyy MMM do'; + + final expected = DateTime.utc(1997, 9, 23); + + // Execute + final actual = underTest.fromString(input, pattern, locale, true); + + // Verify + expect(actual, expected); + }); + }); + + group('Test parsing datetime from list', () { + for (var testData in fromListTestData()) { + test('Should successfully parse datetime as list', () { + // Execute + final actualDateTime = underTest.fromList(testData['input'], false); + + // Verify + expect(actualDateTime, testData['expected']); + }); + } + + test('Should throw JiffyException if datetime list is empty', () { + // Setup + final input = []; + + final expectedExceptionMessage = 'The provided datetime list cannot ' + 'be empty'; + + // Execute and Verify + expect( + () => underTest.fromList(input, false), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + + test('Should successfully pass date time as list if it is in Utc', () { + // Setup + final list = [1997, 9, 23]; + + final expected = DateTime.utc(1997, 9, 23); + + // Execute + final actual = underTest.fromList(list, true); + + // Verify + expect(actual, expected); + }); + }); + + group('Test parsing datetime from map', () { + test('Should successfully parse datetime as map', () { + // Setup + final input = { + Unit.year: 1997, + Unit.month: 9, + Unit.day: 23, + Unit.hour: 12, + Unit.minute: 22, + Unit.second: 11, + Unit.millisecond: 123, + Unit.microsecond: 456, + }; + + final expectedDateTime = DateTime(1997, 9, 23, 12, 22, 11, 123, 456); + // Execute + final actualDateTime = underTest.fromMap(input, false); + + // Verify + expect(actualDateTime, expectedDateTime); + }); + + test('Should throw JiffyException if datetime map is empty', () { + // Setup + final input = {}; + + final expectedExceptionMessage = 'The provided datetime map cannot ' + 'be empty'; + + // Execute and Verify + expect( + () => underTest.fromMap(input, false), + throwsA(isA().having((e) => e.toString(), 'message', + contains(expectedExceptionMessage)))); + }); + + test('Should successfully pass date time as map if it is in Utc', () { + // Setup + final map = { + Unit.year: 1997, + Unit.month: 9, + Unit.day: 23, + Unit.hour: 12, + Unit.minute: 22, + Unit.second: 11, + Unit.millisecond: 123, + Unit.microsecond: 456, + }; + + final expected = DateTime.utc(1997, 9, 23, 12, 22, 11, 123, 456); + + // Execute + final actual = underTest.fromMap(map, true); + + // Verify + expect(actual, expected); + }); + }); +} + +List> fromStringWithPatternTestData() { + return [ + { + 'input': '1997 Sep 23th', + 'pattern': 'yyyy MMM do', + 'expected': DateTime(1997, 9, 23) + }, + { + 'input': '2022 12 25', + 'pattern': 'yyyy MM d', + 'expected': DateTime(2022, 12, 25) + }, + { + 'input': 'January 1st 2021, 12:00:00 AM', + 'pattern': 'MMMM do yyyy, HH:mm:ss a', + 'expected': DateTime(2021, 1, 1, 12) + } + ]; +} + +List> fromStringWithPatternAMAndPMTestData() { + return [ + { + 'input': '1997 Sep 23rd 3:14 pm', + 'pattern': 'yyyy MMM do h:mm a', + 'expected': DateTime(1997, 9, 23, 15, 14) + }, + { + 'input': '1997 Sep 23rd 3 pm', + 'pattern': 'yyyy MMM do h a', + 'expected': DateTime(1997, 9, 23, 15, 0) + }, + { + 'input': '1997 Sep 23rd 3:14 am', + 'pattern': 'yyyy MMM do h:mm a', + 'expected': DateTime(1997, 9, 23, 3, 14) + }, + { + 'input': '1997 Sep 23rd 3 am', + 'pattern': 'yyyy MMM do h a', + 'expected': DateTime(1997, 9, 23, 3, 0) + }, + ]; +} + +List> fromStringWithBasicDateTimeTestData() { + return [ + {'input': '1997-09-23', 'expected': DateTime(1997, 9, 23)}, + {'input': '1997-9-02', 'expected': DateTime(1997, 9, 2)}, + {'input': '1997-12-2', 'expected': DateTime(1997, 12, 2)}, + {'input': '2022/02/25', 'expected': DateTime(2022, 2, 25)}, + {'input': '2022/5/05', 'expected': DateTime(2022, 5, 5)}, + {'input': '2022/10/5', 'expected': DateTime(2022, 10, 5)} + ]; +} + +List> fromStringWithDateTimeAndISOTestData() { + return [ + { + 'input': '2022-12-26 11:18:12.946621', + 'expected': DateTime(2022, 12, 26, 11, 18, 12, 946, 621) + }, + { + 'input': '2022-12-26T11:18:12.947031', + 'expected': DateTime(2022, 12, 26, 11, 18, 12, 947, 031) + } + ]; +} + +List> fromListTestData() { + return [ + { + 'input': [1997], + 'expected': DateTime(1997) + }, + { + 'input': [1997, 9], + 'expected': DateTime(1997, 9) + }, + { + 'input': [1997, 9, 23], + 'expected': DateTime(1997, 9, 23) + }, + { + 'input': [1997, 9, 23, 12], + 'expected': DateTime(1997, 9, 23, 12) + }, + { + 'input': [1997, 9, 23, 12, 11], + 'expected': DateTime(1997, 9, 23, 12, 11) + }, + { + 'input': [1997, 9, 23, 12, 11, 22], + 'expected': DateTime(1997, 9, 23, 12, 11, 22) + }, + { + 'input': [1997, 9, 23, 12, 11, 22, 123], + 'expected': DateTime(1997, 9, 23, 12, 11, 22, 123) + }, + { + 'input': [1997, 9, 23, 12, 11, 22, 123, 456], + 'expected': DateTime(1997, 9, 23, 12, 11, 22, 123, 456) + }, + ]; +} diff --git a/test/src/query_test.dart b/test/src/query_test.dart new file mode 100644 index 0000000..7adfa36 --- /dev/null +++ b/test/src/query_test.dart @@ -0,0 +1,1904 @@ +import 'package:jiffy/jiffy.dart'; +import 'package:jiffy/src/getter.dart'; +import 'package:jiffy/src/manipulator.dart'; +import 'package:jiffy/src/query.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + final getter = Getter(); + final manipulator = Manipulator(getter); + final underTest = Query(getter, manipulator); + + group('Test isBefore query', () { + for (var testData in isBeforeDateTimeTestData()) { + test('Should successfully return if datetime is before', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualIsBefore = underTest.isBefore(testData['firstDateTime'], + testData['secondDateTime'], testData['unit'], startOfWeek); + + // Verify + expect(actualIsBefore, testData['expectedIsBefore']); + }); + } + + for (var testData in isBeforeDateTimeWithStartOfWeekTestData()) { + test( + 'Should successfully return if datetime is before with start of week', + () { + // Setup + final unit = Unit.week; + + // Execute + final actualIsBefore = underTest.isBefore(testData['firstDateTime'], + testData['secondDateTime'], unit, testData['startOfWeek']); + + // Verify + expect(actualIsBefore, testData['expectedIsBefore']); + }); + } + }); + + group('Test isAfter query', () { + for (var testData in isAfterDateTimeTestData()) { + test('Should successfully return if datetime is after', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualIsAfter = underTest.isAfter(testData['firstDateTime'], + testData['secondDateTime'], testData['unit'], startOfWeek); + + // Verify + expect(actualIsAfter, testData['expectedIsAfter']); + }); + } + + for (var testData in isAfterDateTimeWithStartOfWeekTestData()) { + test('Should successfully return if datetime is after with start of week', + () { + // Setup + final unit = Unit.week; + + // Execute + final actualIsAfter = underTest.isAfter(testData['firstDateTime'], + testData['secondDateTime'], unit, testData['startOfWeek']); + + // Verify + expect(actualIsAfter, testData['expectedIsAfter']); + }); + } + }); + + group('Test isSame query', () { + for (var testData in isSameDateTimeTestData()) { + test('Should successfully return if datetime is same', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualIsSame = underTest.isSame(testData['firstDateTime'], + testData['secondDateTime'], testData['unit'], startOfWeek); + + // Verify + expect(actualIsSame, testData['expectedIsSame']); + }); + } + + for (var testData in isSameDateTimeWithStartOfWeekTestData()) { + test('Should successfully return if datetime is same with start of week', + () { + // Setup + final unit = Unit.week; + + // Execute + final actualIsSame = underTest.isSame(testData['firstDateTime'], + testData['secondDateTime'], unit, testData['startOfWeek']); + + // Verify + expect(actualIsSame, testData['expectedIsSame']); + }); + } + }); + + group('Test isSameOrBefore query', () { + for (var testData in isSameOrBeforeTimeTestData()) { + test('Should successfully return if datetime is same or before', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualIsSameOrBefore = underTest.isSameOrBefore( + testData['firstDateTime'], + testData['secondDateTime'], + testData['unit'], + startOfWeek); + + // Verify + expect(actualIsSameOrBefore, testData['expectedIsSameOrBefore']); + }); + } + + for (var testData in isSameOrBeforeDateTimeWithStartOfWeekTestData()) { + test( + 'Should successfully return if datetime is same or before with start of week', + () { + // Setup + final unit = Unit.week; + + // Execute + final actualIsSameOrBefore = underTest.isSameOrBefore( + testData['firstDateTime'], + testData['secondDateTime'], + unit, + testData['startOfWeek']); + + // Verify + expect(actualIsSameOrBefore, testData['expectedIsSameOrBefore']); + }); + } + }); + + group('Test isSameOrAfter query', () { + for (var testData in isSameOrAfterTimeTestData()) { + test('Should successfully return if datetime is same or after', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualIsSameOrAfter = underTest.isSameOrAfter( + testData['firstDateTime'], + testData['secondDateTime'], + testData['unit'], + startOfWeek); + + // Verify + expect(actualIsSameOrAfter, testData['expectedIsSameOrAfter']); + }); + } + + for (var testData in isSameOrAfterDateTimeWithStartOfWeekTestData()) { + test( + 'Should successfully return if datetime is same or before with start of week', + () { + // Setup + final unit = Unit.week; + + // Execute + final actualIsSameOrAfter = underTest.isSameOrAfter( + testData['firstDateTime'], + testData['secondDateTime'], + unit, + testData['startOfWeek']); + + // Verify + expect(actualIsSameOrAfter, testData['expectedIsSameOrAfter']); + }); + } + }); + + group('Test isBetween query', () { + for (var testData in isBetweenTimeTestData()) { + test('Should successfully return if datetime is between', () { + // Setup + final startOfWeek = StartOfWeek.monday; + + // Execute + final actualIsBetween = underTest.isBetween( + testData['firstDateTime'], + testData['secondDateTime'], + testData['thirdDateTime'], + testData['unit'], + startOfWeek); + + // Verify + expect(actualIsBetween, testData['expectedIsBetween']); + }); + } + + for (var testData in isBetweenDateTimeWithStartOfWeekTestData()) { + test( + 'Should successfully return if datetime is between with start of week', + () { + // Setup + final unit = Unit.week; + + // Execute + final actualIsBetween = underTest.isBetween( + testData['firstDateTime'], + testData['secondDateTime'], + testData['thirdDateTime'], + unit, + testData['startOfWeek']); + + // Verify + expect(actualIsBetween, testData['expectedIsBetween']); + }); + } + }); + + for (var testData in isUtcDateTimeTestData()) { + test('Should successfully check if date time is utc', () { + // Execute + final actualIsUtc = Query.isUtc(testData['dateTime']); + + // Verify + expect(actualIsUtc, testData['expectedIsUtc']); + }); + } + + for (var testData in isLeapYearTestData()) { + test('Should successfully check if year is a leap year', () { + // Execute + final actualIsLeapYear = Query.isLeapYear(testData['year']); + + // Verify + expect(actualIsLeapYear, testData['expectedIsLeapYear']); + }); + } +} + +List> isBeforeDateTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 1), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 3), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 1), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 3), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'unit': Unit.week, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 5), + 'unit': Unit.week, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 8), + 'unit': Unit.week, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 3), + 'unit': Unit.week, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1997, 3), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997, 2), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1996), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsBefore': false + }, + ]; +} + +List> isBeforeDateTimeWithStartOfWeekTestData() { + return [ + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 2), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 9), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBefore': false + }, + ]; +} + +List> isAfterDateTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 1), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 3), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 1), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 3), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'unit': Unit.week, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 5), + 'unit': Unit.week, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 8), + 'unit': Unit.week, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 3), + 'unit': Unit.week, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1997, 3), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997, 2), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1996), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsAfter': false + }, + ]; +} + +List> isAfterDateTimeWithStartOfWeekTestData() { + return [ + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 5), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 2), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsAfter': false + }, + ]; +} + +List> isSameDateTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 1), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 3), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(1997, 9, 1), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 3), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'unit': Unit.week, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 5), + 'unit': Unit.week, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 8), + 'unit': Unit.week, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 3), + 'unit': Unit.week, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 3), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997, 2), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(1996), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSame': true + }, + ]; +} + +List> isSameDateTimeWithStartOfWeekTestData() { + return [ + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 5), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSame': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 2), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSame': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSame': true + }, + ]; +} + +List> isSameOrBeforeTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 1), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 3), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 1), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 9, 3), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'unit': Unit.week, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 5), + 'unit': Unit.week, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 8), + 'unit': Unit.week, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 3), + 'unit': Unit.week, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1997, 3), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997, 2), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1996), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSameOrBefore': true + }, + ]; +} + +List> isSameOrBeforeDateTimeWithStartOfWeekTestData() { + return [ + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 5), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrBefore': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 2), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrBefore': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrBefore': true + }, + ]; +} + +List> isSameOrAfterTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'unit': Unit.microsecond, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'unit': Unit.millisecond, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'unit': Unit.second, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 2), + 'unit': Unit.minute, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 1), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 3), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 2), + 'unit': Unit.hour, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 1), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 9, 3), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 2), + 'unit': Unit.day, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'unit': Unit.week, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 5), + 'unit': Unit.week, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 8), + 'unit': Unit.week, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 3), + 'unit': Unit.week, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1997, 3), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997, 2), + 'secondDateTime': DateTime(1997, 2), + 'unit': Unit.month, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1996), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(1998), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(1997), + 'secondDateTime': DateTime(1997), + 'unit': Unit.year, + 'expectedIsSameOrAfter': true + }, + ]; +} + +List> isSameOrAfterDateTimeWithStartOfWeekTestData() { + return [ + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 5), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 4), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 5), + 'secondDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrAfter': false + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 7), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 2), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrAfter': true + }, + { + 'firstDateTime': DateTime(2022, 12, 6), + 'secondDateTime': DateTime(2022, 12, 3), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsSameOrAfter': true + }, + ]; +} + +List> isBetweenTimeTestData() { + return [ + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'unit': Unit.microsecond, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 0), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'unit': Unit.microsecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 4), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'unit': Unit.microsecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'unit': Unit.microsecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 123, 3), + 'unit': Unit.microsecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'unit': Unit.millisecond, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 0), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'unit': Unit.millisecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 4), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'unit': Unit.millisecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'unit': Unit.millisecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'unit': Unit.millisecond, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'unit': Unit.second, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 0), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'unit': Unit.second, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 4), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'unit': Unit.second, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 3), + 'unit': Unit.second, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 11, 22, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 11, 22, 3), + 'unit': Unit.second, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 2), + 'secondDateTime': DateTime(1997, 9, 23, 12, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 3), + 'unit': Unit.minute, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 0), + 'secondDateTime': DateTime(1997, 9, 23, 12, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 3), + 'unit': Unit.minute, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 4), + 'secondDateTime': DateTime(1997, 9, 23, 12, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 3), + 'unit': Unit.minute, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 1), + 'secondDateTime': DateTime(1997, 9, 23, 12, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 3), + 'unit': Unit.minute, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 12, 3), + 'secondDateTime': DateTime(1997, 9, 23, 12, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 12, 3), + 'unit': Unit.minute, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 2), + 'secondDateTime': DateTime(1997, 9, 23, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 3), + 'unit': Unit.hour, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 0), + 'secondDateTime': DateTime(1997, 9, 23, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 3), + 'unit': Unit.hour, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 4), + 'secondDateTime': DateTime(1997, 9, 23, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 3), + 'unit': Unit.hour, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 1), + 'secondDateTime': DateTime(1997, 9, 23, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 3), + 'unit': Unit.hour, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 23, 3), + 'secondDateTime': DateTime(1997, 9, 23, 1), + 'thirdDateTime': DateTime(1997, 9, 23, 3), + 'unit': Unit.hour, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 2), + 'secondDateTime': DateTime(1997, 9, 1), + 'thirdDateTime': DateTime(1997, 9, 3), + 'unit': Unit.day, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 9, 0), + 'secondDateTime': DateTime(1997, 9, 1), + 'thirdDateTime': DateTime(1997, 9, 3), + 'unit': Unit.day, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 4), + 'secondDateTime': DateTime(1997, 9, 1), + 'thirdDateTime': DateTime(1997, 9, 3), + 'unit': Unit.day, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 1), + 'secondDateTime': DateTime(1997, 9, 1), + 'thirdDateTime': DateTime(1997, 9, 3), + 'unit': Unit.day, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 9, 3), + 'secondDateTime': DateTime(1997, 9, 1), + 'thirdDateTime': DateTime(1997, 9, 3), + 'unit': Unit.day, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 2), + 'secondDateTime': DateTime(1997, 1), + 'thirdDateTime': DateTime(1997, 3), + 'unit': Unit.month, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 2), + 'thirdDateTime': DateTime(1997, 4), + 'unit': Unit.month, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 4), + 'secondDateTime': DateTime(1997, 1), + 'thirdDateTime': DateTime(1997, 3), + 'unit': Unit.month, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 1), + 'secondDateTime': DateTime(1997, 1), + 'thirdDateTime': DateTime(1997, 3), + 'unit': Unit.month, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1997, 3), + 'secondDateTime': DateTime(1997, 1), + 'thirdDateTime': DateTime(1997, 3), + 'unit': Unit.month, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1992), + 'secondDateTime': DateTime(1991), + 'thirdDateTime': DateTime(1993), + 'unit': Unit.year, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(1991), + 'secondDateTime': DateTime(1992), + 'thirdDateTime': DateTime(1994), + 'unit': Unit.year, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1994), + 'secondDateTime': DateTime(1991), + 'thirdDateTime': DateTime(1993), + 'unit': Unit.year, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1991), + 'secondDateTime': DateTime(1991), + 'thirdDateTime': DateTime(1993), + 'unit': Unit.year, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(1993), + 'secondDateTime': DateTime(1991), + 'thirdDateTime': DateTime(1993), + 'unit': Unit.year, + 'expectedIsBetween': false + }, + ]; +} + +List> isBetweenDateTimeWithStartOfWeekTestData() { + return [ + { + 'firstDateTime': DateTime(2022, 12, 14), + 'secondDateTime': DateTime(2022, 12, 5), + 'thirdDateTime': DateTime(2022, 12, 19), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(2022, 12, 8), + 'secondDateTime': DateTime(2022, 12, 12), + 'thirdDateTime': DateTime(2022, 12, 19), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 20), + 'secondDateTime': DateTime(2022, 12, 5), + 'thirdDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 7), + 'secondDateTime': DateTime(2022, 12, 5), + 'thirdDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 15), + 'secondDateTime': DateTime(2022, 12, 5), + 'thirdDateTime': DateTime(2022, 12, 12), + 'startOfWeek': StartOfWeek.monday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 14), + 'secondDateTime': DateTime(2022, 12, 4), + 'thirdDateTime': DateTime(2022, 12, 18), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(2022, 12, 8), + 'secondDateTime': DateTime(2022, 12, 11), + 'thirdDateTime': DateTime(2022, 12, 18), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 20), + 'secondDateTime': DateTime(2022, 12, 4), + 'thirdDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 7), + 'secondDateTime': DateTime(2022, 12, 4), + 'thirdDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 15), + 'secondDateTime': DateTime(2022, 12, 4), + 'thirdDateTime': DateTime(2022, 12, 11), + 'startOfWeek': StartOfWeek.sunday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 14), + 'secondDateTime': DateTime(2022, 12, 3), + 'thirdDateTime': DateTime(2022, 12, 17), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBetween': true + }, + { + 'firstDateTime': DateTime(2022, 12, 8), + 'secondDateTime': DateTime(2022, 12, 10), + 'thirdDateTime': DateTime(2022, 12, 17), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 20), + 'secondDateTime': DateTime(2022, 12, 3), + 'thirdDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 7), + 'secondDateTime': DateTime(2022, 12, 3), + 'thirdDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBetween': false + }, + { + 'firstDateTime': DateTime(2022, 12, 15), + 'secondDateTime': DateTime(2022, 12, 3), + 'thirdDateTime': DateTime(2022, 12, 10), + 'startOfWeek': StartOfWeek.saturday, + 'expectedIsBetween': false + }, + ]; +} + +List> isUtcDateTimeTestData() { + return [ + {'dateTime': DateTime.now(), 'expectedIsUtc': false}, + {'dateTime': DateTime.now().toUtc(), 'expectedIsUtc': true}, + ]; +} + +List> isLeapYearTestData() { + return [ + {'year': 1997, 'expectedIsLeapYear': false}, + {'year': 2022, 'expectedIsLeapYear': false}, + {'year': 2020, 'expectedIsLeapYear': true}, + {'year': 2018, 'expectedIsLeapYear': false}, + {'year': 2016, 'expectedIsLeapYear': true}, + ]; +}