Skip to content

Commit

Permalink
Temporal Instant migration cont. and related changes (#3601)
Browse files Browse the repository at this point in the history
* Migrate more of Instant

* Migrate round and some other adjustments

* Complete initial work on Instant

* Add some docs

* nanos -> quotient in roundNumberToIncrementAsIfPositive

* Update comments on todos
  • Loading branch information
nekevss authored Jan 23, 2024
1 parent 4ddcb81 commit ced2904
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 682 deletions.
11 changes: 0 additions & 11 deletions core/engine/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,6 @@ impl JsBigInt {
Self::new(x.inner.as_ref().clone().add(y.inner.as_ref()))
}

/// Utility function for performing `+` operation on more than two values.
#[inline]
#[cfg(feature = "temporal")]
pub(crate) fn add_n(values: &[Self]) -> Self {
let mut result = Self::zero();
for big_int in values {
result = Self::add(&result, big_int);
}
result
}

/// Performs the `-` operation.
#[inline]
#[must_use]
Expand Down
19 changes: 19 additions & 0 deletions core/engine/src/builtins/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ impl OptionType for JsString {
}
}

impl OptionType for f64 {
fn from_value(value: JsValue, context: &mut Context) -> JsResult<Self> {
let value = value.to_number(context)?;

if !value.is_finite() {
return Err(JsNativeError::range()
.with_message("roundingIncrement must be finite.")
.into());
}

Ok(value)
}
}

#[derive(Debug, Copy, Clone, Default)]
pub(crate) enum RoundingMode {
Ceil,
Expand Down Expand Up @@ -171,6 +185,7 @@ impl fmt::Display for RoundingMode {
}
}

// TODO: remove once confirmed.
#[cfg(feature = "temporal")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum UnsignedRoundingMode {
Expand All @@ -182,7 +197,9 @@ pub(crate) enum UnsignedRoundingMode {
}

impl RoundingMode {
// TODO: remove once confirmed.
#[cfg(feature = "temporal")]
#[allow(dead_code)]
pub(crate) const fn negate(self) -> Self {
use RoundingMode::{
Ceil, Expand, Floor, HalfCeil, HalfEven, HalfExpand, HalfFloor, HalfTrunc, Trunc,
Expand All @@ -201,7 +218,9 @@ impl RoundingMode {
}
}

// TODO: remove once confirmed.
#[cfg(feature = "temporal")]
#[allow(dead_code)]
pub(crate) const fn get_unsigned_round_mode(self, is_negative: bool) -> UnsignedRoundingMode {
use RoundingMode::{
Ceil, Expand, Floor, HalfCeil, HalfEven, HalfExpand, HalfFloor, HalfTrunc, Trunc,
Expand Down
Loading

0 comments on commit ced2904

Please sign in to comment.