Repository: louislam/uptime-kuma
File: src/util-frontend.js (JavaScript)

Code before:
 * Get timeout for error toasts
 * @returns {(number|boolean)} Timeout in ms. If false timeout disabled.
 */
export function getToastErrorTimeout() {
    let errorTimeout = -1;

    if (localStorage.toastErrorTimeout !== undefined) {
        const parsedTimeout = parseInt(localStorage.toastErrorTimeout);
        if (parsedTimeout != null && !Number.isNaN(parsedTimeout)) {
            errorTimeout = parsedTimeout;
        }
    }

    if (errorTimeout === -1) {
        errorTimeout = false;
    }

    return errorTimeout;
}

class TimeDurationFormatter {
    /**
     * Default locale and options for Time Duration Formatter (supports both DurationFormat and RelativeTimeFormat)
     */
    constructor() {
        this.durationFormatOptions = { style: "short" };
        this.relativeTimeFormatOptions = { numeric: "always" };
        if (Intl.DurationFormat !== undefined) {
            this.durationFormatInstance = new Intl.DurationFormat(currentLocale(), this.durationFormatOptions);
        } else {
            this.relativeTimeFormatInstance = new Intl.RelativeTimeFormat(currentLocale(), this.relativeTimeFormatOptions);
        }
    }

    /**
     * Method to update the instance locale and options
     * @param {string} locale Localization identifier (e.g., "en", "ar-sy") to update the instance with.
     * @returns {void} No return value.
     */
    updateLocale(locale) {
        if (Intl.DurationFormat !== undefined) {
            this.durationFormatInstance = new Intl.DurationFormat(locale, this.durationFormatOptions);
        } else {
            this.relativeTimeFormatInstance = new Intl.RelativeTimeFormat(locale, this.relativeTimeFormatOptions);
        }
    }

    /**
     * Method to convert seconds into Human readable format
     * @param {number} seconds Receive value in seconds.
     * @returns {string} String converted to Days Mins Seconds Format

Review comment (suggestion):
I think short is a bit akward and `long` provides a bit better message (particularly the german version is quite unnatural in `short`)

The size diff should not matter for the UI here.

```js
let f = new Intl.DurationFormat("en", {style: "long"})
f.format({days:6023, hours:1, minutes:2, seconds: 2}) // 6,023 days, 1 hour, 2 minutes, 2 seconds
f = new Intl.DurationFormat("en", {style: "short"})
f.format({days:6023, hours:1, minutes:2, seconds: 2}) // 6,023 days, 1 hr, 2 min, 2 sec
```

```suggestion
        this.durationFormatOptions = { style: "long" };
```

Code after:
 * Get timeout for error toasts
 * @returns {(number|boolean)} Timeout in ms. If false timeout disabled.
 */
export function getToastErrorTimeout() {
    let errorTimeout = -1;

    if (localStorage.toastErrorTimeout !== undefined) {
        const parsedTimeout = parseInt(localStorage.toastErrorTimeout);
        if (parsedTimeout != null && !Number.isNaN(parsedTimeout)) {
            errorTimeout = parsedTimeout;
        }
    }

    if (errorTimeout === -1) {
        errorTimeout = false;
    }

    return errorTimeout;
}

class TimeDurationFormatter {
    /**
     * Default locale and options for Time Duration Formatter (supports both DurationFormat and RelativeTimeFormat)
     */
    constructor() {
        this.durationFormatOptions = { style: "long" };
        this.relativeTimeFormatOptions = { numeric: "always" };
        if (Intl.DurationFormat !== undefined) {
            this.durationFormatInstance = new Intl.DurationFormat(currentLocale(), this.durationFormatOptions);
        } else {
            this.relativeTimeFormatInstance = new Intl.RelativeTimeFormat(currentLocale(), this.relativeTimeFormatOptions);
        }
    }

    /**
     * Method to update the instance locale and options
     * @param {string} locale Localization identifier (e.g., "en", "ar-sy") to update the instance with.
     * @returns {void} No return value.
     */
    updateLocale(locale) {
        if (Intl.DurationFormat !== undefined) {
            this.durationFormatInstance = new Intl.DurationFormat(locale, this.durationFormatOptions);
        } else {
            this.relativeTimeFormatInstance = new Intl.RelativeTimeFormat(locale, this.relativeTimeFormatOptions);
        }
    }

    /**
     * Method to convert seconds into Human readable format
     * @param {number} seconds Receive value in seconds.
     * @returns {string} String converted to Days Mins Seconds Format