Functional Weave
Code in TypeScript

dates.days-between@1.0.0

impl/rust.rs

597 bytes · the Rust implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::dates_add_days::epoch_day_from_iso;  ← from dates.add-days ^1.0.0 · built alongside by fune

/// Calendar days from one date to another: end minus start, negative when the
/// end is earlier. Both dates are parsed strictly, so an impossible date fails
/// rather than being rolled into the next month.
///
/// # Panics
/// Panics if either date is malformed or impossible.
pub fn days_between(start_iso: &str, end_iso: &str) -> i64 {
    epoch_day_from_iso(end_iso) - epoch_day_from_iso(start_iso)
}

pub fn fune_vector(args: &[Value]) -> Value {
    Value::Int(days_between(args[0].as_str(), args[1].as_str()))
}