2015-11-30 18:11:04 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-10-18 01:54:10 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-11-30 18:11:04 +00:00
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2015-11-30 18:11:04 +00:00
|
|
|
*/
|
|
|
|
|
2023-04-20 08:49:10 +00:00
|
|
|
import { Optional } from "matrix-events-sdk";
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
import { _t, getUserLanguage } from "./languageHandler";
|
2024-09-02 09:07:07 +00:00
|
|
|
import { getUserTimezone } from "./TimezoneHandler";
|
2015-11-30 18:11:04 +00:00
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
export const MINUTE_MS = 60000;
|
|
|
|
export const HOUR_MS = MINUTE_MS * 60;
|
|
|
|
export const DAY_MS = HOUR_MS * 24;
|
2017-05-23 14:16:31 +00:00
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Returns array of 7 weekday names, from Sunday to Saturday, internationalised to the user's language.
|
|
|
|
* @param weekday - format desired "short" | "long" | "narrow"
|
|
|
|
*/
|
|
|
|
export function getDaysArray(weekday: Intl.DateTimeFormatOptions["weekday"] = "short"): string[] {
|
|
|
|
const sunday = 1672574400000; // 2023-01-01 12:00 UTC
|
|
|
|
const { format } = new Intl.DateTimeFormat(getUserLanguage(), { weekday, timeZone: "UTC" });
|
|
|
|
return [...Array(7).keys()].map((day) => format(sunday + day * DAY_MS));
|
2017-05-23 14:16:31 +00:00
|
|
|
}
|
2015-11-30 18:11:04 +00:00
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Returns array of 12 month names, from January to December, internationalised to the user's language.
|
|
|
|
* @param month - format desired "numeric" | "2-digit" | "long" | "short" | "narrow"
|
|
|
|
*/
|
|
|
|
export function getMonthsArray(month: Intl.DateTimeFormatOptions["month"] = "short"): string[] {
|
|
|
|
const { format } = new Intl.DateTimeFormat(getUserLanguage(), { month, timeZone: "UTC" });
|
|
|
|
return [...Array(12).keys()].map((m) => format(Date.UTC(2021, m)));
|
2017-05-14 23:25:12 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
// XXX: Ideally we could just specify `hour12: boolean` but it has issues on Chrome in the `en` locale
|
|
|
|
// https://support.google.com/chrome/thread/29828561?hl=en
|
|
|
|
function getTwelveHourOptions(showTwelveHour: boolean): Intl.DateTimeFormatOptions {
|
|
|
|
return {
|
|
|
|
hourCycle: showTwelveHour ? "h12" : "h23",
|
|
|
|
};
|
2017-05-18 21:00:44 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Formats a given date to a date & time string.
|
|
|
|
*
|
|
|
|
* The output format depends on how far away the given date is from now.
|
|
|
|
* Will use the browser's default time zone.
|
|
|
|
* If the date is today it will return a time string excluding seconds. See {@formatTime}.
|
|
|
|
* If the date is within the last 6 days it will return the name of the weekday along with the time string excluding seconds.
|
|
|
|
* If the date is within the same year then it will return the weekday, month and day of the month along with the time string excluding seconds.
|
|
|
|
* Otherwise, it will return a string representing the full date & time in a human friendly manner. See {@formatFullDate}.
|
|
|
|
* @param date - date object to format
|
|
|
|
* @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode).
|
|
|
|
* Overrides the default from the locale, whether `true` or `false`.
|
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
|
|
|
*/
|
|
|
|
export function formatDate(date: Date, showTwelveHour = false, locale?: string): string {
|
|
|
|
const _locale = locale ?? getUserLanguage();
|
2018-01-10 12:00:11 +00:00
|
|
|
const now = new Date();
|
|
|
|
if (date.toDateString() === now.toDateString()) {
|
2023-08-21 19:38:59 +00:00
|
|
|
return formatTime(date, showTwelveHour, _locale);
|
|
|
|
} else if (now.getTime() - date.getTime() < 6 * DAY_MS) {
|
|
|
|
// Time is within the last 6 days (or in the future)
|
|
|
|
return new Intl.DateTimeFormat(_locale, {
|
|
|
|
...getTwelveHourOptions(showTwelveHour),
|
|
|
|
weekday: "short",
|
|
|
|
hour: "numeric",
|
|
|
|
minute: "2-digit",
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2018-01-10 12:00:11 +00:00
|
|
|
} else if (now.getFullYear() === date.getFullYear()) {
|
2023-08-21 19:38:59 +00:00
|
|
|
return new Intl.DateTimeFormat(_locale, {
|
|
|
|
...getTwelveHourOptions(showTwelveHour),
|
|
|
|
weekday: "short",
|
|
|
|
month: "short",
|
|
|
|
day: "numeric",
|
|
|
|
hour: "numeric",
|
|
|
|
minute: "2-digit",
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2018-01-10 12:00:11 +00:00
|
|
|
}
|
2023-08-21 19:38:59 +00:00
|
|
|
return formatFullDate(date, showTwelveHour, false, _locale);
|
2018-01-10 12:00:11 +00:00
|
|
|
}
|
2016-08-16 14:01:01 +00:00
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Formats a given date to a human-friendly string with short weekday.
|
|
|
|
* Will use the browser's default time zone.
|
|
|
|
* @example "Thu, 17 Nov 2022" in en-GB locale
|
|
|
|
* @param date - date object to format
|
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
|
|
|
*/
|
|
|
|
export function formatFullDateNoTime(date: Date, locale?: string): string {
|
|
|
|
return new Intl.DateTimeFormat(locale ?? getUserLanguage(), {
|
|
|
|
weekday: "short",
|
|
|
|
month: "short",
|
|
|
|
day: "numeric",
|
|
|
|
year: "numeric",
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2018-01-14 18:32:17 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Formats a given date to a date & time string, optionally including seconds.
|
|
|
|
* Will use the browser's default time zone.
|
|
|
|
* @example "Thu, 17 Nov 2022, 4:58:32 pm" in en-GB locale with showTwelveHour=true and showSeconds=true
|
|
|
|
* @param date - date object to format
|
|
|
|
* @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode).
|
|
|
|
* Overrides the default from the locale, whether `true` or `false`.
|
|
|
|
* @param showSeconds - whether to include seconds in the time portion of the string
|
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
|
|
|
*/
|
|
|
|
export function formatFullDate(date: Date, showTwelveHour = false, showSeconds = true, locale?: string): string {
|
|
|
|
return new Intl.DateTimeFormat(locale ?? getUserLanguage(), {
|
|
|
|
...getTwelveHourOptions(showTwelveHour),
|
|
|
|
weekday: "short",
|
|
|
|
month: "short",
|
|
|
|
day: "numeric",
|
|
|
|
year: "numeric",
|
|
|
|
hour: "numeric",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: showSeconds ? "2-digit" : undefined,
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2018-01-10 12:00:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 16:45:44 +00:00
|
|
|
/**
|
|
|
|
* Formats dates to be compatible with attributes of a `<input type="date">`. Dates
|
2023-08-21 19:38:59 +00:00
|
|
|
* should be formatted like "2020-06-23" (formatted according to ISO8601).
|
2023-03-22 16:45:44 +00:00
|
|
|
*
|
|
|
|
* @param date The date to format.
|
|
|
|
* @returns The date string in ISO8601 format ready to be used with an `<input>`
|
|
|
|
*/
|
|
|
|
export function formatDateForInput(date: Date): string {
|
|
|
|
const year = `${date.getFullYear()}`.padStart(4, "0");
|
|
|
|
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
|
|
|
const day = `${date.getDate()}`.padStart(2, "0");
|
2023-08-21 19:38:59 +00:00
|
|
|
return `${year}-${month}-${day}`;
|
2023-03-22 16:45:44 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Formats a given date to a time string including seconds.
|
|
|
|
* Will use the browser's default time zone.
|
|
|
|
* @example "4:58:32 PM" in en-GB locale with showTwelveHour=true
|
|
|
|
* @example "16:58:32" in en-GB locale with showTwelveHour=false
|
|
|
|
* @param date - date object to format
|
|
|
|
* @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode).
|
|
|
|
* Overrides the default from the locale, whether `true` or `false`.
|
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
|
|
|
*/
|
|
|
|
export function formatFullTime(date: Date, showTwelveHour = false, locale?: string): string {
|
|
|
|
return new Intl.DateTimeFormat(locale ?? getUserLanguage(), {
|
|
|
|
...getTwelveHourOptions(showTwelveHour),
|
|
|
|
hour: "numeric",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit",
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2018-02-08 15:58:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Formats a given date to a time string excluding seconds.
|
|
|
|
* Will use the browser's default time zone.
|
|
|
|
* @example "4:58 PM" in en-GB locale with showTwelveHour=true
|
|
|
|
* @example "16:58" in en-GB locale with showTwelveHour=false
|
|
|
|
* @param date - date object to format
|
|
|
|
* @param showTwelveHour - whether to use 12-hour rather than 24-hour time. Defaults to `false` (24 hour mode).
|
|
|
|
* Overrides the default from the locale, whether `true` or `false`.
|
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
|
|
|
*/
|
|
|
|
export function formatTime(date: Date, showTwelveHour = false, locale?: string): string {
|
|
|
|
return new Intl.DateTimeFormat(locale ?? getUserLanguage(), {
|
|
|
|
...getTwelveHourOptions(showTwelveHour),
|
|
|
|
hour: "numeric",
|
|
|
|
minute: "2-digit",
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2018-01-10 12:00:11 +00:00
|
|
|
}
|
2018-01-10 12:06:24 +00:00
|
|
|
|
2021-08-27 14:19:59 +00:00
|
|
|
export function formatSeconds(inSeconds: number): string {
|
2022-11-30 07:47:29 +00:00
|
|
|
const isNegative = inSeconds < 0;
|
|
|
|
inSeconds = Math.abs(inSeconds);
|
|
|
|
|
2021-08-27 14:19:59 +00:00
|
|
|
const hours = Math.floor(inSeconds / (60 * 60))
|
|
|
|
.toFixed(0)
|
|
|
|
.padStart(2, "0");
|
|
|
|
const minutes = Math.floor((inSeconds % (60 * 60)) / 60)
|
|
|
|
.toFixed(0)
|
|
|
|
.padStart(2, "0");
|
|
|
|
const seconds = Math.floor((inSeconds % (60 * 60)) % 60)
|
|
|
|
.toFixed(0)
|
|
|
|
.padStart(2, "0");
|
|
|
|
|
|
|
|
let output = "";
|
|
|
|
if (hours !== "00") output += `${hours}:`;
|
|
|
|
output += `${minutes}:${seconds}`;
|
|
|
|
|
2022-11-30 07:47:29 +00:00
|
|
|
if (isNegative) {
|
|
|
|
output = "-" + output;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:19:59 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2022-11-10 10:53:49 +00:00
|
|
|
export function formatTimeLeft(inSeconds: number): string {
|
|
|
|
const hours = Math.floor(inSeconds / (60 * 60)).toFixed(0);
|
|
|
|
const minutes = Math.floor((inSeconds % (60 * 60)) / 60).toFixed(0);
|
|
|
|
const seconds = Math.floor((inSeconds % (60 * 60)) % 60).toFixed(0);
|
|
|
|
|
|
|
|
if (hours !== "0") {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|hours_minutes_seconds_left", {
|
2022-11-10 10:53:49 +00:00
|
|
|
hours,
|
|
|
|
minutes,
|
|
|
|
seconds,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minutes !== "0") {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|minutes_seconds_left", {
|
2022-11-10 10:53:49 +00:00
|
|
|
minutes,
|
|
|
|
seconds,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|seconds_left", {
|
2022-11-10 10:53:49 +00:00
|
|
|
seconds,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:16:50 +00:00
|
|
|
function withinPast24Hours(prevDate: Date, nextDate: Date): boolean {
|
2023-08-21 19:38:59 +00:00
|
|
|
return Math.abs(prevDate.getTime() - nextDate.getTime()) <= DAY_MS;
|
2021-11-03 10:16:50 +00:00
|
|
|
}
|
|
|
|
|
2023-03-27 20:22:46 +00:00
|
|
|
function withinCurrentDay(prevDate: Date, nextDate: Date): boolean {
|
|
|
|
return withinPast24Hours(prevDate, nextDate) && prevDate.getDay() === nextDate.getDay();
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:16:50 +00:00
|
|
|
function withinCurrentYear(prevDate: Date, nextDate: Date): boolean {
|
|
|
|
return prevDate.getFullYear() === nextDate.getFullYear();
|
|
|
|
}
|
|
|
|
|
2023-04-20 08:49:10 +00:00
|
|
|
export function wantsDateSeparator(prevEventDate: Optional<Date>, nextEventDate: Optional<Date>): boolean {
|
2018-01-10 12:06:24 +00:00
|
|
|
if (!nextEventDate || !prevEventDate) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Return early for events that are > 24h apart
|
2021-11-03 10:16:50 +00:00
|
|
|
if (!withinPast24Hours(prevEventDate, nextEventDate)) {
|
2018-01-10 12:06:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare weekdays
|
|
|
|
return prevEventDate.getDay() !== nextEventDate.getDay();
|
|
|
|
}
|
2021-06-01 07:10:03 +00:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
export function formatFullDateNoDay(date: Date): string {
|
2023-08-21 19:38:59 +00:00
|
|
|
const locale = getUserLanguage();
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|date_at_time", {
|
2023-08-21 19:38:59 +00:00
|
|
|
date: date.toLocaleDateString(locale).replace(/\//g, "-"),
|
|
|
|
time: date.toLocaleTimeString(locale).replace(/:/g, "-"),
|
2021-06-09 10:42:57 +00:00
|
|
|
});
|
2021-06-01 07:10:03 +00:00
|
|
|
}
|
2021-06-03 07:10:00 +00:00
|
|
|
|
2022-10-18 01:54:10 +00:00
|
|
|
/**
|
2023-08-21 19:38:59 +00:00
|
|
|
* Returns an ISO date string without textual description of the date (ie: no "Wednesday" or similar)
|
2022-10-18 01:54:10 +00:00
|
|
|
* @param date The date to format.
|
|
|
|
* @returns The date string in ISO format.
|
|
|
|
*/
|
|
|
|
export function formatFullDateNoDayISO(date: Date): string {
|
|
|
|
return date.toISOString();
|
|
|
|
}
|
|
|
|
|
2023-08-21 19:38:59 +00:00
|
|
|
/**
|
|
|
|
* Formats a given date to a string.
|
|
|
|
* Will use the browser's default time zone.
|
|
|
|
* @example 17/11/2022 in en-GB locale
|
|
|
|
* @param date - date object to format
|
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
|
|
|
*/
|
|
|
|
export function formatFullDateNoDayNoTime(date: Date, locale?: string): string {
|
|
|
|
return new Intl.DateTimeFormat(locale ?? getUserLanguage(), {
|
|
|
|
year: "numeric",
|
|
|
|
month: "numeric",
|
|
|
|
day: "numeric",
|
2024-09-02 09:07:07 +00:00
|
|
|
timeZone: getUserTimezone(),
|
2023-08-21 19:38:59 +00:00
|
|
|
}).format(date);
|
2021-06-03 07:10:00 +00:00
|
|
|
}
|
2021-11-03 10:16:50 +00:00
|
|
|
|
|
|
|
export function formatRelativeTime(date: Date, showTwelveHour = false): string {
|
2023-08-21 19:38:59 +00:00
|
|
|
const now = new Date();
|
2023-03-27 20:22:46 +00:00
|
|
|
if (withinCurrentDay(date, now)) {
|
2021-11-03 10:16:50 +00:00
|
|
|
return formatTime(date, showTwelveHour);
|
|
|
|
} else {
|
|
|
|
const months = getMonthsArray();
|
|
|
|
let relativeDate = `${months[date.getMonth()]} ${date.getDate()}`;
|
|
|
|
|
|
|
|
if (!withinCurrentYear(date, now)) {
|
|
|
|
relativeDate += `, ${date.getFullYear()}`;
|
|
|
|
}
|
|
|
|
return relativeDate;
|
|
|
|
}
|
|
|
|
}
|
2022-03-21 11:42:58 +00:00
|
|
|
|
|
|
|
/**
|
2023-08-21 19:38:59 +00:00
|
|
|
* Formats duration in ms to human-readable string
|
|
|
|
* Returns value in the biggest possible unit (day, hour, min, second)
|
2022-03-21 11:42:58 +00:00
|
|
|
* Rounds values up until unit threshold
|
2023-08-21 19:38:59 +00:00
|
|
|
* i.e. 23:13:57 -> 23h, 24:13:57 -> 1d, 44:56:56 -> 2d
|
2022-03-21 11:42:58 +00:00
|
|
|
*/
|
|
|
|
export function formatDuration(durationMs: number): string {
|
|
|
|
if (durationMs >= DAY_MS) {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_days", { value: Math.round(durationMs / DAY_MS) });
|
2022-03-21 11:42:58 +00:00
|
|
|
}
|
|
|
|
if (durationMs >= HOUR_MS) {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_hours", { value: Math.round(durationMs / HOUR_MS) });
|
2022-03-21 11:42:58 +00:00
|
|
|
}
|
|
|
|
if (durationMs >= MINUTE_MS) {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_minutes", { value: Math.round(durationMs / MINUTE_MS) });
|
2022-03-21 11:42:58 +00:00
|
|
|
}
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_seconds", { value: Math.round(durationMs / 1000) });
|
2022-03-21 11:42:58 +00:00
|
|
|
}
|
2022-11-29 21:21:51 +00:00
|
|
|
|
|
|
|
/**
|
2023-08-21 19:38:59 +00:00
|
|
|
* Formats duration in ms to human-readable string
|
2022-11-29 21:21:51 +00:00
|
|
|
* Returns precise value down to the nearest second
|
2023-08-21 19:38:59 +00:00
|
|
|
* i.e. 23:13:57 -> 23h 13m 57s, 44:56:56 -> 1d 20h 56m 56s
|
2022-11-29 21:21:51 +00:00
|
|
|
*/
|
|
|
|
export function formatPreciseDuration(durationMs: number): string {
|
|
|
|
const days = Math.floor(durationMs / DAY_MS);
|
|
|
|
const hours = Math.floor((durationMs % DAY_MS) / HOUR_MS);
|
|
|
|
const minutes = Math.floor((durationMs % HOUR_MS) / MINUTE_MS);
|
|
|
|
const seconds = Math.floor((durationMs % MINUTE_MS) / 1000);
|
|
|
|
|
|
|
|
if (days > 0) {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_days_hours_minutes_seconds", { days, hours, minutes, seconds });
|
2022-11-29 21:21:51 +00:00
|
|
|
}
|
|
|
|
if (hours > 0) {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_hours_minutes_seconds", { hours, minutes, seconds });
|
2022-11-29 21:21:51 +00:00
|
|
|
}
|
|
|
|
if (minutes > 0) {
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_minutes_seconds", { minutes, seconds });
|
2022-11-29 21:21:51 +00:00
|
|
|
}
|
Port more strings to translation keys (#11474)
* Port composer formatting strings to translation keys
```
replace "Bold" "composer|format_bold"
replace "Italic" "composer|format_italic"
replace "Underline" "composer|format_underline"
replace "Strikethrough" "composer|format_strikethrough"
replace "Bulleted list" "composer|format_unordered_list"
replace "Numbered list" "composer|format_ordered_list"
replace "Indent increase" "composer|format_increase_indent"
replace "Indent decrease" "composer|format_decrease_indent"
replace "Code" "composer|format_inline_code"
replace "Code block" "composer|format_code_block"
replace "Link" "composer|format_link"
copy "composer|format_bold" "Bold"
copy "composer|format_link" "Link"
copy "composer|format_inline_code" "Code"
```
* Port role strings to translation keys
```
copy "Default" "power_level|default"
copy "Restricted" "power_level|restricted"
copy "Moderator" "power_level|moderator"
copy "Admin" "power_level|admin"
```
* Port bug reporting strings to translation keys
```
replace "If you've submitted a bug via GitHub, debug logs can help us track down the problem. " "bug_reporting|introduction"
replace "Debug logs contain application usage data including your username, the IDs or aliases of the rooms you have visited, which UI elements you last interacted with, and the usernames of other users. They do not contain messages." "bug_reporting|description"
copy "To report a Matrix-related security issue, please read the Matrix.org <a>Security Disclosure Policy</a>." "bug_reporting|matrix_security_issue"
replace "Submit debug logs" "bug_reporting|submit_debug_logs"
replace "Bug reporting" "bug_reporting|title"
replace "If there is additional context that would help in analysing the issue, such as what you were doing at the time, room IDs, user IDs, etc., please include those things here." "bug_reporting|additional_context"
replace "Send logs" "bug_reporting|send_logs"
replace "GitHub issue" "bug_reporting|github_issue"
replace "Download logs" "bug_reporting|download_logs"
copy "Before submitting logs, you must <a>create a GitHub issue</a> to describe your problem." "bug_reporting|before_submitting"
```
* i18n
* Port time duration strings to translation keys
```
replace "%(hours)sh %(minutes)sm %(seconds)ss left" "time|hours_minutes_seconds_left"
replace "%(minutes)sm %(seconds)ss left" "time|minutes_seconds_left"
replace "%(seconds)ss left" "time|seconds_left"
replace "%(date)s at %(time)s" "time|date_at_time"
replace "%(value)sd" "time|short_days"
replace "%(value)sh" "time|short_hours"
replace "%(value)sm" "time|short_minutes"
replace "%(value)ss" "time|short_seconds"
replace "%(days)sd %(hours)sh %(minutes)sm %(seconds)ss" "time|short_days_hours_minutes_seconds"
replace "%(hours)sh %(minutes)sm %(seconds)ss" "time|short_hours_minutes_seconds"
replace "%(minutes)sm %(seconds)ss" "time|short_minutes_seconds"
```
* i18n
2023-08-31 07:35:34 +00:00
|
|
|
return _t("time|short_seconds", { value: seconds });
|
2022-11-29 21:21:51 +00:00
|
|
|
}
|
2023-02-02 21:39:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a timestamp to a short date
|
2023-08-21 19:38:59 +00:00
|
|
|
* Similar to {@formatFullDateNoDayNoTime} but with 2-digit on day, month, year.
|
|
|
|
* @example 25/12/22 in en-GB locale
|
2023-02-02 21:39:23 +00:00
|
|
|
* @param timestamp - epoch timestamp
|
2023-08-21 19:38:59 +00:00
|
|
|
* @param locale - the locale string to use, in BCP 47 format, defaulting to user's selected application locale
|
2023-02-02 21:39:23 +00:00
|
|
|
* @returns {string} formattedDate
|
|
|
|
*/
|
2023-08-21 19:38:59 +00:00
|
|
|
export const formatLocalDateShort = (timestamp: number, locale?: string): string =>
|
2024-09-02 09:07:07 +00:00
|
|
|
new Intl.DateTimeFormat(locale ?? getUserLanguage(), {
|
|
|
|
day: "2-digit",
|
|
|
|
month: "2-digit",
|
|
|
|
year: "2-digit",
|
|
|
|
timeZone: getUserTimezone(),
|
|
|
|
}).format(timestamp);
|