Functional Weave
Code in Rust

payroll.notice-period@1.0.1

impl/rust.rs

1,204 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::hr_length_of_service::length_of_service;  ← from hr.length-of-service ^1.0.0 · built alongside by fune

/// ERA 1996 s.86 minimum notice. Below one month's service the section does
/// not apply at all, which is different from one week: an employer who
/// dismisses on day 20 owes no statutory notice.
///
/// # Panics
/// Panics on a malformed date or a notice date before the start date.
pub fn statutory_notice(start_date: &str, notice_date: &str) -> StatutoryNotice {
    let service = length_of_service(start_date, notice_date);
    let at_least_one_month = service.years > 0 || service.months > 0;
    let employer_weeks = if !at_least_one_month {
        0
    } else if service.years < 2 {
        1
    } else {
        service.years.min(12)
    };
    StatutoryNotice {
        service_years: service.years,
        employer_weeks,
        employee_weeks: if at_least_one_month { 1 } else { 0 },
    }
}

pub fn fune_vector(args: &[Value]) -> Value {
    let n = statutory_notice(args[0].as_str(), args[1].as_str());
    Value::obj(vec![
        ("serviceYears", Value::Int(n.service_years)),
        ("employerWeeks", Value::Int(n.employer_weeks)),
        ("employeeWeeks", Value::Int(n.employee_weeks)),
    ])
}