kijewski / tzdb Goto Github PK
View Code? Open in Web Editor NEWStatic time zone information for tz-rs.
Home Page: https://docs.rs/tzdb
License: Apache License 2.0
Static time zone information for tz-rs.
Home Page: https://docs.rs/tzdb
License: Apache License 2.0
I'm consuming an API that takes future DST transitions to let the system know when to update its time. I like the idea of this crate and that it can be used independently of time zone info tied to an OS / file system.
When I enumerate the list of transitions for a time zone, say for America/New_York
, I notice the range only goes up to 1173596400
, or Sun Mar 11 2007.
fn main() {
let time_zone = tzdb::tz_by_name("America/New_york").unwrap();
let latest_transition = time_zone
.transitions()
.iter()
.map(|&t| t.unix_leap_time())
.max()
.unwrap();
println!("{}", latest_transition);
}
1173596400
However, when I run make-tzdb
manually on a local Manjaro box, I get a mod.rs that contains transitions up to 2140668000
or Sun Nov 01 2037.
This system appears to have the latest tzdata version 2022g installed.
$ head -n 1 /usr/share/zoneinfo/tzdata.zi
# version 2022g
Is it possible there is some time zone transition info missing in the generated code submodule?
Since the tz-rs
crate only work with Unix times and not TAI, it is better to generate time zones without leap seconds by default to avoid having to compute the Unix leap times associated to the time zones transitions.
serde_cbor is unmaintained
Details | |
---|---|
Status | unmaintained |
Package | serde_cbor |
Version | 0.11.2 |
URL | https://github.com/pyfisch/cbor |
Date | 2021-08-15 |
The serde_cbor
crate is unmaintained. The author has archived the github repository.
Alternatives proposed by the author:
See advisory page for additional details.
I cannot make a PR since this needs two branches, one of which is a squashed branch:
https://github.com/x-hgg-x/tzdb/tree/generated
https://github.com/x-hgg-x/tzdb/tree/v0.5.x
Steps to reproduce:
generated
branch with only the generated data, and squash the branch to leave only one commit, then push it on Github.src/generated
folder and commit, then run the command git submodule add -f -b generated -- ./ src/generated
.After modifying the generated data, we can then do the following :
cd src/generated
git checkout generated
git add .
git commit --amend --no-edit # Don't keep history for the generated files
git push
cd ../..
git add src/generated
git commit -m 'update'
git push
So I would like to be able to get current time zone name? Is it possible to add that feature?
ref #101
fn main() {
const PREFIX: &str = "/usr/share/zoneinfo/";
let mut s = std::fs::read_link("/etc/localtime").unwrap()
.into_os_string()
.into_string().unwrap();
println!("{:?}",s);
}
~ cargo run
"../usr/share/zoneinfo/Asia/Shanghai"
~
etc/localtime
path~ ls -als /etc/localtime
0 lrwxrwxrwx 1 root root 35 Jul 1 00:46 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai
~
So,above code return Relative path
,not a Absolute path
. It's seems a bug:https://github.com/strawlab/iana-time-zone/blob/main/src/tz_linux.rs#L18-L29
In iana-time-zone
respsitory not include Relative path
, May be need fix.
...
const PREFIX: &str = "/usr/share/zoneinfo/";
let mut s = read_link("/etc/localtime")?
.into_os_string()
.into_string()
.map_err(|_| crate::GetTimezoneError::FailedParsingString)?;
if !s.starts_with(PREFIX) {
return Err(crate::GetTimezoneError::FailedParsingString);
}
// Trim to the correct length without allocating.
s.replace_range(..PREFIX.len(), "");
...
recommend link:https://stackoverflow.com/questions/30511331/getting-the-absolute-path-from-a-pathbuf
Hi!
Thank you for your crate!
Looks like something is wrong:
let tz = tz_by_name("Asia/Kuala_Lumpur").expect(("Not found"));
Title says it all :)
~ uname -a
~ Linux 3.10.x86_64 #1 SMP Wed Feb 23 16:47:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
~ timedatectl
Local time: Tue 2022-08-09 17:46:20 CST
Universal time: Tue 2022-08-09 09:46:20 UTC
RTC time: Tue 2022-08-09 09:46:20
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
Hi @Kijewski, as a consumer of tzdb
, I prefer to delegate to tz-rs
for "now" functionality. It looks like the 0.5.x branch which is in pre-release includes a new tzdb::now
module which depends on utcnow
.
Would you be open to gating tzdb::now
and the utcnow
dependency behind an on-by-default cargo feature?
My motivation here is that I prefer to not have dependencies in my Cargo.lock
file that my applications don't use.
I'm happy to push a PR for this if you'd like me to.
If strawlab/iana-time-zone#104 is merged, I'd like to depend on iana-time-zone
directly so I can control which features are activated. I believe I'd be able to implement local_tz
myself by calling:
let tz = tzdb::raw_tz_by_name(iana_time_zone::get_timezone()?);
Additionally, un-nesting iana-time-zone
from this crate's dependency tree should improve compile times for apps depending on tzdb
by allowing this crate (which takes 6 seconds to compile on my machine) to move earlier in the crate DAG.
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.