This package provides time zone database and time zone aware DateTime
object.
Current Time Zone database version: 2015b
TimeZone objects require time zone data, so the first step is to load one of our time zone databases.
We are providing two different APIs for browsers and standalone environments.
Import package:timezone/browser.dart
library and run async function
Future initializeTimeZone([String path])
.
import 'package:timezone/browser.dart';
initializeTimeZone().then((_) {
final detroit = getLocation('America/Detroit');
final now = new TZDateTime.now(detroit);
});
Import package:timezone/standalone.dart
library and run async function
Future initializeTimeZone([String path])
.
import 'package:timezone/standalone.dart';
initializeTimeZone().then((_) {
final detroit = getLocation('America/Detroit');
final now = new TZDateTime.now(detroit);
});
By default, when library is initialized, local location will be UTC
.
To overwrite local location you can use setLocalLocation(Location
location)
function.
initializeTimeZone().then((_) {
final detroit = getLocation('America/Detroit');
setLocalLocation(detroit);
});
Each location in the database represents a national region where all clocks keeping local time have agreed since 1970. Locations are identified by continent or ocean and then by the name of the location, which is typically the largest city within the region. For example, America/New_York represents most of the US eastern time zone; America/Phoenix represents most of Arizona, which uses mountain time without daylight saving time (DST); America/Detroit represents most of Michigan, which uses eastern time but with different DST rules in 1975; and other entries represent smaller regions like Starke County, Indiana, which switched from central to eastern time in 1991 and switched back in 2006.
final detroit = getLocation('America/Detroit');
We don't provide any functions to get locations by timezone abbreviations because of the ambiguities.
Alphabetic time zone abbreviations should not be used as unique identifiers for UTC offsets as they are ambiguous in practice. For example, "EST" denotes 5 hours behind UTC in English-speaking North America, but it denotes 10 or 11 hours ahead of UTC in Australia; and French-speaking North Americans prefer "HNE" to "EST".
TimeZone object represents time zone and contains offset, dst flag, and name in the abbreviated form.
final timeInUtc = new DateTime.utc(1995, 1, 1);
final timeZone = detroit.timeZone(timeInUtc.millisecondsSinceEpoch);
TZDateTime
object implements standard DateTime
interface and
contains information about location and time zone.
final date = new TZDateTime(detroit, 2014, 11, 17);
To convert between time zones, just create a new TZDateTime
object
using from
constructor and pass Location
and DateTime
to the
constructor.
final localTime = new DateTime(2010, 1, 1);
final detroitTime = new TZDateTime.from(time, detroit);
This constructor supports any objects that implements DateTime
interface, so you can pass native DateTime
object or ours
TZDateTime
.
We are using IANA Time Zone Database to build our databases.
We are currently building three different database variants:
Script for updating Time Zone database, it will automatically download the IANA Time Zone Database and compile into our native format.
$ pub run tool/get -s 2014h
Argument -s
is for specifying source version.
generate_data_subset
script is removed. It will be available as a
separate package.setLocalLocation
to change local location.initializeTimeZoneSync
function for standalone environments.tzfile
library renamed to tzdata
.zone1970.tab
parser to tzdata
library.package:collection
dependency.Add this to your package's pubspec.yaml file:
dependencies:
timezone: "^0.4.3"
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:timezone/timezone.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.4.3 | Feb 23, 2016 |
|
|
0.4.2 | Feb 23, 2016 |
|
|
0.4.1 | Jan 30, 2016 |
|
|
0.4.0 | Nov 24, 2015 |
|
|
0.3.1 | Apr 26, 2015 |
|
|
0.3.0 | Apr 8, 2015 |
|
|
0.2.5 | Jan 6, 2015 |
|
|
0.2.4 | Dec 25, 2014 |
|
|
0.2.3 | Dec 15, 2014 |
|
|
0.2.2+2 | Dec 15, 2014 |
|
|
We analyzed this package on Apr 9, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
88 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
84 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
0 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
69 |
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:timezone/timezone.dart
.
Fix analysis and formatting issues.
Analysis or formatting checks reported 5 errors 18 hints.
Strong-mode analysis of
lib/src/date_time.dart
failed with the following error:line: 11 col: 7
Missing concrete implementations of getter 'DateTime.microsecond' and getter 'DateTime.microsecondsSinceEpoch'.Strong-mode analysis of
lib/src/location.dart
failed with the following error:line: 240 col: 3
Invalid override. The type of 'TimeZone.==' ('(TimeZone) → bool') isn't a subtype of 'Object.==' ('(dynamic) → bool').Similar analysis of the following files failed:
lib/browser.dart
(hint)lib/src/env.dart
(hint)lib/src/location_database.dart
(hint)lib/src/tools.dart
(hint)lib/src/tzdata/zicfile.dart
(hint)lib/src/tzdata/zone_tab.dart
(hint)lib/src/tzdb.dart
(hint)lib/standalone.dart
(hint)
The description is too short.
Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.
Package is pre-v1 release.
While there is nothing inherently wrong with versions of
0.*.*
, it usually means that the author is still experimenting with the general direction API.
Maintain an example.
Create a short demo in the
example/
directory to show how to use this package. Common file name patterns include:main.dart
,example.dart
or you could also usetimezone.dart
.