| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 2 | |
| 3 | use superrust-analyzer cargo rrule 0.14.0 parser/::{regexrust-analyzer cargo rrule 0.14.0 parser/regex/::ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#}; |
| 4 | use craterust-analyzer cargo rrule 0.14.0 crate/::{corerust-analyzer cargo rrule 0.14.0 core/::Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#, NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#}; |
| 5 | use chronorust-analyzer cargo chrono 0.4.40 crate/::{NaiveDaterust-analyzer cargo chrono 0.4.40 naive/date/NaiveDate#, TimeZonerust-analyzer cargo chrono 0.4.40 offset/TimeZone#, Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#}; |
| 6 | |
| 7 | /// Attempts to convert a `str` to a `chrono_tz::Tz`. |
| 8 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn parse_timezonerust-analyzer cargo rrule 0.14.0 parser/datetime/parse_timezone().(tz: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 9 | chrono_tzrust-analyzer cargo chrono-tz 0.10.3 crate/::Tzrust-analyzer cargo chrono-tz 0.10.3 timezones/Tz#::from_strrust-analyzer cargo chrono-tz 0.10.3 timezones/impl#[Tz][FromStr]from_str().(tz) |
| 10 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidTimezonerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidTimezone#(tz.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 11 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#Tz#) |
| 12 | } |
| 13 | |
| 14 | /// Convert a datetime string and a timezone to a `chrono::DateTime<Tz>`. |
| 15 | /// If the string specifies a zulu timezone with `Z`, then the timezone |
| 16 | /// argument will be ignored. |
| 17 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn datestring_to_daterust-analyzer cargo rrule 0.14.0 parser/datetime/datestring_to_date().( |
| 18 | dt: &str, |
| 19 | tz: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>, |
| 20 | property: &str, |
| 21 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<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#>, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 22 | let ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 23 | yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year., |
| 24 | monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month., |
| 25 | dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day., |
| 26 | timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time., |
| 27 | flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags., |
| 28 | } = ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#::from_ical_datetimerust-analyzer cargo rrule 0.14.0 parser/regex/impl#[ParsedDateString]from_ical_datetime().(dt).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime# { |
| 29 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 30 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 31 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 32 | |
| 33 | // Combine parts to create data time. |
| 34 | let date = |
| 35 | NaiveDaterust-analyzer cargo chrono 0.4.40 naive/date/NaiveDate#::from_ymd_optrust-analyzer cargo chrono 0.4.40 naive/date/impl#[NaiveDate]from_ymd_opt().(year, month, day).ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime# { |
| 36 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 37 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 38 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 39 | |
| 40 | // Spec defines this is a date-time OR date |
| 41 | // So the time can will be set to 0:0:0 if only a date is given. |
| 42 | // https://icalendar.org/iCalendar-RFC-5545/3-8-2-4-date-time-start.html |
| 43 | let (hour, min, sec) = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(time) = time { |
| 44 | (time.hourrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#hour., time.minrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#min., time.secrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#sec.) |
| 45 | } else { |
| 46 | (0, 0, 0) |
| 47 | }; |
| 48 | let datetime = date |
| 49 | .and_hms_optrust-analyzer cargo chrono 0.4.40 naive/date/impl#[NaiveDate]and_hms_opt().(hour, min, sec) |
| 50 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime# { |
| 51 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 52 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTime#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 53 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 54 | |
| 55 | // Apply timezone appended to the datetime before converting to UTC. |
| 56 | // For more info https://icalendar.org/iCalendar-RFC-5545/3-3-5-date-time.html |
| 57 | let datetime: 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#> = if flags.zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set. { |
| 58 | // If a `Z` is present, UTC should be used. |
| 59 | chronorust-analyzer cargo chrono 0.4.40 crate/::DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#::<chronorust-analyzer cargo chrono 0.4.40 crate/::Utcrust-analyzer cargo chrono 0.4.40 offset/utc/Utc#>::from_naive_utc_and_offsetrust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]from_naive_utc_and_offset().(datetime, chronorust-analyzer cargo chrono 0.4.40 crate/::Utcrust-analyzer cargo chrono 0.4.40 offset/utc/Utc#) |
| 60 | .with_timezonerust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]with_timezone().(&Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::UTCrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]UTC.) |
| 61 | } else { |
| 62 | // If no `Z` is present, local time should be used. |
| 63 | use chronorust-analyzer cargo chrono 0.4.40 crate/::offsetrust-analyzer cargo chrono 0.4.40 offset/::LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#; |
| 64 | // Get datetime in local time or machine local time. |
| 65 | // So this also takes into account daylight or standard time (summer/winter). |
| 66 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tz) = tz { |
| 67 | // Use the timezone specified in the `tz` |
| 68 | match tz.from_local_datetimerust-analyzer cargo chrono 0.4.40 offset/TimeZone#from_local_datetime().(&datetime) { |
| 69 | LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#::Nonerust-analyzer cargo chrono 0.4.40 offset/LocalResult#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimeInLocalTimezonerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeInLocalTimezone# { |
| 70 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeInLocalTimezone#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 71 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeInLocalTimezone#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 72 | }), |
| 73 | LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#::Singlerust-analyzer cargo chrono 0.4.40 offset/LocalResult#Single#(date) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(date), |
| 74 | LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#::Ambiguousrust-analyzer cargo chrono 0.4.40 offset/LocalResult#Ambiguous#(date1, date2) => { |
| 75 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::DateTimeInLocalTimezoneIsAmbiguousrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous# { |
| 76 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 77 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 78 | date1rust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#date1.: date1.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().(), |
| 79 | date2rust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#date2.: date2.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().(), |
| 80 | }) |
| 81 | } |
| 82 | }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 83 | } else { |
| 84 | // Use current system timezone |
| 85 | // TODO Add option to always use UTC when this is executed on a server. |
| 86 | let local = Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::LOCALrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]LOCAL.; |
| 87 | match local.from_local_datetimerust-analyzer cargo chrono 0.4.40 offset/TimeZone#from_local_datetime().(&datetime) { |
| 88 | LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#::Nonerust-analyzer cargo chrono 0.4.40 offset/LocalResult#None# => { |
| 89 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimeInLocalTimezonerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeInLocalTimezone# { |
| 90 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeInLocalTimezone#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 91 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeInLocalTimezone#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 92 | }) |
| 93 | } |
| 94 | LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#::Singlerust-analyzer cargo chrono 0.4.40 offset/LocalResult#Single#(date) => date, |
| 95 | LocalResultrust-analyzer cargo chrono 0.4.40 offset/LocalResult#::Ambiguousrust-analyzer cargo chrono 0.4.40 offset/LocalResult#Ambiguous#(date1, date2) => { |
| 96 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::DateTimeInLocalTimezoneIsAmbiguousrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous# { |
| 97 | valuerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#value.: dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 98 | propertyrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#property.: property.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 99 | date1rust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#date1.: date1.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().(), |
| 100 | date2rust-analyzer cargo rrule 0.14.0 parser/error/ParseError#DateTimeInLocalTimezoneIsAmbiguous#date2.: date2.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().(), |
| 101 | }) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(datetime) |
| 108 | } |
| 109 | |
| 110 | /// Attempts to convert a `str` to a `Weekday`. |
| 111 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn str_to_weekdayrust-analyzer cargo rrule 0.14.0 parser/datetime/str_to_weekday().(d: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 112 | let day = match &d.to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). { |
| 113 | "MO" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Monrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Mon#, |
| 114 | "TU" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Tuerust-analyzer cargo chrono 0.4.40 weekday/Weekday#Tue#, |
| 115 | "WE" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Wedrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Wed#, |
| 116 | "TH" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Thurust-analyzer cargo chrono 0.4.40 weekday/Weekday#Thu#, |
| 117 | "FR" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Frirust-analyzer cargo chrono 0.4.40 weekday/Weekday#Fri#, |
| 118 | "SA" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Satrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Sat#, |
| 119 | "SU" => Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Sunrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Sun#, |
| 120 | _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidWeekdayrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidWeekday#(d.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())), |
| 121 | }; |
| 122 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(day) |
| 123 | } |
| 124 | |
| 125 | /// Parse the "BYWEEKDAY" and "BYDAY" values |
| 126 | /// Example: `SU,MO,TU,WE,TH,FR` or `4MO` or `-1WE` |
| 127 | /// > For example, within a MONTHLY rule, +1MO (or simply 1MO) represents the first Monday |
| 128 | /// > within the month, whereas -1MO represents the last Monday of the month. |
| 129 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn parse_weekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/parse_weekdays().(val: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#>, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 130 | let mut wdays = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 131 | // Separate all days |
| 132 | for day in val.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(',') { |
| 133 | let wday = day.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 134 | wdays.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(wday); |
| 135 | } |
| 136 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(wdays) |
| 137 | } |
| 138 | |
| 139 | #[cfg(test)] |
| 140 | mod testsrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/ { |
| 141 | use superrust-analyzer cargo rrule 0.14.0 parser/datetime/::*; |
| 142 | |
| 143 | const US_PACIFICrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/US_PACIFIC.: Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz# = Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::US__Pacificrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]US__Pacific.; |
| 144 | |
| 145 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 146 | fn parses_valid_nweekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/parses_valid_nweekdays().() { |
| 147 | let tests = [ |
| 148 | ("SU", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Everyrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Every#(Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Sunrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Sun#)]), |
| 149 | ("-12TU", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Nthrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Nth#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().12, Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Tuerust-analyzer cargo chrono 0.4.40 weekday/Weekday#Tue#)]), |
| 150 | ( |
| 151 | "MO,WE", |
| 152 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Everyrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Every#(Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Monrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Mon#), NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Everyrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Every#(Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Wedrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Wed#)], |
| 153 | ), |
| 154 | ( |
| 155 | "MO,WE,3TU,-4SA", |
| 156 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 157 | NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Everyrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Every#(Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Monrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Mon#), |
| 158 | NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Everyrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Every#(Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Wedrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Wed#), |
| 159 | NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Nthrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Nth#(3, Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Tuerust-analyzer cargo chrono 0.4.40 weekday/Weekday#Tue#), |
| 160 | NWeekdayrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#::Nthrust-analyzer cargo rrule 0.14.0 core/rrule/NWeekday#Nth#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().4, Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Satrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Sat#), |
| 161 | ], |
| 162 | ), |
| 163 | ]; |
| 164 | |
| 165 | for (input, expected_output) in tests { |
| 166 | let output = parse_weekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/parse_weekdays().(input); |
| 167 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expected_output)); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 172 | fn rejects_invalid_nweekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/rejects_invalid_nweekdays().() { |
| 173 | let tests = ["", " ", "fjoasfjapsjop", "MONDAY", "MONDAY, TUESDAY"]; |
| 174 | |
| 175 | for input in tests { |
| 176 | let res = parse_weekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/parse_weekdays().(input); |
| 177 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 182 | fn parses_valid_weekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/parses_valid_weekdays().() { |
| 183 | let tests = [ |
| 184 | ("MO", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Monrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Mon#), |
| 185 | ("TU", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Tuerust-analyzer cargo chrono 0.4.40 weekday/Weekday#Tue#), |
| 186 | ("WE", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Wedrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Wed#), |
| 187 | ("TH", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Thurust-analyzer cargo chrono 0.4.40 weekday/Weekday#Thu#), |
| 188 | ("FR", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Frirust-analyzer cargo chrono 0.4.40 weekday/Weekday#Fri#), |
| 189 | ("SA", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Satrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Sat#), |
| 190 | ("SU", Weekdayrust-analyzer cargo chrono 0.4.40 weekday/Weekday#::Sunrust-analyzer cargo chrono 0.4.40 weekday/Weekday#Sun#), |
| 191 | ]; |
| 192 | |
| 193 | for (input, expected_output) in tests { |
| 194 | let output = str_to_weekdayrust-analyzer cargo rrule 0.14.0 parser/datetime/str_to_weekday().(input); |
| 195 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expected_output)); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 200 | fn rejects_invalid_weekdaysrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/rejects_invalid_weekdays().() { |
| 201 | let tests = ["", " ", "fjoasfjapsjop", "MONDAY", "MONDAY, TUESDAY"]; |
| 202 | |
| 203 | for input in tests { |
| 204 | let res = str_to_weekdayrust-analyzer cargo rrule 0.14.0 parser/datetime/str_to_weekday().(input); |
| 205 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 210 | fn parses_valid_datestime_strrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/parses_valid_datestime_str().() { |
| 211 | let tests = [ |
| 212 | ( |
| 213 | "19970902T090000Z", |
| 214 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 215 | 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().(1997, 9, 2, 9, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().(), |
| 216 | ), |
| 217 | ( |
| 218 | "19970902T090000", |
| 219 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::UTCrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]UTC.), |
| 220 | 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().(1997, 9, 2, 9, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().(), |
| 221 | ), |
| 222 | ( |
| 223 | "19970902T090000", |
| 224 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(US_PACIFICrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/US_PACIFIC.), |
| 225 | US_PACIFICrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/US_PACIFIC..with_ymd_and_hmsrust-analyzer cargo chrono 0.4.40 offset/TimeZone#with_ymd_and_hms().(1997, 9, 2, 9, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().(), |
| 226 | ), |
| 227 | ( |
| 228 | "19970902T090000Z", |
| 229 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(US_PACIFICrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/US_PACIFIC.), |
| 230 | // Timezone is overwritten by the zulu specified in the datetime string |
| 231 | 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().(1997, 9, 2, 9, 0, 0).unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().(), |
| 232 | ), |
| 233 | ]; |
| 234 | |
| 235 | for (datetime_str, timezone, expected_output) in tests { |
| 236 | let output = datestring_to_daterust-analyzer cargo rrule 0.14.0 parser/datetime/datestring_to_date().(datetime_str, timezone, "DTSTART"); |
| 237 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expected_output)); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 242 | fn rejects_invalid_datetime_strrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/rejects_invalid_datetime_str().() { |
| 243 | let tests = [ |
| 244 | ("", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 245 | ("TZID=America/New_York:19970902T090000", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 246 | ("19970902T09", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 247 | ("19970902T09", Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(US_PACIFICrust-analyzer cargo rrule 0.14.0 parser/datetime/tests/US_PACIFIC.)), |
| 248 | ]; |
| 249 | |
| 250 | for (datetime_str, timezone) in tests { |
| 251 | let res = datestring_to_daterust-analyzer cargo rrule 0.14.0 parser/datetime/datestring_to_date().(datetime_str, timezone, "DTSTART"); |
| 252 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 253 | } |
| 254 | } |
| 255 | } |