File: tzdump.rs

package info (click to toggle)
rust-zoneinfo-compiled 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 124 kB
  • sloc: makefile: 10
file content (37 lines) | stat: -rw-r--r-- 1,164 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extern crate zoneinfo_compiled;

use std::env;
use std::fs::File;
use std::io::Read;
use std::path::Path;


// This example is broken until we have a way to get at the transitions in
// time zone data directly. Right now it just does a Rust Debug dump of the
// file...

fn main() {
    for arg in env::args().skip(1) {
        match File::open(&Path::new(&arg)) {
            Ok(mut file) => {
                let mut contents = Vec::new();
                file.read_to_end(&mut contents).unwrap();
                match zoneinfo_compiled::parse(contents) {
                    Ok(tzdata) => println!("{:#?}", tzdata),
                    Err(e)     => println!("Error: {}", e),
                }
            },
            Err(e) => println!("Couldn't open file {}: {}", arg, e),
        }
    }
}

// fn tzdump(mut tz: zoneinfo_compiled::TZData) {
//     tz.transitions.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
//
//     for t in tz.transitions {
//         let l = &*t.local_time_type;
//         println!("{:11?}: name:{:5} offset:{:5} DST:{:5} type:{:?}",
//                   t.timestamp, l.name, l.offset, l.is_dst, l.transition_type);
//     }
// }