https://github.com/chronotope/chrono-tz

TimeZone implementations for rust-chrono from the IANA database

https://github.com/chronotope/chrono-tz

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 43 committers (2.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.6%) to scientific vocabulary

Keywords from Contributors

argument-parser calendar command-line-parser parsed-arguments positional-arguments subcommands packaging pip
Last synced: 10 months ago · JSON representation

Repository

TimeZone implementations for rust-chrono from the IANA database

Basic Info
  • Host: GitHub
  • Owner: chronotope
  • License: other
  • Language: Rust
  • Default Branch: main
  • Size: 1.72 MB
Statistics
  • Stars: 261
  • Watchers: 8
  • Forks: 63
  • Open Issues: 20
  • Releases: 46
Created over 9 years ago · Last pushed 11 months ago
Metadata Files
Readme License

README.md

Chrono-TZ

Chrono-TZ GitHub Actions Chrono-TZ on crates.io Chrono-TZ on docs.rs Chat

Chrono-TZ is a library that provides implementors of the TimeZone trait for chrono. The impls are generated by a build script using the IANA database and parse-zoneinfo.

Documentation

Documentation is hosted on docs.rs

Examples

Create a time in one timezone and convert it to UTC

```rust use chrono::{TimeZone, Utc}; use chrono_tz::US::Pacific;

let pacifictime = Pacific.ymd(1990, 5, 6).andhms(12, 30, 45); let utctime = pacifictime.withtimezone(&Utc); asserteq!(utctime, Utc.ymd(1990, 5, 6).andhms(19, 30, 45)); ```

Create a naive datetime and convert it to a timezone-aware datetime

```rust use chrono::{TimeZone, NaiveDate}; use chrono_tz::Africa::Johannesburg;

let naivedt = NaiveDate::fromymd(2038, 1, 19).andhms(3, 14, 08); let tzaware = Johannesburg.fromlocaldatetime(&naivedt).unwrap(); asserteq!(tzaware.tostring(), "2038-01-19 03:14:08 SAST"); ```

London and New York change their clocks on different days in March so only have a 4-hour difference on certain days.

```rust use chrono::TimeZone; use chronotz::Europe::London; use chronotz::America::New_York;

let londontime = London.ymd(2016, 3, 18).andhms(3, 0, 0); let nytime = londontime.withtimezone(&NewYork); asserteq!(nytime, NewYork.ymd(2016, 3, 17).andhms(23, 0, 0)); ```

You can get the raw offsets as well if you want to see the standard UTC offset as well as any special offsets in effect (such as DST) at a given time. Note that you need to import the OffsetComponents trait.

```rust use chrono::{Duration, TimeZone}; use chronotz::Europe::London; use chronotz::OffsetComponents;

let londontime = London.ymd(2016, 5, 10).andhms(12, 0, 0);

// London typically has zero offset from UTC, but has a 1h adjustment forward // when summer time is in effect. asserteq!(londontime.offset().baseutcoffset(), Duration::hours(0)); asserteq!(londontime.offset().dst_offset(), Duration::hours(1)); ```

Adding 24 hours across a daylight savings change causes a change in local time

```rust use chrono::{TimeZone, Duration}; use chrono_tz::Europe::London;

let dt = London.ymd(2016, 10, 29).andhms(12, 0, 0); let later = dt + Duration::hours(24); asserteq!(later, London.ymd(2016, 10, 30).and_hms(11, 0, 0)); ```

And of course you can always convert a local time to a unix timestamp

```rust use chrono::TimeZone; use chrono_tz::Asia::Kolkata;

let dt = Kolkata.ymd(2000, 1, 1).andhms(0, 0, 0); let timestamp = dt.timestamp(); asserteq!(timestamp, 946665000); ```

Pretty-printing a string will use the correct abbreviation for the timezone

```rust use chrono::TimeZone; use chrono_tz::Europe::London;

let dt = London.ymd(2016, 5, 10).andhms(12, 0, 0); asserteq!(dt.tostring(), "2016-05-10 12:00:00 BST"); asserteq!(dt.to_rfc3339(), "2016-05-10T12:00:00+01:00"); ```

You can convert a timezone string to a timezone using the FromStr trait

```rust use chrono::TimeZone; use chronotz::Tz; use chronotz::UTC;

let tz: Tz = "Antarctica/SouthPole".parse().unwrap(); let dt = tz.ymd(2016, 10, 22).andhms(12, 0, 0); let utc = dt.withtimezone(&UTC); asserteq!(utc.to_string(), "2016-10-21 23:00:00 UTC"); ```

no_std Support

To use this library without depending on the Rust standard library, put this in your Cargo.toml:

toml [dependencies] chrono = { version = "0.4", default-features = false } chrono-tz = { version = "0.5", default-features = false }

If you are using this library in an environment with limited program space, such as a microcontroller, take note that you will also likely need to enable optimizations and Link Time Optimization: ```toml [profile.dev] opt-level = 2 lto = true

[profile.release] lto = true ```

Otherwise, the additional binary size added by this library may overflow available program space and trigger a linker error.

Limiting the Timezone Table to Zones of Interest

Chrono-tz by default generates timezones for all entries in the IANA database. If you are interested in only a few timezones you can use enable the filter-by-regex feature and set an environment variable to select them. The environment variable is called CHRONO_TZ_TIMEZONE_FILTER and is a regular expression. It should be specified in your top-level build:

sh CHRONO_TZ_TIMEZONE_FILTER="(Europe/London|US/.*)" cargo build

This can significantly reduce the size of the generated database, depending on how many timezones you are interested in. Wikipedia has an article listing the timezone names.

The filtering applied is liberal; if you use a pattern such as "US/.*" then chrono-tz will include all the zones that are linked, such as "America/Denver", not just "US/Mountain".

Developing

chrono-tz uses git submodules, so in order to build locally you will need to run git submodule init and git submodule update.

Future Improvements

  • Handle leap seconds
  • Handle Julian to Gregorian calendar transitions
  • Load tzdata always from latest version
  • Dynamic tzdata loading

Owner

  • Name: Chronotope
  • Login: chronotope
  • Kind: organization

Home for Chrono, a Rust date/time library

GitHub Events

Total
  • Create event: 27
  • Release event: 4
  • Issues event: 10
  • Watch event: 20
  • Delete event: 21
  • Issue comment event: 45
  • Push event: 29
  • Pull request review comment event: 27
  • Pull request review event: 29
  • Pull request event: 30
  • Fork event: 5
Last Year
  • Create event: 27
  • Release event: 4
  • Issues event: 10
  • Watch event: 20
  • Delete event: 21
  • Issue comment event: 45
  • Push event: 29
  • Pull request review comment event: 27
  • Pull request review event: 29
  • Pull request event: 30
  • Fork event: 5

Committers

Last synced: 12 months ago

All Time
  • Total Commits: 354
  • Total Committers: 43
  • Avg Commits per committer: 8.233
  • Development Distribution Score (DDS): 0.774
Past Year
  • Commits: 22
  • Committers: 6
  • Avg Commits per committer: 3.667
  • Development Distribution Score (DDS): 0.409
Top Committers
Name Email Commits
Ben S o****m@b****e 80
Djzin d****n 66
Brandon W Maister q****r@g****m 45
Dirkjan Ochtman d****n@o****l 44
Paul Dicker p****l@p****l 44
Brandon W Maister b****m@k****m 8
Lucio Franco l****4@g****m 6
Ariel Dabalsa a****a@g****m 5
Ian Wagner i****r@s****m 4
Ian Wagner i****e@g****m 3
Malloc Voidstar 1****a 3
Nikhil Benesch n****h@g****m 3
Andrea Corradi a****c@u****t 2
Andrew Kane a****w@a****g 2
Kristofer Rye k****e@g****m 2
René Kijewski r****i@f****e 2
Léo Gaspard l****o@g****o 2
Ondřej Hošek o****k@g****m 2
Paolo Barbolini p****i@m****t 2
Petros Angelatos p****g@g****m 2
Philip Daniels P****1@g****m 2
Ran Benita r****n@u****m 2
Utkarsh Upadhyay m****t@g****m 2
klensy k****y 2
laralove l****3@i****m 1
kennytm k****m@g****m 1
bspeice b****e 1
David Quintanel d****l@k****m 1
Filipp Samoilov f****v@w****m 1
Jared Bosco j****o@f****m 1
and 13 more...

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 63
  • Total pull requests: 140
  • Average time to close issues: about 1 year
  • Average time to close pull requests: about 2 months
  • Total issue authors: 54
  • Total pull request authors: 40
  • Average comments per issue: 2.65
  • Average comments per pull request: 1.49
  • Merged pull requests: 104
  • Bot issues: 0
  • Bot pull requests: 6
Past Year
  • Issues: 6
  • Pull requests: 40
  • Average time to close issues: about 11 hours
  • Average time to close pull requests: 7 days
  • Issue authors: 5
  • Pull request authors: 9
  • Average comments per issue: 0.33
  • Average comments per pull request: 0.85
  • Merged pull requests: 29
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • breezewish (3)
  • pitdicker (3)
  • ianthetechie (2)
  • robertbastian (2)
  • NilsIrl (2)
  • westy92 (2)
  • jorgecarleitao (2)
  • musically-ut (1)
  • quodlibetor (1)
  • kellpossible (1)
  • SudoDios (1)
  • jan-hudec (1)
  • fenhl (1)
  • ijackson (1)
  • jcare44 (1)
Pull Request Authors
  • djc (46)
  • pitdicker (29)
  • quodlibetor (16)
  • github-actions[bot] (6)
  • ianthetechie (5)
  • robertbastian (5)
  • LucioFranco (4)
  • paolobarbolini (4)
  • acrrd (4)
  • benesch (3)
  • sinanunansigma (2)
  • Kijewski (2)
  • mjdwitt (2)
  • RavuAlHemio (2)
  • yinho999 (2)
Top Labels
Issue Labels
documentation (4) enhancement (1) help wanted (1)
Pull Request Labels
breaking change (1)

Packages

  • Total packages: 4
  • Total downloads:
    • cargo 170,828,957 total
  • Total docker downloads: 70,022,210
  • Total dependent packages: 339
    (may contain duplicates)
  • Total dependent repositories: 8,785
    (may contain duplicates)
  • Total versions: 91
  • Total maintainers: 3
crates.io: chrono-tz

TimeZone implementations for chrono from the IANA database

  • Versions: 36
  • Dependent Packages: 329
  • Dependent Repositories: 3,186
  • Downloads: 62,386,893 Total
  • Docker Downloads: 23,341,715
Rankings
Dependent packages count: 0.3%
Downloads: 0.4%
Dependent repos count: 0.7%
Docker downloads count: 1.5%
Average: 3.6%
Forks count: 8.3%
Stargazers count: 10.5%
Maintainers (1)
Last synced: 10 months ago
crates.io: chrono-tz-build

internal build script for chrono-tz

  • Versions: 10
  • Dependent Packages: 1
  • Dependent Repositories: 2,513
  • Downloads: 54,795,601 Total
  • Docker Downloads: 23,338,780
Rankings
Downloads: 0.6%
Dependent repos count: 0.8%
Docker downloads count: 1.5%
Average: 5.3%
Dependent packages count: 18.2%
Maintainers (1)
Last synced: 10 months ago
proxy.golang.org: github.com/chronotope/chrono-tz
  • Versions: 36
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 7.0%
Average: 8.2%
Dependent repos count: 9.3%
Last synced: 10 months ago
crates.io: parse-zoneinfo

Parse zoneinfo files from the IANA database

  • Versions: 9
  • Dependent Packages: 9
  • Dependent Repositories: 3,086
  • Downloads: 53,646,463 Total
  • Docker Downloads: 23,341,715
Rankings
Downloads: 0.5%
Dependent repos count: 0.7%
Docker downloads count: 1.5%
Dependent packages count: 4.0%
Average: 9.1%
Forks count: 18.3%
Stargazers count: 29.8%
Maintainers (2)
Last synced: 10 months ago

Dependencies

Cargo.toml cargo
  • chrono 0.4 development
  • serde_test 1 development
  • chrono 0.4
  • phf 0.11
  • serde 1
  • uncased 0.9
.github/workflows/rust.yml actions
  • actions-rs/toolchain v1 composite
  • actions/checkout v2 composite
.github/workflows/update-tz.yml actions
  • actions/checkout v2 composite
  • quodlibetor/pull-request-action 1.0.6-patch1 composite
chrono-tz/Cargo.toml cargo
  • chrono 0.4 development
  • serde_test 1 development
  • chrono 0.4
  • phf 0.11
  • serde 1
  • uncased 0.9