Skip to content

Commit

Permalink
bump tzf-rel to v0.0.2023-b and add data_version method (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn authored Mar 26, 2023
1 parent 71d4fd6 commit 6ac4768
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 62 deletions.
87 changes: 28 additions & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license-file = "LICENSE"
name = "tzf-rs"
readme = "README.md"
repository = "http://github.com/ringsaturn/tzf-rs"
version = "0.3.1"
version = "0.4.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -21,7 +21,7 @@ prost = "0.11"
rand = "0.8.5"

# tzf-rel = { git = "http://github.com/ringsaturn/tzf-rel", tag = "v0.0.2022-f5"}
tzf-rel = "0.0.2022-g1"
tzf-rel = "0.0.2023-b"

# geometry-rs = { git = "http://github.com/ringsaturn/geometry-rs", tag = "v0.1.0"}
geometry-rs = "0.1.2"
Expand Down
6 changes: 6 additions & 0 deletions src/gen/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct Timezones {
/// Reduced data will toggle neighbor search as plan b
#[prost(bool, tag = "2")]
pub reduced: bool,
#[prost(string, tag = "3")]
pub version: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand All @@ -89,6 +91,8 @@ pub struct CompressedTimezones {
pub method: i32,
#[prost(message, repeated, tag = "2")]
pub timezones: ::prost::alloc::vec::Vec<CompressedTimezone>,
#[prost(string, tag = "3")]
pub version: ::prost::alloc::string::String,
}
/// PreindexTimezone tile item.
///
Expand Down Expand Up @@ -117,6 +121,8 @@ pub struct PreindexTimezones {
pub agg_zoom: i32,
#[prost(message, repeated, tag = "3")]
pub keys: ::prost::alloc::vec::Vec<PreindexTimezone>,
#[prost(string, tag = "4")]
pub version: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
Expand Down
44 changes: 43 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ impl Item {
#[derive(Debug)]
pub struct Finder {
all: Vec<Item>,
data_version: String,
}

impl Finder {
/// `from_pb` is used when you can use your own timezone data, as long as
/// it's compatible with Proto's desc.
pub fn from_pb(tzs: gen::Timezones) -> Finder {
let mut f: Finder = Finder { all: vec![] };
let mut f: Finder = Finder {
all: vec![],
data_version: tzs.version,
};
for tz in tzs.timezones.iter() {
let mut polys: Vec<Polygon> = vec![];

Expand Down Expand Up @@ -167,6 +171,18 @@ impl Finder {
}
return ret;
}

/// Example:
///
/// ```rust
/// use tzf_rs::Finder;
///
/// let finder = Finder::new();
/// println!("{:?}", finder.data_version());
/// ```
pub fn data_version(&self) -> &str {
return &self.data_version;
}
}

/// deg2num is used to convert longitude, latitude to [Slippy map tilenames]
Expand Down Expand Up @@ -202,6 +218,7 @@ pub struct FuzzyFinder {
min_zoom: i64,
max_zoom: i64,
all: HashMap<(i64, i64, i64), String>, // K: <x,y,z>
data_version: String,
}

impl FuzzyFinder {
Expand All @@ -210,6 +227,7 @@ impl FuzzyFinder {
min_zoom: tzs.agg_zoom as i64,
max_zoom: tzs.idx_zoom as i64,
all: HashMap::new(),
data_version: tzs.version,
};
for item in tzs.keys.iter() {
f.all.insert(
Expand Down Expand Up @@ -251,6 +269,18 @@ impl FuzzyFinder {
}
return "";
}

/// Example:
///
/// ```rust
/// use tzf_rs::FuzzyFinder;
///
/// let finder = FuzzyFinder::new();
/// println!("{:?}", finder.data_version());
/// ```
pub fn data_version(&self) -> &str {
return &self.data_version;
}
}

/// It's most recommend to use, combine both [Finder] and [FuzzyFinder].
Expand Down Expand Up @@ -304,4 +334,16 @@ impl DefaultFinder {
pub fn timezonenames(&self) -> Vec<&str> {
return self.finder.timezonenames();
}

/// Example:
///
/// ```rust
/// use tzf_rs::DefaultFinder;
///
/// let finder = DefaultFinder::new();
/// println!("{:?}", finder.data_version());
/// ```
pub fn data_version(&self) -> &str {
return &self.finder.data_version;
}
}
3 changes: 3 additions & 0 deletions tzinfo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ message Timezone {
message Timezones {
repeated Timezone timezones = 1;
bool reduced = 2; // Reduced data will toggle neighbor search as plan b
string version = 3;
}

enum CompressMethod {
Expand All @@ -76,6 +77,7 @@ message CompressedTimezone {
message CompressedTimezones {
CompressMethod method = 1;
repeated CompressedTimezone timezones = 2;
string version = 3;
}

// PreindexTimezone tile item.
Expand All @@ -93,4 +95,5 @@ message PreindexTimezones {
int32 idxZoom = 1; // which zoom value the tiles generated
int32 aggZoom = 2; // which zoom value the tiles merge up with.
repeated PreindexTimezone keys = 3;
string version = 4;
}

0 comments on commit 6ac4768

Please sign in to comment.