timerender: Extract new variant of get_full_datetime.

Separating these concepts allows us to provide a much nicer format for
contexts where ultra-specific clarification is not a priority.

This new variant is currently only used in the scheduled messages UI.
This commit is contained in:
Tim Abbott
2023-04-30 22:02:10 -07:00
parent 341f3a1ce2
commit 6fe02e933a
6 changed files with 28 additions and 6 deletions

View File

@@ -446,6 +446,18 @@ export function absolute_time(timestamp: number, today = new Date()): string {
// Pass time_format="time" to not include seconds in the time format.
export function get_full_datetime(time: Date, time_format: TimeFormat = "time_sec"): string {
const date_string = get_localized_date_or_time_for_format(time, "dayofyear_year");
const time_string = get_localized_date_or_time_for_format(time, time_format);
return $t({defaultMessage: "{date} at {time}"}, {date: date_string, time: time_string});
}
// Preferred variant for displaying a full datetime to users in
// contexts like tooltips, where the time was already displayed to the
// user in a less precise format.
export function get_full_datetime_clarification(
time: Date,
time_format: TimeFormat = "time_sec",
): string {
const locale = get_user_locale();
const date_string = time.toLocaleDateString(locale);
let time_string = get_localized_date_or_time_for_format(time, time_format);