{"id":13551052,"url":"https://github.com/Dana-Ferguson/time_machine","last_synced_at":"2025-04-03T01:31:12.100Z","repository":{"id":29562548,"uuid":"121625210","full_name":"Dana-Ferguson/time_machine","owner":"Dana-Ferguson","description":"A date and time API for Dart","archived":false,"fork":false,"pushed_at":"2023-10-05T15:28:48.000Z","size":9985,"stargazers_count":124,"open_issues_count":43,"forks_count":38,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T06:01:55.650Z","etag":null,"topics":["dart","dartlang","date","time","timezone","tsdb"],"latest_commit_sha":null,"homepage":"https://pub.dartlang.org/packages/time_machine/","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dana-Ferguson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2018-02-15T12:04:40.000Z","updated_at":"2025-01-20T22:44:42.000Z","dependencies_parsed_at":"2024-01-16T19:13:07.599Z","dependency_job_id":null,"html_url":"https://github.com/Dana-Ferguson/time_machine","commit_stats":{"total_commits":593,"total_committers":9,"mean_commits":65.88888888888889,"dds":0.06745362563237778,"last_synced_commit":"246f3608b16d7fa36ee2155b3a21884b48c75b01"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dana-Ferguson%2Ftime_machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dana-Ferguson%2Ftime_machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dana-Ferguson%2Ftime_machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dana-Ferguson%2Ftime_machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dana-Ferguson","download_url":"https://codeload.github.com/Dana-Ferguson/time_machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922034,"owners_count":20855341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","dartlang","date","time","timezone","tsdb"],"created_at":"2024-08-01T12:01:41.689Z","updated_at":"2025-04-03T01:31:12.025Z","avatar_url":"https://github.com/Dana-Ferguson.png","language":"Dart","funding_links":[],"categories":["Dart"],"sub_categories":[],"readme":"![logo-dtm](https://user-images.githubusercontent.com/7284858/43960873-65f3f080-9c81-11e8-9d4d-c34c7e4cc46c.png)\n\nThe Dart Time Machine is a date and time library for\n[Flutter](https://flutter.io/), [Web](https://webdev.dartlang.org/), and [Server](https://www.dartlang.org/dart-vm)\nwith support for timezones, calendars, cultures, formatting and parsing.\n\nTime Machine provides an alternative date and time API over Dart Core.\nFor comparision:\n\n**Dart Core API**\n* Duration - an amount of time with microsecond precision\n* DateTime - a unique point on the utc_timeline or a point in localtime with microsecond or millisecond precision\n\n**Time Machine API**\n* Time - an amount of time with nanosecond precision\n* Instant - a unique point on the utc_timeline\n* LocalTime - the time on the clock\n* LocalDate - the date on the calendar\n* LocalDateTime - a location on the clock and calendar\n* Period - amount of time on the clock and calendar\n* Offset - the timezone offset from the utc_timeline\n* DateTimeZone - a mapping between the utc_timeline, and clock and calendar locations\n* ZonedDateTime - a unique point on the utc_timeline and a location on the clock and calendar\n* Culture - formatting and parsing rules specific to a locale\n\n**Time Machine's Goals**\n* Flexibility - multiple representations of time to fit different use cases\n* Consistency - works the same across all platforms\n* Testable - easy to test your date and time dependent code\n* Clarity - clear, concise, and intuitive\n* Easy - the library should do the hard things for you\n\nThe last two/three? are generic library goals.\n\nTime Machine is a port of [Noda Time](https://www.nodatime.org); use it for all your .NET needs.\n\nCurrent TZDB Version: 2022a\n\n### Example Code:\n\n```dart\n// Sets up timezone and culture information\nawait TimeMachine.initialize();\nprint('Hello, ${DateTimeZone.local} from the Dart Time Machine!\\n');\n\nvar tzdb = await DateTimeZoneProviders.tzdb;\nvar paris = await tzdb[\"Europe/Paris\"];\n\nvar now = Instant.now();\n\nprint('Basic');\nprint('UTC Time: $now');\nprint('Local Time: ${now.inLocalZone()}');\nprint('Paris Time: ${now.inZone(paris)}\\n');\n\nprint('Formatted');\nprint('UTC Time: ${now.toString('dddd yyyy-MM-dd HH:mm')}');\nprint('Local Time: ${now.inLocalZone().toString('dddd yyyy-MM-dd HH:mm')}\\n');\n\nvar french = await Cultures.getCulture('fr-FR');\nprint('Formatted and French ($french)');\nprint('UTC Time: ${now.toString('dddd yyyy-MM-dd HH:mm', french)}');\nprint('Local Time: ${now.inLocalZone().toString('dddd yyyy-MM-dd HH:mm', french)}\\n');\n\nprint('Parse French Formatted ZonedDateTime');\n\n// without the 'z' parsing will be forced to interpret the timezone as UTC\nvar localText = now\n    .inLocalZone()\n    .toString('dddd yyyy-MM-dd HH:mm z', french);\n\nvar localClone = ZonedDateTimePattern\n    .createWithCulture('dddd yyyy-MM-dd HH:mm z', french)\n    .parse(localText);\n\nprint(localClone.value);\n```\n\n### VM\n\n![selection_116](https://user-images.githubusercontent.com/7284858/41519375-bcbbc818-7295-11e8-9fd0-de2e8668b105.png)\n\n### Flutter\n\n![selection_117](https://user-images.githubusercontent.com/7284858/41519377-bebbde82-7295-11e8-8f10-d350afd1f746.png)\n\n### Web (Dart2JS and DDC)\n\n![selection_118](https://user-images.githubusercontent.com/7284858/41519378-c058d6a0-7295-11e8-845d-6782f1e7cbbe.png)\n\nAll unit tests pass on DartVM and DartWeb (just _Chrome_ at this time).\nTests have been run on preview versions of Dart2,\nbut the focus is on DartStable, and they are not run before every pub publish.\nThe public API is stabilizing -- mostly focusing on taking C# idiomatic code\nand making it Dart idiomatic code, so I wouldn't expect any over zealous changes.\nThis is a preview release -- but, I'd feel comfortable using it. (_Author Stamp of Approval!_)\n\nDocumentation was ported, but some things changed for Dart and the documentation is being slowly updated (and we need\nan additional automated formatting pass).\n\nDon't use any functions annotated with `@internal`. As of v0.3 you should not find any, but if you do, let me know.\n\nTodo (before v1):\n - [x] Port Noda Time\n - [x] Unit tests passing in DartVM\n - [ ] Dartification of the API\n   - [X] First pass style updates\n   - [X] Second pass ergonomics updates\n   - [X] Synchronous TZDB timezone provider\n   - [ ] Review all I/O and associated classes and their structure\n   - [ ] Simplify the API and make the best use of named constructors\n - [X] Non-Gregorian/Julian calendar systems\n - [X] Text formatting and Parsing\n - [X] Remove XML tags from documentation and format them for pub (*human second pass still needed*)\n - [X] Implement Dart4Web features\n - [X] Unit tests passing in DartWeb\n - [ ] Fix DartDoc Formatting\n - [ ] Create simple website with examples (at minimal a good set of examples under the examples directory)\n\nExternal data: Timezones (TZDB via Noda Time) and Culture (ICU via BCL) are produced by a C# tool that is not\nincluded in this repository. The goal is to port all this functionality to Dart, the initial tool was created for\nbootstrapping -- and guaranteeing that our data is exactly the same thing that Noda Time would see (to ease porting).\n\nFuture Todo:\n - [ ] Produce our own TSDB files\n - [ ] Produce our own Culture files\n - [ ] Benchmarking \u0026 Optimizing Library for Dart\n\n### Flutter Specific Notes\n\nYou'll need this entry in your pubspec.yaml.\n\n```yaml\n# The following section is specific to Flutter.\nflutter:\n  assets:\n    - packages/time_machine/data/cultures/cultures.bin\n    - packages/time_machine/data/tzdb/tzdb.bin\n```\n\nYour initialization function will look like this:\n```dart\nimport 'package:flutter/services.dart';\n\nWidgetsFlutterBinding.ensureInitialized();\n\n// TimeMachine discovers your TimeZone heuristically (it's actually pretty fast).\nawait TimeMachine.initialize({'rootBundle': rootBundle});\n```\n\nOnce flutter gets [`Isolate.resolvePackageUri`](https://github.com/flutter/flutter/issues/14815) functionality,\nwe'll be able to merge VM and the Flutter code paths and no asset entry and no special import will be required.\nIt would look just like the VM example.\n\nOr with: https://pub.dartlang.org/packages/flutter_native_timezone\n\n```dart\nimport 'package:flutter/services.dart';\n\n// you can get Timezone information directly from the native interface with flutter_native_timezone\nawait TimeMachine.initialize({\n  'rootBundle': rootBundle,\n  'timeZone': await Timezone.getLocalTimezone(),\n});\n```\n\n### DDC Specific Notes\n\n`toString` on many of the classes will not propagate `patternText` and `culture` parameters.\n`Instant` and `ZonedDateTime` currently have `toStringDDC` functions available to remedy this.\n\nThis also works:\n\n```dart\ndynamic foo = new Foo();\nvar foo = new Foo() as dynamic;\n(foo as dynamic).toString(patternText, culture);\n```\n\nWe learned in [Issue:33876](https://github.com/dart-lang/sdk/issues/33876) that `dynamic` code uses a different flow path.\nWrapping your code as dynamic will allow `toString()` to work normally. It will unfortunately ruin your intellisense.\n\nSee [Issue:33876](https://github.com/dart-lang/sdk/issues/33876) for more information. The [fix](https://dart-review.googlesource.com/c/sdk/+/65282)\nexists, now we just wait for it to hit a live build.\n\n`toStringDDC` instead of `toStringFormatted` to attempt to get a negative\n[contagion](https://engineering.riotgames.com/news/taxonomy-tech-debt) coefficient. If you are writing on DartStable today\nand you need some extra string support because of this bug, let me know.\n\n_Update_: Dart 2.0 stable did not launch with the fix. Stable release windows are 6 weeks.\nHopefully we get the fix in the next release (second half of September).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDana-Ferguson%2Ftime_machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDana-Ferguson%2Ftime_machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDana-Ferguson%2Ftime_machine/lists"}