{"id":19027331,"url":"https://github.com/odroe/now","last_synced_at":"2026-04-03T03:02:29.727Z","repository":{"id":142848513,"uuid":"610661975","full_name":"odroe/now","owner":"odroe","description":"⏱️ A minimalist DateTime library for validating, parsing, manipulating and formatting times.","archived":false,"fork":false,"pushed_at":"2026-02-02T03:33:55.000Z","size":40,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-09T23:29:02.194Z","etag":null,"topics":["dart","date","datetinme","format","moment","now","time"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/odroe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"odroe","open_collective":"openodroe"}},"created_at":"2023-03-07T08:21:25.000Z","updated_at":"2025-10-22T04:34:16.000Z","dependencies_parsed_at":"2023-12-16T19:00:54.052Z","dependency_job_id":"a6ce3241-6116-4062-944f-fb8c39e6ddec","html_url":"https://github.com/odroe/now","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.2692307692307693,"last_synced_commit":"0beec5b350a58144c512eca6ce1cdb7a1efa9cb7"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/odroe/now","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fnow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fnow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fnow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fnow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odroe","download_url":"https://codeload.github.com/odroe/now/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odroe%2Fnow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31330108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T02:17:30.558Z","status":"ssl_error","status_checked_at":"2026-04-03T02:17:30.071Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","date","datetinme","format","moment","now","time"],"created_at":"2024-11-08T21:07:57.676Z","updated_at":"2026-04-03T03:02:29.685Z","avatar_url":"https://github.com/odroe.png","language":"Dart","funding_links":["https://github.com/sponsors/odroe","https://opencollective.com/openodroe"],"categories":[],"sub_categories":[],"readme":"# Now\n\nA minimalist DateTime library for validating, parsing, manipulating and formatting times.\n\n## Installation\n\nThis will add a like this to you packages `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  now: latest\n```\n\nOr you can install it from the command line:\n\n```bash\ndart pub add now\n```\n\n## Sponsors\n\nNow is an [MIT licensed](LICENSE) open source project with its ongoing development made possible entirely by the support of these awesome backers. If you'd like to join them, please consider [sponsoring Odroe development](https://github.com/sponsors/odroe).\n\n\u003cp align=\"center\"\u003e\n  \u003ca target=\"_blank\" href=\"https://github.com/sponsors/odroe#sponsors\"\u003e\n    \u003cimg alt=\"sponsors\" src=\"https://github.com/odroe/.github/raw/main/sponsors.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Getting Started\n\n### Create a DateTime\n\n```dart\n/// Create a new DateTime from local time zone.\nfinal current = now(); // Same as DateTime.now()\nfinal utc = now.utc(); // Same as DateTime.now().toUtc()\n```\n\n### Format a DateTime\n\n```dart\nfinal pattern = 'YYYY-MM-DD HH:mm:ss.SSS';\nfinal formated = now().format(pattern); // Same as DateTime.now().format(pattern)\n\nprint(formated); // 2021-08-01 12:00:00.000\n```\n\n### Convert a DateTime\n\nObtained a UTC safely originally from a different time zone.\n\n```dart\nfinal utc = date.isUtc ? date : date.toUtc();\n```\n\nNow you can convert it to a UTC time zone.\n\n```dart\nfinal utc = date.utc; // Same as date.isUtc ? date : date.toUtc();\n```\n\n### DateTime addition and subtraction\n\n```dart\nfinal date = now();\n\n/// Add 1 day.\nfinal tomorrow = date + 1.day; // Same as date.add(Duration(days: 1));\n\n/// Subtract 1 day.\nfinal yesterday = date - 1.day; // Same as date.subtract(Duration(days: 1));\n```\n\n### DateTime comparison\n\n- Compare DateTime with DateTime less than or equal.\n\n  ```dart\n  final date1 = now();\n  final date2 = date1 + 1.day;\n\n  print(date1 \u003c= date2); // true\n  print(date1.isBeforeOrEqual(date2)); // true\n  ```\n\n- Compare DateTime with DateTime greater than or equal.\n\n  ```dart\n  final date1 = now();\n  final date2 = date1 + 1.day;\n\n  print(date2 \u003e= date1); // true\n  print(date2.isAfterOrEqual(date1)); // true\n  ```\n\n- Compare DateTime with DateTime less than.\n\n  ```dart\n  final date1 = now();\n  final date2 = date1 + 1.day;\n\n  print(date1 \u003c date2); // true\n  print(date1.isBefore(date2)); // true\n  ```\n\n- Compare DateTime with DateTime greater than.\n\n  ```dart\n  final date1 = now();\n  final date2 = date1 + 1.day;\n\n  print(date2 \u003e date1); // true\n  print(date2.isAfter(date1)); // true\n  ```\n\n### Duration extensions\n\n#### Weeks in the duration\n\n```dart\nfinal Duration duration = Duration(days: 7);\n\nprint(duration.inWeeks); // 1\n```\n\n#### Convert a int to a Duration\n\n| Unit           | Same as                         | Description                  | Example         |\n| -------------- | ------------------------------- | ---------------------------- | --------------- |\n| `microseconds` | `Duration(microseconds: \u003cint\u003e)` | Microseconds in the duration | `1.microsecond` |\n| `milliseconds` | `Duration(milliseconds: \u003cint\u003e)` | Milliseconds in the duration | `1.millisecond` |\n| `seconds`      | `Duration(seconds: \u003cint\u003e)`      | Seconds in the duration      | `1.second`      |\n| `minutes`      | `Duration(minutes: \u003cint\u003e)`      | Minutes in the duration      | `1.minute`      |\n| `hours`        | `Duration(hours: \u003cint\u003e)`        | Hours in the duration        | `1.hour`        |\n| `days`         | `Duration(days: \u003cint\u003e)`         | Days in the duration         | `1.day`         |\n| `weeks`        | `Duration(days: \u003cint\u003e * 7)`     | Weeks in the duration        | `1.week`        |\n\n## Format specifiers\n\nBy default we register all the built-in formatters.\n\n| specifier | Description            | Example                           |\n| --------- | ---------------------- | --------------------------------- |\n| `A`       | AM/PM Upper case       | `now().format('A') -\u003e AM`         |\n| `a`       | am/pm Lower case       | `now().format('a') -\u003e am`         |\n| `D`       | Day of month, 1-31     | `now().format('D') -\u003e 1`          |\n| `DD`      | Day of month, 01-31    | `now().format('DD') -\u003e 01`        |\n| `d`       | Day of week, 1-7       | `now().format('d') -\u003e 1`          |\n| `dd`      | Day of week min name   | `now().format('dd') -\u003e Mo`        |\n| `ddd`     | Day of week short name | `now().format('ddd') -\u003e Mon`      |\n| `dddd`    | Day of week full name  | `now().format('dddd') -\u003e Monday`  |\n| `H`       | Hour, 0-23             | `now().format('H') -\u003e 0`          |\n| `HH`      | Hour, 00-23            | `now().format('HH') -\u003e 00`        |\n| `h`       | Hour, 1-12             | `now().format('h') -\u003e 1`          |\n| `hh`      | Hour, 01-12            | `now().format('hh') -\u003e 01`        |\n| `SSS`     | Milliseconds, 000-999  | `now().format('SSS') -\u003e 000`      |\n| `m`       | Minute, 0-59           | `now().format('m') -\u003e 0`          |\n| `mm`      | Minute, 00-59          | `now().format('mm') -\u003e 00`        |\n| `M`       | Month, 1-12            | `now().format('M') -\u003e 1`          |\n| `MM`      | Month, 01-12           | `now().format('MM') -\u003e 01`        |\n| `MMM`     | Month abbreviated name | `now().format('MMM') -\u003e Jan`      |\n| `MMMM`    | Month full name        | `now().format('MMMM') -\u003e January` |\n| `Q`       | Quarter, 1-4           | `now().format('Q') -\u003e 1`          |\n| `s`       | Second, 0-59           | `now().format('s') -\u003e 0`          |\n| `ss`      | Second, 00-59          | `now().format('ss') -\u003e 00`        |\n| `YY`      | Year, 00-99            | `now().format('YY') -\u003e 21`        |\n| `YYYY`    | Year, 0000-9999        | `now().format('YYYY') -\u003e 2023`    |\n| `Z`       | Timezone               | `now().format('Z') -\u003e +01:00`     |\n| `ZZ`      | Timezone               | `now().format('ZZ') -\u003e +0100`     |\n\n### Escape specifiers\n\nOccasionally, single-character specifiers exist for formatters. Our formatting mode hopes that this string will not be processed by the formatter, but will output the characters we defined as it is.\n\n- `\\` Prefix, a character after the `\\` symbol ensures output as is.\n\n  ```dart\n  now().format('HH:mm A ss'); // 00:00 AM 00\n\n  // This is not what we expect, since the second s needs to be output as-is.\n  now().format(r'HH:mm A s\\s'); // 00:00 AM 0s\n\n  // Or\n  now().format('HH:mm A s\\\\s'); // 00:00 AM 0s\n  ```\n\n## DateTime formatter\n\nSometimes the built-in formatter cannot meet all your needs, you can register a DateTime formatter via `now.register`:\n\n```dart\nfinal DateTimeFormatter formatter = ...\n\nnow.register(formatter);\n```\n\nYou may already have a DateTime formatter, but its specifier is not what you expect:\n\n```dart\nfinal DateTimeFormatter formatter = ...\n\nnow.registerWith('Custom specifier', formatter);\n```\n\n### Custom formatter\n\nIf you wish to customize the DateTime formatter, you need to implement the `DateTimeFormatter` interface imported from `package:now/formatter.dart`:\n\n```dart\nimport 'package:now/formatter.dart';\n\nclass MyFormatter implements DateTimeFormatter {\n  const MyFormatter();\n\n  /// Matched the [specifier] and return the [DateTime] format result.\n  @override\n  String format(DateTime dateTime) {\n    // TODO: format the [dateTime] and return the result.\n    return 'My format result';\n  }\n\n  @override\n  String get specifier =\u003e 'My specifier';\n}\n```\n\nThen we register and use it:\n\n```dart\nimport 'package:now/now.dart';\n\nmain() {\n  now.register(const MyFormatter());\n\n  print(now().format('YYYY - My specifier')); // Output: 2023 - My format result\n}\n```\n\n## Function-based formatter\n\nIf you don't want to implement the `DateTimeFormatter` interface, you can also use the function-based formatter:\n\n```dart\nimport 'package:now/now.dart';\n\nmain() {\n  now.registerWithFn('My specifier', (dateTime) {\n    return 'My format result';\n  });\n\n  print(now().format('YYYY - My specifier')); // Output: 2023 - My format result\n}\n```\n\n## Stopwatch\n\nWe provide a helper method for `Stopwatch` that can be directly created and started:\n\n```dart\nfinal stopwatch = now.stopwatch(); // Same as Stopwatch()..start()\n```\n\n## Destroy formatters\n\n| Method                 | Description                                 | Example                                  |\n| ---------------------- | ------------------------------------------- | ---------------------------------------- |\n| `now.destroy()`        | Destroys a registered with a test function. | `now.destroy((f) =\u003e f.specifier == 'A')` |\n| `now.destroyAll()`     | Destroys all registered formatters.         | `now.destroyAll()`                       |\n| `now.destroyWith()`    | Destroys a registered formatter.            | `now.destroyWith('A')`                   |\n| `now.destroyDefault()` | Destroys all built-in formatters.           | `now.destroyDefault()`                   |\n\n## Contributing\n\nWe welcome contributions! Please read our [contributing guide](CONTRIBUTING.md) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Prisma.\n\nThank you to all the people who already contributed to Odroe!\n\n[![Contributors](https://opencollective.com/openodroe/contributors.svg?width=890)](https://github.com/odroe/prisma-dart/graphs/contributors)\n\n## Code of Conduct\n\nThis project has adopted the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). For more information see the [Code of Conduct FAQ](https://www.contributor-covenant.org/faq) or contact [hello@odroe.com](mailto:hello@odroe.com) with any additional questions or comments.\n\n## Stay in touch\n\n- [Website](https://prisma.pub)\n- [Twitter](https://twitter.com/odroeinc)\n- [Discord](https://discord.gg/r27AjtUUbV)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodroe%2Fnow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodroe%2Fnow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodroe%2Fnow/lists"}