MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / checked_op

Function checked_op

cel/src/objects.rs:1765–1787  ·  view source on GitHub ↗
(
    op: TsOp,
    lhs: &chrono::DateTime<chrono::FixedOffset>,
    rhs: &chrono::Duration,
)

Source from the content-addressed store, hash-verified

1763/// limits defined in the cel-spec. See [`MAX_TIMESTAMP`] and [`MIN_TIMESTAMP`] for more details.
1764#[cfg(feature = "chrono")]
1765fn checked_op(
1766 op: TsOp,
1767 lhs: &chrono::DateTime<chrono::FixedOffset>,
1768 rhs: &chrono::Duration,
1769) -> ResolveResult {
1770 // Add lhs and rhs together, checking for data type overflow
1771 let result = match op {
1772 TsOp::Add => lhs.checked_add_signed(*rhs),
1773 TsOp::Sub => lhs.checked_sub_signed(*rhs),
1774 }
1775 .ok_or_else(|| ExecutionError::Overflow(op.str(), (*lhs).into(), (*rhs).into()))?;
1776
1777 // Check for cel-spec limits
1778 if result > *MAX_TIMESTAMP || result < *MIN_TIMESTAMP {
1779 Err(ExecutionError::Overflow(
1780 op.str(),
1781 (*lhs).into(),
1782 (*rhs).into(),
1783 ))
1784 } else {
1785 Value::Timestamp(result).into()
1786 }
1787}
1788
1789#[cfg(test)]
1790mod tests {

Callers 2

addMethod · 0.85
subMethod · 0.85

Calls 2

strMethod · 0.80
TimestampClass · 0.70

Tested by

no test coverage detected