# shellcheck shell=dash

___x_cmd_fileage_stat(){
    local x_=""
    if ___x_cmd_fileage_stat_ "$@"; then
        printf "%s\n" "$x_"
    else
        printf "%s\n" "" # for pipline
        return 1
    fi
}

___x_cmd_fileage_stat_(){
    # Reference: https://linux.die.net/man/1/stat
    if ___x_cmd_cmds stat -c "%Y" /bin/sh 2>/dev/null 1>&2; then
        ___x_cmd_fileage_stat_(){
            local param="%Y"
            case "$1" in
                -m) shift ;;
                # https://unix.stackexchange.com/questions/24441/get-file-created-creation-time
                -c) param="%Y"; shift ;;  # created time using modified time
                -a) param="%X"; shift ;;
            esac

            x_=
            [ -f "$1" ] || return 1
            x_="$(___x_cmd_cmds stat -c "$param" "$@")"
        }
    elif ___x_cmd_cmds stat -f "%m" /bin/sh 2>/dev/null 1>&2; then
        ___x_cmd_fileage_stat_(){
            local param="%m"
            case "$1" in
                -m) shift ;;
                -c) param="%c"; shift ;;
                -a) param="%a"; shift ;;
            esac

            x_=
            [ -f "$1" ] || return 1
            x_="$(___x_cmd_cmds stat -f "$param" "$@")"
        }
    else
        return 1
    fi

    ___x_cmd_fileage_stat_ "$@"
}
