# shellcheck shell=dash

___x_cmd_date_epochminus_(){
    local is_human=""
    case "$1" in
        -H) is_human=1 ;;
    esac

    local a="$1";   ___x_cmd_date_epochminus_1000_ "$a" || return $?;   a="$x_"
    local b="$2";   ___x_cmd_date_epochminus_1000_ "$b" || return $?;   b="$x_"
    local res=$((a - b))
    res="000${res}"
    b="${res%???}"
    a="${res#"${b}"}"
    x_="${b}.${a}"
    ___x_cmd_date_epochminus_trim0_ "$x_" || return $?
    [ "$x_" = "${x_#.}" ] || x_="0${x_}"

    if [ "$is_human" = 1 ]; then
        ___x_cmd humantime sec_ "$x_"
    fi
}

___x_cmd_date_epochminus(){
    local x_=""; ___x_cmd_date_epochminus_ "$@" || return $?
    printf "%s\n" "$x_"
}

___x_cmd_date_epochminus_1000_(){
    case "$1" in
        *.*)
                local a="${1#*.}000"
                a="${a%"${a#???}"}"
                x_="${1%.*}${a}"
                ;;
        *)      x_="${1}000" ;;
    esac
    ___x_cmd_date_epochminus_trim0_ "$x_"
}

___x_cmd_date_epochminus_trim0_(){
    local a="$1"
    local b="${a#0}"
    while [ "$a" != "$b" ]; do
        a="$b"
        b="${a#0}"
    done
    x_="$b"
}
