Skip to main content

TimeLocalizationUtils

Locale strings for TimeCalendarUtils, RelativeTimeUtils and TimeDurationUtils, covering the same locales as NumberLocalizationUtils. Lookups resolve through ResolveLocaleUtils, so en-gb lands on English and es-mx on Spanish, and an unknown locale falls back to English with a warning.

To add a locale, add one entry to LOCALES. Every field is required, so a missing phrase is a type error rather than a runtime surprise.

Types

CalendarFormat

type CalendarFormat = string | (
dateTimeDateTime,
referenceTimeDateTime
) → string

A Time.format template, or a function given the time and the reference time that returns the finished text.

CalendarFormats

interface CalendarFormats {
sameDayCalendarFormat
nextDayCalendarFormat
nextWeekCalendarFormat
lastDayCalendarFormat
lastWeekCalendarFormat
sameElseCalendarFormat
}

The phrase TimeCalendarUtils.calendar uses for each distance from the reference day.

CalendarFormatOverrides

type CalendarFormatOverrides = {
sameDayCalendarFormat?,
nextDayCalendarFormat?,
nextWeekCalendarFormat?,
lastDayCalendarFormat?,
lastWeekCalendarFormat?,
sameElseCalendarFormat?
}

A partial CalendarFormats a caller passes to override a locale's phrases.

RelativeTimeString

type RelativeTimeString = string | (
amountnumber,
withoutSuffixboolean,
keystring,
isFutureboolean
) → string

A relative time string with %d for the amount, or a function given the amount, whether a suffix will be added, the threshold key and whether the time is in the future, for languages that inflect.

RelativeTimeStrings

Relative time strings for every threshold key. future and past take %s.

RelativeTimeStringOverrides

type RelativeTimeStringOverrides = {[string]RelativeTimeString}

Relative time strings a caller passes to override or extend a locale's, keyed by threshold key. Custom thresholds may add their own keys here.

DurationPhrase

type DurationPhrase = {
onestring,
otherstring
} | (amountnumber) → string

A duration phrase with %d for the amount: a singular and plural pair, or a function of the amount for languages with more plural forms.

DurationStrings

interface DurationStrings {
minutesDurationPhrase
secondsDurationPhrase
millisecondsDurationPhrase
}

Duration phrases for every breakdown field.

DurationStringOverrides

type DurationStringOverrides = {[string]DurationPhrase}

Duration phrases a caller passes to override a locale's, keyed by breakdown field.

TimeLocale

interface TimeLocale {
calendarCalendarFormats
relativeTimeRelativeTimeStrings
durationDurationStrings
}

Everything one locale needs.

Functions

getLocale

TimeLocalizationUtils.getLocale(localestring?) → TimeLocale

Returns the read-only TimeLocale for a locale, defaulting to English.

getCalendarFormatsForLocale

TimeLocalizationUtils.getCalendarFormatsForLocale(localestring?) → CalendarFormats

Returns the read-only CalendarFormats for a locale, defaulting to English.

getRelativeTimeStringsForLocale

TimeLocalizationUtils.getRelativeTimeStringsForLocale(localestring?) → RelativeTimeStrings

Returns the read-only RelativeTimeStrings for a locale, defaulting to English.

getDurationStringsForLocale

TimeLocalizationUtils.getDurationStringsForLocale(localestring?) → DurationStrings

Returns the read-only DurationStrings for a locale, defaulting to English.

Show raw api
{
    "functions": [
        {
            "name": "getLocale",
            "desc": "Returns the read-only [TimeLocale] for a locale, defaulting to English.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "TimeLocale\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 927,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "getCalendarFormatsForLocale",
            "desc": "Returns the read-only [CalendarFormats] for a locale, defaulting to English.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "CalendarFormats\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 946,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "getRelativeTimeStringsForLocale",
            "desc": "Returns the read-only [RelativeTimeStrings] for a locale, defaulting to English.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "RelativeTimeStrings\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 953,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "getDurationStringsForLocale",
            "desc": "Returns the read-only [DurationStrings] for a locale, defaulting to English.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DurationStrings\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 960,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "CalendarFormat",
            "desc": "A [Time.format] template, or a function given the time and the reference time that returns\nthe finished text.",
            "lua_type": "string | (dateTime: DateTime, referenceTime: DateTime) -> string",
            "source": {
                "line": 29,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "CalendarFormats",
            "desc": "The phrase [TimeCalendarUtils.calendar] uses for each distance from the reference day.",
            "fields": [
                {
                    "name": "sameDay",
                    "lua_type": "CalendarFormat",
                    "desc": ""
                },
                {
                    "name": "nextDay",
                    "lua_type": "CalendarFormat",
                    "desc": ""
                },
                {
                    "name": "nextWeek",
                    "lua_type": "CalendarFormat",
                    "desc": ""
                },
                {
                    "name": "lastDay",
                    "lua_type": "CalendarFormat",
                    "desc": ""
                },
                {
                    "name": "lastWeek",
                    "lua_type": "CalendarFormat",
                    "desc": ""
                },
                {
                    "name": "sameElse",
                    "lua_type": "CalendarFormat",
                    "desc": ""
                }
            ],
            "source": {
                "line": 43,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "CalendarFormatOverrides",
            "desc": "A partial [CalendarFormats] a caller passes to override a locale's phrases.",
            "lua_type": "{ sameDay: CalendarFormat?, nextDay: CalendarFormat?, nextWeek: CalendarFormat?, lastDay: CalendarFormat?, lastWeek: CalendarFormat?, sameElse: CalendarFormat? }",
            "source": {
                "line": 58,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "RelativeTimeString",
            "desc": "A relative time string with `%d` for the amount, or a function given the\namount, whether a suffix will be added, the threshold key and whether the time is in the\nfuture, for languages that inflect.",
            "lua_type": "string | (amount: number, withoutSuffix: boolean, key: string, isFuture: boolean) -> string",
            "source": {
                "line": 75,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "RelativeTimeStrings",
            "desc": "Relative time strings for every threshold key. `future` and `past` take `%s`.",
            "fields": [
                {
                    "name": "future",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "past",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "s",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "m",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "mm",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "h",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "hh",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "d",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "dd",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "M",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "MM",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "y",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                },
                {
                    "name": "yy",
                    "lua_type": "RelativeTimeString",
                    "desc": ""
                }
            ],
            "source": {
                "line": 96,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "RelativeTimeStringOverrides",
            "desc": "Relative time strings a caller passes to override or extend a locale's, keyed by threshold\nkey. Custom thresholds may add their own keys here.",
            "lua_type": "{ [string]: RelativeTimeString }",
            "source": {
                "line": 119,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "DurationPhrase",
            "desc": "A duration phrase with `%d` for the amount: a singular and plural pair, or a function of the\namount for languages with more plural forms.",
            "lua_type": "{ one: string, other: string } | (amount: number) -> string",
            "source": {
                "line": 128,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "DurationStrings",
            "desc": "Duration phrases for every breakdown field.",
            "fields": [
                {
                    "name": "years",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "months",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "weeks",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "days",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "hours",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "minutes",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "seconds",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                },
                {
                    "name": "milliseconds",
                    "lua_type": "DurationPhrase",
                    "desc": ""
                }
            ],
            "source": {
                "line": 144,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "DurationStringOverrides",
            "desc": "Duration phrases a caller passes to override a locale's, keyed by breakdown field.",
            "lua_type": "{ [string]: DurationPhrase }",
            "source": {
                "line": 161,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        },
        {
            "name": "TimeLocale",
            "desc": "Everything one locale needs.",
            "fields": [
                {
                    "name": "calendar",
                    "lua_type": "CalendarFormats",
                    "desc": ""
                },
                {
                    "name": "relativeTime",
                    "lua_type": "RelativeTimeStrings",
                    "desc": ""
                },
                {
                    "name": "duration",
                    "lua_type": "DurationStrings",
                    "desc": ""
                }
            ],
            "source": {
                "line": 172,
                "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
            }
        }
    ],
    "name": "TimeLocalizationUtils",
    "desc": "Locale strings for [TimeCalendarUtils], [RelativeTimeUtils] and [TimeDurationUtils], covering\nthe same locales as [NumberLocalizationUtils]. Lookups resolve through [ResolveLocaleUtils],\nso `en-gb` lands on English and `es-mx` on Spanish, and an unknown locale falls back to English\nwith a warning.\n\nTo add a locale, add one entry to `LOCALES`. Every field is required, so a missing phrase is a\ntype error rather than a runtime surprise.",
    "source": {
        "line": 13,
        "path": "src/time/src/Shared/TimeLocalizationUtils.lua"
    }
}