time_machine 0.1.0 copy "time_machine: ^0.1.0" to clipboard
time_machine: ^0.1.0 copied to clipboard

outdatedDart 1 only

Date and time library for DartVM, Dart4Web and Flutter with support for timezones, calendars, culture-aware formatting and parsing.

Dart Time Machine #

Time Machine is a date and time API for Dart (port of Noda Time). Time Machine is timezone and culture sensitive. Intended targets are DartVM, Dart4Web, and Flutter.

Example Code:

// Sets up timezone and culture information
await TimeMachine.initialize();
print('Hello, ${DateTimeZone.local} from the Dart Time Machine!');

var tzdb = await DateTimeZoneProviders.tzdb;
var paris = await tzdb["Europe/Paris"];

var now = SystemClock.instance.getCurrentInstant();

print('\nBasic');
print('UTC Time: $now');
print('Local Time: ${now.inLocalZone()}');
print('Paris Time: ${now.inZone(paris)}');

print('\nFormatted');
print('UTC Time: ${now.toString('dddd yyyy-MM-dd HH:mm')}');
print('Local Time: ${now.inLocalZone().toString('dddd yyyy-MM-dd HH:mm')}');

print('\nFormatted and French');
var culture = await Cultures.getCulture('fr-FR');
print('UTC Time: ${now.toString('dddd yyyy-MM-dd HH:mm', culture)}');
print('Local Time: ${
  now.inLocalZone().toString('dddd yyyy-MM-dd HH:mm', culture)}');

print('\nParse French Formatted DateTimeZone');
// without the 'z' parsing will be forced to interpret the timezone as UTC
var localText = now
    .inLocalZone()
    .toString('dddd yyyy-MM-dd HH:mm z', culture);

var localClone = ZonedDateTimePattern
    .createWithCulture('dddd yyyy-MM-dd HH:mm z', culture)
    .parse(localText);
print(localClone.value);

VM #

selection_116

Flutter #

selection_117

Web #

selection_118

A lot of functionality works at this time, but the public API is starting to stabilize. TZDB QoL changes are in progress. This is a preview release. Documentation was also ported, but some things changed for Dart and the documentation will have minor inaccuracies in some places.

Don't use any functions annotated with @internal. I don't intend to keep this annotation, but with part \ part of usage discouraged and no friend semantics, I'm unsure of the direction to go with this.

  • Prototype an automated tool to produce public interface files?

Todo:

  • Port over major classes
  • Port over corresponding unit tests
  • Dartification of the API
    • First pass style updates
    • Second pass ergonomics updates
    • Synchronous TZDB timezone provider
  • Non-Gregorian/Julian calendar systems
  • Text formatting and Parsing
  • Remove XML tags from documentation and format them for pub (human second pass still needed)
  • Implement Dart4Web features
  • maybe: Create simple website with samples (at minimal a samples directory in github)

External data: Timezones (TZDB via Noda Time) and Culture (ICU via BCL) are produced by a C# tool that is not included in this repository.

I'm hoping that JS/VM specific functions will work via conditional imports. For testing atm, VM is default, but full JS support is planned. (fingers crossed that this makes it into Dart 2)

The unit testing framework uses reflection and won't work in Dart4Web 2.0 or later; we'll cross this bridge later.

Future Todo:

  • Produce our own TSDB files
  • Produce our own Culture files
  • Benchmarking & Optimizing Library for Dart
140
likes
0
pub points
95%
popularity

Publisher

unverified uploader

Date and time library for DartVM, Dart4Web and Flutter with support for timezones, calendars, culture-aware formatting and parsing.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, logging, meta, quiver_hashcode, resource

More

Packages that depend on time_machine