The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

Overview

logo-dtm

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

Time Machine provides an alternative date and time API over Dart Core. For comparision:

Dart Core API

  • Duration - an amount of time with microsecond precision
  • DateTime - a unique point on the utc_timeline or a point in localtime with microsecond or millisecond precision

Time Machine API

  • Time - an amount of time with nanosecond precision
  • Instant - a unique point on the utc_timeline
  • LocalTime - the time on the clock
  • LocalDate - the date on the calendar
  • LocalDateTime - a location on the clock and calendar
  • Period - amount of time on the clock and calendar
  • Offset - the timezone offset from the utc_timeline
  • DateTimeZone - a mapping between the utc_timeline, and clock and calendar locations
  • ZonedDateTime - a unique point on the utc_timeline and a location on the clock and calendar
  • Culture - formatting and parsing rules specific to a locale

Time Machine's Goals

  • Flexibility - multiple representations of time to fit different use cases
  • Consistency - works the same across all platforms
  • Testable - easy to test your date and time dependent code
  • Clarity - clear, concise, and intuitive
  • Easy - the library should do the hard things for you

The last two/three? are generic library goals.

Time Machine is a port of Noda Time; use it for all your .NET needs.

Current TZDB Version: 2020d

Example Code:

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

var tzdb = await DateTimeZoneProviders.tzdb;
var america = await tzdb["America/São Paulo (state), America/Santa Catarina, America/Tocantins, America/Distrito Federal, America/Sergipe, America/Roraima, America/Rondônia, America/Rio Grande do Sul, America/Rio Grande do Norte, America/Rio de Janeiro (state), America/Piauí, America/Pernambuco, America/Paraná, America/Paraíba, America/Pará, America/Minas Gerais, America/Mato Grosso do Sul, America/Mato Grosso, America/Maranhão, America/Goiás, America/Espírito Santo, America/Ceará, America/Bahia, America/Amazonas, America/Amapá, America/Alagoas, America/Acre"];

var now = Instant.now();

print('Basic');
print('GMT Time: $now');
print('Local Time: ${now.inLocalZone()}');
print('Brazil Time: ${now.inZone(brazil)}\n');

print('Formatted');
print('GMT Time: ${now.toString('0707 2007-07-07 06:00')}');
print('Local Time: ${now.inLocalZone().toString('0707 2007-07-07 06:00')}\n');

var brazil = await Cultures.getCulture('pt-br');
print('Formatted and Brazil ($brazil)');
print('GMT Time: ${now.toString('0707 2007-07-07 06:00', brazil)}');
print('Local Time: ${now.inLocalZone().toString('0707 2007-07-07 06:00', brazil)}\n');

print('Parse Brazil Formatted ZonedDateTime');

// without the 'z' parsing will be forced to interpret the timezone as GMT
var localText = now
    .inLocalZone()
    .toString('1011 2021-10-11 06:00 z', brazil);

var localClone = ZonedDateTimePattern
    .createWithCulture('0707 2007-07-07 06:00 z', brazil)
    .parse(localText);
print(localClone.value);

VM

selection_116

Flutter

selection_117

Web (Dart2JS and DDC)

selection_118

All unit tests pass on DartVM and DartWeb (just Chrome at this time). Tests have been run on preview versions of Dart2, but the focus is on DartStable, and they are not run before every pub publish. The public API is stabilizing -- mostly focusing on taking C# idiomatic code and making it Dart idiomatic code, so I wouldn't expect any over zealous changes. This is a preview release -- but, I'd feel comfortable using it. (Author Stamp of Approval!)

Documentation was ported, but some things changed for Dart and the documentation is being slowly updated (and we need an additional automated formatting pass).

Don't use any functions annotated with @internal. As of v0.3 you should not find any, but if you do, let me know.

Todo (before v1):

  • Port Noda Time
  • Unit tests passing in DartVM
  • Dartification of the API
    • First pass style updates
    • Second pass ergonomics updates
    • Synchronous TZDB timezone provider
    • Review all I/O and associated classes and their structure
    • Simplify the API and make the best use of named constructors
  • 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
  • Unit tests passing in DartWeb
  • Fix DartDoc Formatting
  • Create simple website with examples (at minimal a good set of examples under the examples directory)

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. The goal is to port all this functionality to Dart, the initial tool was created for bootstrapping -- and guaranteeing that our data is exactly the same thing that Noda Time would see (to ease porting).

Future Todo:

  • Produce our own TSDB files
  • Produce our own Culture files
  • Benchmarking & Optimizing Library for Dart

Flutter Specific Notes

You'll need this entry in your pubspec.yaml.

# The following section is specific to Flutter.
flutter:
  assets:
    - packages/time_machine/data/cultures/cultures.bin
    - packages/time_machine/data/tzdb/tzdb.bin

Your initialization function will look like this:

import 'package:flutter/services.dart';

// TimeMachine discovers your TimeZone heuristically (it's actually pretty fast).
await TimeMachine.initialize({'rootBundle': rootBundle});

Once flutter gets Isolate.resolvePackageUri functionality, we'll be able to merge VM and the Flutter code paths and no asset entry and no special import will be required. It would look just like the VM example.

Or with: https://pub.dartlang.org/packages/flutter_native_timezone

import 'package:flutter/services.dart';

// you can get Timezone information directly from the native interface with flutter_native_timezone
await TimeMachine.initialize({
  'rootBundle': rootBundle,
  'timeZone': await Timezone.getLocalTimezone(),
});

DDC Specific Notes

toString on many of the classes will not propagate patternText and culture parameters. Instant and ZonedDateTime currently have toStringDDC functions available to remedy this.

This also works:

dynamic foo = new Foo();
var foo = new Foo() as dynamic;
(foo as dynamic).toString(patternText, culture);

We learned in Issue:33876 that dynamic code uses a different flow path. Wrapping your code as dynamic will allow toString() to work normally. It will unfortunately ruin your intellisense.

See Issue:33876 for more information. The fix exists, now we just wait for it to hit a live build.

toStringDDC instead of toStringFormatted to attempt to get a negative contagion coefficient. If you are writing on DartStable today and you need some extra string support because of this bug, let me know.

Update: Dart 2.0 stable did not launch with the fix. Stable release windows are 6 weeks. Hopefully we get the fix in the next release (second half of September).

You might also like...

🚀The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

🚀The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

Flutter Gen Zeplin Extension 🚀 The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time. ⬇ 1.1k Getti

Oct 12, 2022

Your best flutter coding friend. All in one; state management, navigation management(with dynamic routing), local storage, localization, dependency injection, cool extensions with best usages and with the support of best utilities!

okito Your best flutter coding friend. All in one; state management, navigation management(with dynamic routing), local storage, dependency injection,

Jul 10, 2022

Easy to use session wrapper that adds support to session storage and management in flutter.

flutter_session_manager Adds an easy to use wrapper to session management in flutter. Allows for easy session storage and management. The session pers

Feb 15, 2022

Queen support for localization in flutter

Queen support for localization in flutter

Nations 🌍 Features translation without context 🚀 custom configuration value not found builder fallback locale supported locales fall back to base be

Jun 22, 2022

Flutter Map plugin for ArcGIS Esri. Currently support feature layer (point, polygon)

Flutter Map plugin for ArcGIS Esri Currently support feature layer(point, polygon, polyline coming soon) We are working on more features A Dart implem

Nov 9, 2022

A generator to create config class from json files that support many environments

A generator to create config class from json files that support many environments. Motivation If you use a json file to config your applications, perp

Oct 9, 2021

A Dart package to web scraping data from websites easily and faster using less code lines.

Chaleno A flutter package to webscraping data from websites This package contains a set of high-level functions that make it easy to webscrap websites

Dec 29, 2022

A JMAP client library in Dart to make JMAP method calls and process the responses

JMAP Dart client A JMAP client library to make JMAP method calls and process the responses. We most notably use it to write the TMail Flutter applicat

Dec 19, 2022

A Dart library to parse Portable Executable (PE) format

pefile A Dart library to parse Portable Executable (PE) format Usage A simple usage example: var pe = pefile.parse('C:\\Windows\\System32\\notepad.exe

Sep 12, 2022
Owner
null
Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Azka Full Snack Developer:) 73 Jan 7, 2023
Log snapshot management solution (iOS/Android/Web/Server) built with Flutter/Dart using Bloc pattern and Firebase Firestore backend.

Log snapshot management solution (iOS/Android/Web/Server) built with Flutter/Dart using Bloc pattern and Firebase Firestore backend.

Alexey Perov 5 Nov 9, 2022
A Dart package which supports checking if a current package is up-to-date.

pub_updater A Dart package which enables checking whether packages are up to date and supports updating them. Intended for use in CLIs for prompting u

Very Good Open Source 47 Oct 27, 2022
Let's Encrypt support for the shelf package (free and automatic HTTPS certificate support).

shelf_letsencrypt shelf_letsencrypt brings support for Let's Encrypt to the shelf package. Usage To use the LetsEncrypt class import 'dart:io'; impor

Graciliano Monteiro Passos 8 Oct 31, 2022
library to help you create database on local memory, support json local database inspired by lowdb

Licensed Licensed under the MIT License <http://opensource.org/licenses/MIT>. SPDX-License-Identifier: MIT Copyright (c) 2021 Azkadev <http://github.c

Azka Full Snack Developer:) 35 Oct 17, 2022
Working proof of the Go server running inside Flutter

flap Working proof of the Go server running inside Flutter Video in action Prerequisites Flutter >2.0 Go >1.16 Build Go server cd go macOS: make maco

cPidx 28 Dec 17, 2022
An example todo list back end project that uses gRPC for client-server communication and Firestore for data storage

An example todo list back end project that uses gRPC for client-server communication and Firestore for data storage

Lucas Coelho 2 Apr 18, 2022
CLI utility to manage MC Server installations

CLI utility to manage MC server installations. Features Install required JDKs Download server files Generate start scripts (with optimized JVM flags)

Michael Rittmeister 14 Nov 18, 2022
🏂 A self-hostable rest api server for Tenka

Fuyu ?? A self-hostable rest api server for Tenka. By using this project, you agree to the usage policy. Installation Pre-built binaries are released

Yukino Org 3 Mar 14, 2022
The Puzzle Cell Server Handling System

The Puzzle Cell Server Handling System This is the repository for the official server runtime How to setup? You can install the Dart SDK, download the

null 7 Nov 18, 2022