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::iso_from_epoch_day; ← from dates.add-days ^1.0.0 · built alongside by fune
/// 0001-01-01T00:00:00Z and 9999-12-31T23:59:59Z in Unix seconds.
const MIN_SECONDS: i64 = -62135596800;
const MAX_SECONDS: i64 = 253402300799;
/// Unix seconds as YYYY-MM-DDTHH:MM:SSZ. The day is floored (`div_euclid`),
/// so a negative time falls on the day before the epoch rather than rounding
/// towards it.
///
/// # Panics
/// Panics outside years 0001 to 9999.
pub fn unix_to_iso(seconds: i64) -> String {
if !(MIN_SECONDS..=MAX_SECONDS).contains(&seconds) {
panic!(
"seconds must be from {} to {} (years 0001 to 9999), received {}",
MIN_SECONDS, MAX_SECONDS, seconds
);
}
let day = seconds.div_euclid(86400);
let rest = seconds.rem_euclid(86400);
format!(
"{}T{:02}:{:02}:{:02}Z",
iso_from_epoch_day(day),
rest / 3600,
(rest % 3600) / 60,
rest % 60
)
}
pub fn fune_vector(args: &[Value]) -> Value {
let seconds = match &args[0] {
Value::Int(i) => *i,
other => panic!("seconds must be a whole number, received {}", other),
};
Value::str(&unix_to_iso(seconds))
}