
___x_cmd_claude_usage_util_offset_date_(){
    local date="$1"
    local offset="${2:-1}"
    if ___x_cmd os is darwin; then
        local sign="+"
        if [ "$offset" -lt 0 ]; then
            sign=""
        fi
        x_="$(___x_cmd_cmds date -v${sign}${offset}d -jf "%Y-%m-%d" "$date" +"%Y-%m-%d")"
    else
        x_="$(___x_cmd_cmds date -d "$date $offset days" +"%Y-%m-%d")"
    fi
}

___x_cmd_claude_usage_util_date_to_sec_(){
    local date="$1"
    if ___x_cmd os is darwin; then
        x_="$(___x_cmd_cmds date -j -f "%Y-%m-%d" "$date" +%s)"
    else
        x_="$(___x_cmd_cmds date -d "$date" +%s)"
    fi
}

___x_cmd_claude_usage_util_month_end_(){
    local month="$1"
    local date_start="${month}-01"
    if ___x_cmd os is darwin; then
        x_="$(___x_cmd_cmds date -v+1m -v1d -v-1d -jf "%Y-%m-%d" "$date_start" +"%Y-%m-%d")"
    else
        x_="$(___x_cmd_cmds date -d "$date_start +1 month -1 day" +"%Y-%m-%d")"
    fi
}

___x_cmd_claude_usage_util_offset_month_(){
    local month="$1"
    local offset="${2:-1}"

    local op=
    local date_start="${month}-01"
    if ___x_cmd os is darwin; then
        if [ "${offset#-}" != "$offset" ]; then
            op=""
        else
            op="+"
        fi
        x_="$(___x_cmd_cmds date -v${op}${offset}m -jf "%Y-%m-%d" "$date_start" +"%Y-%m")"
    else
        x_="$(___x_cmd_cmds date -d "$date_start $offset month" +"%Y-%m")"
    fi
}
