kennytm / tzfile Goto Github PK
View Code? Open in Web Editor NEWRust chrono::TimeZone implementation using the system tz database
License: MIT License
Rust chrono::TimeZone implementation using the system tz database
License: MIT License
this would enable more cases like accepting user provided timezone identifiers
Tz::named
always loads its time zones from /usr/share/zoneinfo/
, even if TZDIR
is set. From what I can tell, glibc respects this variable.
This would be useful since NixOS uses a nonstandard time zone directory location (/etc/zoneinfo/
or /etc/static/zoneinfo/
) which this library currently can't find.
Windows user here, is there a chance to use it?
According to https://www.freedesktop.org/software/systemd/man/localtime.html, if /etc/localtime
is missing, the default UTC time zone should be used.
Currently, Tz::local()
returns a No such file or directory
error. It would be nice if Tz::local()
defaults to parsing /usr/share/zoneinfo/UTC
if /etc/localtime
is not found.
Chrono's Serialize implementation uses Debug formatting for Serialize, and assumes that it will produce valid RFC 3339: https://docs.rs/chrono/0.4.19/src/chrono/datetime.rs.html#2066
https://docs.rs/chrono/0.4.19/src/chrono/datetime.rs.html#720
ArcTz's offset prints the time zone's name in Debug, not the offset, so DateTime serializes into an incorrect format.
For example:
use chrono::{DateTime, NaiveDate, TimeZone};
use serde::Serialize;
use tzfile::ArcTz;
#[derive(Debug, Serialize)]
pub struct Foo {
pub date: DateTime<ArcTz>,
}
fn main() {
let tz = ArcTz::named("Europe/Budapest").unwrap();
let dt = tz.from_utc_datetime(&NaiveDate::from_ymd(2021, 3, 11).and_hms(17, 49, 32));
println!("{:?}", dt.offset());
let foo = Foo { date: dt };
let j = serde_json::to_string(&foo).unwrap();
println!("{}", j);
}
This prints {"date":"2021-03-11T18:49:32CET"}
, which isn't valid RFC3339.
---- chrono_tz_tests::second_offsets stdout ----
thread 'chrono_tz_tests::second_offsets' panicked at 'assertion failed: `(left == right)`
left: `"1914-01-01 13:40:28 WET"`,
right: `"1914-01-01 14:00:00 AMT"`', src/lib.rs:913:9
It would be nice to mirror the functionality from chrono_tz
and, for example, make tzfile::Tz
serializable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.