Skip to main content

CountdownTextUtils

Utility functions to format countdowns in-game, built on TimeDurationUtils.

Functions​

formatCountdown​

CountdownTextUtils.formatCountdown(
seconds: number,
whenAtZeroText: string?,
locale: string?
) → string

Formats a number of seconds as countdown text, showing only as many units as the remaining time needs: 45, then 3:05, then 1:02:03, and 2 days 1:02:03 for longer waits. Each unit counts up to a round number before the next is used, so a one minute countdown starts at 60, a one hour countdown at 60:00, and a single day rolls into the hours as 47:15:00. The days word is localized through TimeDurationUtils.format; locale defaults to English. Fractional seconds are truncated.

print(CountdownTextUtils.formatCountdown(0, "Now!")) --> Now!
print(CountdownTextUtils.formatCountdown(185)) --> 3:05
print(CountdownTextUtils.formatCountdown(3 * 86400 + 5, nil, "es-es")) --> 3 días 0:00:05
Show raw api
{
    "functions": [
        {
            "name": "formatCountdown",
            "desc": "Formats a number of seconds as countdown text, showing only as many units as the remaining\ntime needs: `45`, then `3:05`, then `1:02:03`, and `2 days 1:02:03` for longer waits. Each unit\ncounts up to a round number before the next is used, so a one minute countdown starts at `60`,\na one hour countdown at `60:00`, and a single day rolls into the hours as `47:15:00`.\nThe `days` word is localized through [TimeDurationUtils.format]; `locale` defaults to English.\nFractional seconds are truncated.\n\n```lua\nprint(CountdownTextUtils.formatCountdown(0, \"Now!\")) --> Now!\nprint(CountdownTextUtils.formatCountdown(185)) --> 3:05\nprint(CountdownTextUtils.formatCountdown(3 * 86400 + 5, nil, \"es-es\")) --> 3 días 0:00:05\n```",
            "params": [
                {
                    "name": "seconds",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "whenAtZeroText",
                    "desc": "",
                    "lua_type": "string?"
                },
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 28,
                "path": "src/countdowntext/src/Shared/CountdownTextUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "CountdownTextUtils",
    "desc": "Utility functions to format countdowns in-game, built on [TimeDurationUtils].",
    "source": {
        "line": 7,
        "path": "src/countdowntext/src/Shared/CountdownTextUtils.lua"
    }
}