# shellcheck shell=sh        disable=SC2039,SC1090,SC3043,SC2263
# x-cmd cve lib/util — shared helpers used by data/, la/, fz/.
#
# These wrappers exist because `___x_cmd_cmds date` and `___x_cmd_cmds stat`
# route through x-cmd's wrappers, which refuse format-string arguments like
# `+%s` / `-c %Y`. We bypass with `command …` for the primitives.

# Current epoch seconds. Returns 0 on success, 0 on failure (always emits
# a number so callers don't have to handle empty).
___x_cmd_cve_util_now(){
    command date +%s 2>/dev/null || printf '0'
}

# Current calendar year (4 digits).
___x_cmd_cve_util_year(){
    command date +%Y 2>/dev/null || printf '0'
}

# Portable file mtime in seconds since epoch. Tries GNU stat (-c), then
# BSD/macOS stat (-f), then falls back to 0 so callers always get a number.
___x_cmd_cve_util_mtime(){
    command stat -c %Y "$1" 2>/dev/null \
    || command stat -f %m "$1" 2>/dev/null \
    || printf '0'
}