Giter VIP home page Giter VIP logo

tzdb's People

Contributors

dependabot[bot] avatar kijewski avatar lopopolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

isgasho clownsw

tzdb's Issues

Transition date ranges

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?

Don't generate time zones with leap seconds by default

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.

Use a git submodule instead of squashing commits

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:

  • Create a new generated branch with only the generated data, and squash the branch to leave only one commit, then push it on Github.
  • Switch to the main branch, delete the 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

tzdb::local_tz() function get None ,existing problems tzdb 0.4.1 version

ref #101

  • rust code
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);
}
  • exec cargo run
~ cargo run
"../usr/share/zoneinfo/Asia/Shanghai"
~
  • Then ,see 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

tzdb::local_tz() function get None in linux, expect get Some value .

~ 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

Optional `now` module in 0.5.x

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.

Make `iana-time-zone` dep and `local_tz` function optional

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.