Skip to content

Commit 26403d1

Browse files
authored
chore: cleanup zoneinfo_rs crate (#674)
This PR does some general cleanup for the `zoneinfo_rs` crate. There are no major code changes besides organizational changes and alteration to module paths. It primarily completes the following: - Splits apart the types in the types module between rule, zone, and shared. - Adds some documentation to the general types - Adds an unstable feature and flags zoneinfo's `tzif` support The goal here is generally to clean up this crate for a 0.1.0 release.
1 parent 45d9746 commit 26403d1

File tree

12 files changed

+439
-367
lines changed

12 files changed

+439
-367
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exclude = [
3030
[workspace.dependencies]
3131
# Self
3232
temporal_rs = { version = "0.1.2", path = ".", default-features = false }
33-
timezone_provider = { version = "0.1.2", path = "./provider" }
33+
timezone_provider = { version = "0.1.2", path = "./provider", default-features = false }
3434
zoneinfo_rs = { version = "0.0.18", path = "./zoneinfo" }
3535

3636
# Dependencies

provider/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ zerovec = { workspace = true, features = ["derive", "alloc"] }
5757
tinystr = { workspace = true, features = ["zerovec"] }
5858

5959
# IANA dependency
60-
zoneinfo_rs = { workspace = true, features = ["std"], optional = true }
60+
zoneinfo_rs = { workspace = true, features = ["std", "unstable"], optional = true }
6161

6262
# tzif dependency
6363
tzif = { workspace = true, optional = true }

zoneinfo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ rust-version.workspace = true
77
authors.workspace = true
88
license.workspace = true
99
repository.workspace = true
10-
readme.workspace = true
1110
exclude.workspace = true
1211
include = [
1312
"src/**/*",
@@ -19,6 +18,7 @@ include = [
1918

2019
[features]
2120
std = []
21+
unstable = []
2222

2323
[dependencies]
2424
hashbrown = "0.16.0"

zoneinfo/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ zoneinfo files.
99
```rust
1010
use std::path::Path;
1111
use zoneinfo_rs::{ZoneInfoData, ZoneInfoCompiler};
12-
// Below assumes we are in the parent directory of `tzdata`
12+
// Below assumes we are in the parent directory of `tzdata`.
1313
let zoneinfo_filepath = Path::new("./tzdata/");
14+
// Parse and then compile the files from the directory.
1415
let parsed_data = ZoneInfoData::from_zoneinfo_directory(zoneinfo_filepath)?;
1516
let _compiled_data = ZoneInfoCompiler::new(parsed_data).build();
1617
```

zoneinfo/src/compiler.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
77
use alloc::collections::BTreeSet;
88
use alloc::string::String;
9+
10+
#[cfg(feature = "unstable")]
11+
use crate::tzif::TzifBlockV2;
12+
use crate::{
13+
posix::PosixTimeZone,
14+
types::{QualifiedTimeKind, Time},
15+
zone::ZoneRecord,
16+
ZoneInfoData,
17+
};
18+
919
use hashbrown::HashMap;
1020

1121
#[derive(Debug, Clone, PartialEq)]
@@ -108,6 +118,7 @@ pub struct CompiledTransitions {
108118
//
109119
// I think I would prefer all of that live in the `tzif` crate, but that will
110120
// be a process to update. So implement it here, and then upstream it?
121+
#[cfg(feature = "unstable")]
111122
impl CompiledTransitions {
112123
pub fn to_v2_data_block(&self) -> TzifBlockV2 {
113124
TzifBlockV2::from_transition_data(self)
@@ -123,14 +134,6 @@ pub struct CompiledTransitionsMap {
123134

124135
// ==== ZoneInfoCompiler build / compile methods ====
125136

126-
use crate::{
127-
posix::PosixTimeZone,
128-
types::{QualifiedTimeKind, Time},
129-
tzif::TzifBlockV2,
130-
zone::ZoneRecord,
131-
ZoneInfoData,
132-
};
133-
134137
/// The compiler for turning `ZoneInfoData` into `CompiledTransitionsData`
135138
pub struct ZoneInfoCompiler {
136139
data: ZoneInfoData,

zoneinfo/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ pub mod parser;
5454
pub mod posix;
5555
pub mod rule;
5656
pub mod types;
57-
pub mod tzif;
5857
pub mod zone;
5958

59+
#[cfg(feature = "unstable")]
60+
pub mod tzif;
61+
6062
#[doc(inline)]
6163
pub use compiler::ZoneInfoCompiler;
6264

@@ -67,6 +69,7 @@ use rule::Rules;
6769
use zone::ZoneRecord;
6870

6971
/// Well-known zone info file
72+
#[doc(hidden)]
7073
pub const ZONEINFO_FILES: &[&str] = &[
7174
"africa",
7275
"antarctica",

zoneinfo/src/posix.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
//! POSIX time zone types and implementation
2+
//!
3+
//! For more information on POSIX time zones, see the [GNU docs][gnu-docs].
4+
//!
5+
//! [gnu-docs]: https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
6+
17
use crate::{
28
rule::{LastRules, Rule},
3-
types::{DayOfMonth, Month, QualifiedTime, Sign, Time, WeekDay},
9+
types::{
10+
rule::{DayOfMonth, WeekDay},
11+
Month, QualifiedTime, Sign, Time,
12+
},
413
utils::month_to_day,
514
zone::ZoneEntry,
615
};
716
use alloc::string::String;
817
use core::fmt::Write;
918

10-
/// The POSIX time zone designated by the [GNU documentation][gnu-docs]
11-
///
12-
/// [gnu-docs]: https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
19+
/// A parsed POSIX time zone
1320
#[derive(Debug, PartialEq)]
1421
pub struct PosixTimeZone {
1522
pub abbr: PosixAbbreviation,

zoneinfo/src/rule.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use alloc::{borrow::ToOwned, string::String, vec, vec::Vec};
88

99
use crate::{
1010
parser::{next_split, ContextParse, LineParseContext, ZoneInfoParseError},
11-
types::{DayOfMonth, Month, QualifiedTime, Time, ToYear},
11+
types::{
12+
rule::{DayOfMonth, ToYear},
13+
Month, QualifiedTime, Time,
14+
},
1215
utils::{self, epoch_seconds_for_epoch_days},
1316
};
1417

@@ -301,7 +304,7 @@ impl Rule {
301304
#[cfg(test)]
302305
mod tests {
303306
use super::*;
304-
use crate::types::{Sign, WeekDay};
307+
use crate::types::{rule::WeekDay, Sign};
305308

306309
const TEST_DATA: [&str; 22] = [
307310
"Rule Algeria 1916 only - Jun 14 23:00s 1:00 S",

0 commit comments

Comments
 (0)