| 1 | use superrust-analyzer cargo rrule 0.14.0 iter/::utilsrust-analyzer cargo rrule 0.14.0 iter/utils/::{add_time_to_daterust-analyzer cargo rrule 0.14.0 iter/utils/add_time_to_date()., date_from_ordinalrust-analyzer cargo rrule 0.14.0 iter/utils/date_from_ordinal()., pymodrust-analyzer cargo rrule 0.14.0 iter/utils/pymod().}; |
| 2 | 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#; |
| 3 | use chronorust-analyzer cargo chrono 0.4.40 crate/::NaiveTimerust-analyzer cargo chrono 0.4.40 naive/time/NaiveTime#; |
| 4 | |
| 5 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn build_pos_listrust-analyzer cargo rrule 0.14.0 iter/pos_list/build_pos_list().( |
| 6 | by_set_pos: &[i32], |
| 7 | dayset: &[usize], |
| 8 | timeset: &[NaiveTimerust-analyzer cargo chrono 0.4.40 naive/time/NaiveTime#], |
| 9 | year_ordinal: i64, |
| 10 | tz: Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#, |
| 11 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<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#>> { |
| 12 | let mut pos_list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 13 | |
| 14 | if timeset.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 15 | return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 16 | } |
| 17 | |
| 18 | let timeset_len = u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u32][`TryFrom<usize>`]try_from().(timeset.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 19 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("timeset length is a maximum of 24 * 60 * 60 which is covered by u32"); |
| 20 | let timeset_len_float = f64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[f64][`From<u32>`]from().(timeset_len); |
| 21 | let timeset_len_int = i32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i32][`TryFrom<u32>`]try_from().(timeset_len) |
| 22 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("timeset length is a maximum of 24 * 60 * 60 which is covered by i32"); |
| 23 | for pos in by_set_pos { |
| 24 | let pos = if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 { pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&i32`][`Sub<i32>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&i32`][`Sub<i32>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[`&i32`][`Sub<i32>`]sub().1 } else { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().pos }; |
| 25 | let day_pos = (f64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[f64][`From<i32>`]from().(pos) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().timeset_len_float).floorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/impl#[f64]floor().() as isize; |
| 26 | let time_pos = usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<i32>`]try_from().(pymodrust-analyzer cargo rrule 0.14.0 iter/utils/pymod().(pos, timeset_len_int)) |
| 27 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("modulus is a positive number and within the range of usize"); |
| 28 | |
| 29 | let day_idx = if day_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().0 { |
| 30 | let dayset_len = isize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[isize][`TryFrom<usize>`]try_from().(dayset.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 31 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("dayset is controlled by us and is never more than isize::MAX"); |
| 32 | let index = dayset_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().day_pos; |
| 33 | match usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`TryFrom<isize>`]try_from().(index) { |
| 34 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(day_idx) => day_idx, |
| 35 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => continue, |
| 36 | } |
| 37 | } else { |
| 38 | usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`TryFrom<isize>`]try_from().(day_pos).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("a non-negative isize fits within a usize") |
| 39 | }; |
| 40 | let day = match dayset.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(day_idx) { |
| 41 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(day) => day, |
| 42 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => continue, |
| 43 | }; |
| 44 | let day = i64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[i64][`TryFrom<usize>`]try_from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().day) |
| 45 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("dayset is controlled by us and all elements are within range of i64"); |
| 46 | |
| 47 | // Get ordinal which is UTC |
| 48 | let date = date_from_ordinalrust-analyzer cargo rrule 0.14.0 iter/utils/date_from_ordinal().(year_ordinal rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().day); |
| 49 | // Create new Date + Time combination |
| 50 | // Use Time from `timeset`. |
| 51 | let time = timeset[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().time_pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 52 | let res = match add_time_to_daterust-analyzer cargo rrule 0.14.0 iter/utils/add_time_to_date().(tz, date, time) { |
| 53 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(date) => date, |
| 54 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => continue, |
| 55 | }; |
| 56 | |
| 57 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pos_list.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&res) { |
| 58 | pos_list.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(res); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | pos_list.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 63 | |
| 64 | pos_list |
| 65 | } |