From 26f633416813d484b416e9344923809cd4ba21c5 Mon Sep 17 00:00:00 2001 From: nekevss Date: Wed, 11 Oct 2023 20:42:40 -0400 Subject: [PATCH] Review feedback --- .../src/builtins/temporal/calendar/mod.rs | 1 - .../src/builtins/temporal/date_equations.rs | 24 ++++++++----------- .../src/builtins/temporal/duration/mod.rs | 1 - 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/boa_engine/src/builtins/temporal/calendar/mod.rs b/boa_engine/src/builtins/temporal/calendar/mod.rs index 464271ce9f7..d58f35f6807 100644 --- a/boa_engine/src/builtins/temporal/calendar/mod.rs +++ b/boa_engine/src/builtins/temporal/calendar/mod.rs @@ -27,7 +27,6 @@ use rustc_hash::FxHashMap; mod iso; pub(crate) mod utils; -#[cfg(feature = "experimental")] #[cfg(test)] mod tests; diff --git a/boa_engine/src/builtins/temporal/date_equations.rs b/boa_engine/src/builtins/temporal/date_equations.rs index 7c4fd855db2..201a90386dc 100644 --- a/boa_engine/src/builtins/temporal/date_equations.rs +++ b/boa_engine/src/builtins/temporal/date_equations.rs @@ -94,25 +94,21 @@ pub(crate) fn epoch_time_for_month_given_year(m: i32, y: i32) -> f64 { } pub(crate) fn epoch_time_to_date(t: f64) -> i32 { + const OFFSETS: [i16; 12] = [ + 1, -30, -58, -89, -119, -150, -180, -211, -242, -272, -303, -333, + ]; let day_in_year = epoch_time_to_day_in_year(t); let in_leap_year = mathematical_in_leap_year(t); let month = epoch_time_to_month_in_year(t); - match month { - 0 => day_in_year + 1, - 1 => day_in_year - 30, - 2 => day_in_year - 59 - in_leap_year, - 3 => day_in_year - 89 - in_leap_year, - 4 => day_in_year - 119 - in_leap_year, - 5 => day_in_year - 150 - in_leap_year, - 6 => day_in_year - 180 - in_leap_year, - 7 => day_in_year - 211 - in_leap_year, - 8 => day_in_year - 242 - in_leap_year, - 9 => day_in_year - 272 - in_leap_year, - 10 => day_in_year - 303 - in_leap_year, - 11 => day_in_year - 333 - in_leap_year, - _ => unreachable!(), + // Cast from i32 to usize should be safe as the return must be 0-11 + let mut date = day_in_year + i32::from(OFFSETS[month as usize]); + + if month >= 2 { + date -= in_leap_year; } + + date } pub(crate) fn epoch_time_to_day_in_year(t: f64) -> i32 { diff --git a/boa_engine/src/builtins/temporal/duration/mod.rs b/boa_engine/src/builtins/temporal/duration/mod.rs index a953c0475be..5319b96c078 100644 --- a/boa_engine/src/builtins/temporal/duration/mod.rs +++ b/boa_engine/src/builtins/temporal/duration/mod.rs @@ -26,7 +26,6 @@ use super::{ mod record; -#[cfg(feature = "experimental")] #[cfg(test)] mod tests;