Debian Codegraph @

examples/timezone_support.rs

raw symbols SCIP
1 //! # Timezone Support
2 //!
3 //! This examples uses `RRuleSet` with one `RRule` that yields recurrences
4 //! in the Europe/Berlin timezone, and one EXDATE that is specified
5 //! in UTC and collides with one of those recurrences.
6
7 use chronorust-analyzer cargo chrono 0.4.40 crate/::{DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#, TimeZonerust-analyzer cargo chrono 0.4.40 offset/TimeZone#};
8 use rrulerust-analyzer cargo rrule 0.14.0 crate/::{Frequencyrust-analyzer cargo rrule 0.14.0 core/rrule/Frequency#, RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#, Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#};
9
10 fn mainrust-analyzer cargo rrule 0.14.0 main().() {
11 let tz = Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::Europe__Berlinrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]Europe__Berlin.;
12 let start_date = tz.with_ymd_and_hmsrust-analyzer cargo chrono 0.4.40 offset/TimeZone#with_ymd_and_hms().(2020, 1, 1, 9, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().();
13 let exdate = Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::UTCrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]UTC..with_ymd_and_hmsrust-analyzer cargo chrono 0.4.40 offset/TimeZone#with_ymd_and_hms().(2020, 1, 2, 8, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().();
14
15 // Build an rrule set that occurs daily at 9:00 for 4 times
16 let rrule_set = RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#::defaultrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`][Default]default().()
17 .countrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]count().(4)
18 .freqrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]freq().(Frequencyrust-analyzer cargo rrule 0.14.0 core/rrule/Frequency#::Dailyrust-analyzer cargo rrule 0.14.0 core/rrule/Frequency#Daily#)
19 .buildrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]build().(start_date)
20 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("RRule invalid")
21 // Exdate in the UTC at 8:00 which is 9:00 in Berlin and therefore
22 // collides with the second rrule occurrence.
23 .exdaterust-analyzer cargo rrule 0.14.0 core/rruleset/impl#[RRuleSet]exdate().(exdate);
24
25 let recurrences = rrule_set.all_uncheckedrust-analyzer cargo rrule 0.14.0 core/rruleset/impl#[RRuleSet]all_unchecked().();
26 // RRule contained 4 recurrences but 1 was filtered away by the exdate
27 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recurrences.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3);
28
29 // If you want to get back the DateTimes in another timezone, you can just iterate over the result
30 // and convert them to another timezone by using the with_timezone method provided by the DateTime type.
31 // Refer to the chrono and chrono-tz crates for more documentation on working with the DateTime type.
32
33 // Convert to `chrono_tz::Tz`
34 let _recurrences_in_moscow_tz: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<chrono_tzrust-analyzer cargo chrono-tz 0.10.3 crate/::Tzrust-analyzer cargo chrono-tz 0.10.3 timezones/Tz#>> = recurrences
35 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
36 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|d| d.with_timezonerust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]with_timezone().(&chrono_tzrust-analyzer cargo chrono-tz 0.10.3 crate/::Europerust-analyzer cargo chrono-tz 0.10.3 directory/Europe/::Moscowrust-analyzer cargo chrono-tz 0.10.3 directory/Europe/Moscow.))
37 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
38
39 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Done, everything worked.");
40 }