Skip to content

Commit

Permalink
remove crate defined timezone constants
Browse files Browse the repository at this point in the history
This to enable build-time timezone filtering (chrono-tz feature filter-by-regex).
  • Loading branch information
oll3 committed Jul 13, 2024
1 parent f0416ed commit 2c99203
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 1,865 deletions.
1 change: 1 addition & 0 deletions rrule-afl-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rust-version.workspace = true
[dependencies]
afl = "*"
chrono = "0.4.19"
chrono-tz = "0.9.0"
num-traits = "0.2.15"

[dependencies.rrule]
Expand Down
5 changes: 3 additions & 2 deletions rrule-afl-fuzz/src/take_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ pub fn take_datetime(input: &mut &[u8]) -> DateTime<Tz> {
LocalResult::None => {
// Will always succeed
let nanos: i64 = take_data_i64(input);
Utc.timestamp_nanos(nanos).with_timezone(&Tz::UTC)
Utc.timestamp_nanos(nanos)
.with_timezone(&Tz::Tz(chrono_tz::Tz::UTC))
}
LocalResult::Single(datetime) | LocalResult::Ambiguous(datetime, _) => {
datetime.with_timezone(&Tz::UTC)
datetime.with_timezone(&Tz::Tz(chrono_tz::Tz::UTC))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rrule-debugger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rust-version.workspace = true
[dependencies]
rrule = { path = "../rrule" }
chrono = "0.4.19"
chrono-tz = "0.9.0"
clap = { version = "4.1.9", features = ["derive"] }
rrule-afl-fuzz = { version = "0.1.0", path = "../rrule-afl-fuzz" }
log = "0.4.16"
Expand Down
2 changes: 1 addition & 1 deletion rrule-debugger/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn test_parsed_rrule() {
}

fn ymd_hms(year: i32, month: u32, day: u32, hour: u32, minute: u32, second: u32) -> DateTime<Tz> {
Tz::UTC
Tz::Tz(chrono_tz::Tz::UTC)
.with_ymd_and_hms(year, month, day, hour, minute, second)
.unwrap()
}
4 changes: 3 additions & 1 deletion rrule/examples/manual_rrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rrule::{Frequency, RRule, Tz};

fn main() {
// Build an RRuleSet that starts the first day in 2020 at 9:00AM and occurs daily 5 times
let start_date = Tz::UTC.with_ymd_and_hms(2020, 1, 1, 9, 0, 0).unwrap();
let start_date = Tz::Tz(chrono_tz::Tz::UTC)
.with_ymd_and_hms(2020, 1, 1, 9, 0, 0)
.unwrap();
let rrule_set = RRule::default()
.count(5)
.freq(Frequency::Daily)
Expand Down
12 changes: 10 additions & 2 deletions rrule/examples/manual_rrule_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ fn main() {
NWeekday::Every(Weekday::Tue),
NWeekday::Every(Weekday::Wed),
])
.build(Tz::UTC.with_ymd_and_hms(2020, 1, 1, 9, 0, 0).unwrap())
.build(
Tz::Tz(chrono_tz::UTC)
.with_ymd_and_hms(2020, 1, 1, 9, 0, 0)
.unwrap(),
)
.expect("RRule invalid");

// Build exrule that occurs weekly on Wednesday
let exrule = RRule::default()
.count(4)
.freq(Frequency::Weekly)
.by_weekday(vec![NWeekday::Every(Weekday::Wed)])
.validate(Tz::UTC.with_ymd_and_hms(2020, 1, 1, 9, 0, 0).unwrap())
.validate(
Tz::Tz(chrono_tz::UTC)
.with_ymd_and_hms(2020, 1, 1, 9, 0, 0)
.unwrap(),
)
.expect("RRule invalid");

let recurrences = rrule_set.exrule(exrule).all(10).dates;
Expand Down
6 changes: 4 additions & 2 deletions rrule/examples/timezone_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use chrono::{DateTime, TimeZone};
use rrule::{Frequency, RRule, Tz};

fn main() {
let tz = Tz::Europe__Berlin;
let tz = Tz::Tz(chrono_tz::Tz::Europe__Berlin);
let start_date = tz.with_ymd_and_hms(2020, 1, 1, 9, 0, 0).unwrap();
let exdate = Tz::UTC.with_ymd_and_hms(2020, 1, 2, 8, 0, 0).unwrap();
let exdate = Tz::Tz(chrono_tz::Tz::UTC)
.with_ymd_and_hms(2020, 1, 2, 8, 0, 0)
.unwrap();

// Build an rrule set that occurs daily at 9:00 for 4 times
let rrule_set = RRule::default()
Expand Down
10 changes: 6 additions & 4 deletions rrule/src/core/rruleset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,15 @@ mod tests {

use crate::{Frequency, RRule, RRuleSet, Tz};

const UTC: Tz = Tz::Tz(chrono_tz::UTC);

#[test]
fn rruleset_string_roundtrip() {
let rruleset_str = "DTSTART:20120201T093000Z\nRRULE:FREQ=DAILY;COUNT=3;BYHOUR=9;BYMINUTE=30;BYSECOND=0\nRDATE;VALUE=DATE-TIME:19970101T000000Z,19970120T000000Z\nEXRULE:FREQ=YEARLY;COUNT=8;BYMONTH=6,7;BYMONTHDAY=1;BYHOUR=9;BYMINUTE=30;BYSECOND=0\nEXDATE;VALUE=DATE-TIME:19970121T000000Z";
let rruleset = RRuleSet::from_str(rruleset_str).unwrap();

// Check start date
let dt_start = Tz::UTC.with_ymd_and_hms(2012, 2, 1, 9, 30, 0).unwrap();
let dt_start = UTC.with_ymd_and_hms(2012, 2, 1, 9, 30, 0).unwrap();
assert_eq!(rruleset.dt_start, dt_start);

// Check rrule
Expand All @@ -371,8 +373,8 @@ mod tests {
assert_eq!(
rruleset.rdate,
vec![
Tz::UTC.with_ymd_and_hms(1997, 1, 1, 0, 0, 0).unwrap(),
Tz::UTC.with_ymd_and_hms(1997, 1, 20, 0, 0, 0).unwrap()
UTC.with_ymd_and_hms(1997, 1, 1, 0, 0, 0).unwrap(),
UTC.with_ymd_and_hms(1997, 1, 20, 0, 0, 0).unwrap()
]
);

Expand All @@ -389,7 +391,7 @@ mod tests {
// Check exdate
assert_eq!(
rruleset.exdate,
vec![Tz::UTC.with_ymd_and_hms(1997, 1, 21, 0, 0, 0).unwrap()]
vec![UTC.with_ymd_and_hms(1997, 1, 21, 0, 0, 0).unwrap()]
);

// Serialize to string again
Expand Down
Loading

0 comments on commit 2c99203

Please sign in to comment.