Debian Codegraph @

src/core/datetime.rs

raw symbols SCIP
1 use superrust-analyzer cargo rrule 0.14.0 core/::timezonerust-analyzer cargo rrule 0.14.0 core/timezone/::Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#;
2 use chronorust-analyzer cargo chrono 0.4.40 crate/::{Datelikerust-analyzer cargo chrono 0.4.40 traits/Datelike#, Durationrust-analyzer cargo chrono 0.4.40 Duration#, NaiveTimerust-analyzer cargo chrono 0.4.40 naive/time/NaiveTime#, Timelikerust-analyzer cargo chrono 0.4.40 traits/Timelike#};
3
4 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn duration_from_midnightrust-analyzer cargo rrule 0.14.0 core/datetime/duration_from_midnight().(time: NaiveTimerust-analyzer cargo chrono 0.4.40 naive/time/NaiveTime#) -> Durationrust-analyzer cargo chrono 0.4.40 Duration# {
5 Durationrust-analyzer cargo chrono 0.4.40 Duration#::hoursrust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta]hours().(i64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i64][`From<u32>`]from().(time.hourrust-analyzer cargo chrono 0.4.40 naive/time/impl#[NaiveTime][Timelike]hour().()))
6 +rust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta][`Add<Self>`]add(). rust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta][`Add<Self>`]add().Durationrust-analyzer cargo chrono 0.4.40 Duration#::minutesrust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta]minutes().(i64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i64][`From<u32>`]from().(time.minuterust-analyzer cargo chrono 0.4.40 naive/time/impl#[NaiveTime][Timelike]minute().()))
7 +rust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta][`Add<Self>`]add(). rust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta][`Add<Self>`]add().Durationrust-analyzer cargo chrono 0.4.40 Duration#::secondsrust-analyzer cargo chrono 0.4.40 time_delta/impl#[TimeDelta]seconds().(i64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i64][`From<u32>`]from().(time.secondrust-analyzer cargo chrono 0.4.40 naive/time/impl#[NaiveTime][Timelike]second().()))
8 }
9
10 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn get_monthrust-analyzer cargo rrule 0.14.0 core/datetime/get_month().(dt: &chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>) -> u8 {
11 u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u8][`TryFrom<u32>`]try_from().(dt.monthrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Datelike]month().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("month is between 1-12 which is covered by u8")
12 }
13
14 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn get_dayrust-analyzer cargo rrule 0.14.0 core/datetime/get_day().(dt: &chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>) -> i8 {
15 i8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i8][`TryFrom<u32>`]try_from().(dt.dayrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Datelike]day().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("day is between 1-31 which is covered by i8")
16 }
17
18 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn get_hourrust-analyzer cargo rrule 0.14.0 core/datetime/get_hour().(dt: &chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>) -> u8 {
19 u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u8][`TryFrom<u32>`]try_from().(dt.hourrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Timelike]hour().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("hour is between 0-23 which is covered by u8")
20 }
21
22 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn get_minuterust-analyzer cargo rrule 0.14.0 core/datetime/get_minute().(dt: &chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>) -> u8 {
23 u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u8][`TryFrom<u32>`]try_from().(dt.minuterust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Timelike]minute().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("minute is between 0-59 which is covered by u8")
24 }
25
26 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn get_secondrust-analyzer cargo rrule 0.14.0 core/datetime/get_second().(dt: &chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>) -> u8 {
27 u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u8][`TryFrom<u32>`]try_from().(dt.secondrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`][Timelike]second().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("second is between 0-59 which is covered by u8")
28 }
29
30 /// Generates an iCalendar date-time string format with the prefix symbols.
31 /// Like: `:19970714T173000Z` or `;TZID=America/New_York:19970714T133000`
32 /// ref: <https://tools.ietf.org/html/rfc5545#section-3.3.5>
33 pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn datetime_to_ical_formatrust-analyzer cargo rrule 0.14.0 core/datetime/datetime_to_ical_format().(dt: &chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
34 let mut tz_prefix = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
35 let mut tz_postfix = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
36 let tz = dt.timezonerust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]timezone().();
37 match tz {
38 Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::Localrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#Local#(_) => {}
39 Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#Tz#(tz) => match tz {
40 chrono_tzrust-analyzer cargo chrono-tz 0.10.3 crate/::UTCrust-analyzer cargo chrono-tz 0.10.3 directory/UTC. => {
41 tz_postfix = "Z".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
42 }
43 tz => {
44 tz_prefix = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(";TZID={}", tz.namerust-analyzer cargo chrono-tz 0.10.3 timezones/impl#[Tz]name().());
45 }
46 },
47 }
48
49 let dt = dt.formatrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]format().("%Y%m%dT%H%M%S");
50 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}:{}{}", tz_prefix, dt, tz_postfix)
51 }