mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 05:35:04 +08:00
Add seconds to formatFullDate()
Fixes vector-im/riot-web#6055 Signed-off-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
parent
754b7fbad5
commit
7a594ce08d
@ -50,11 +50,15 @@ function pad(n) {
|
|||||||
return (n < 10 ? '0' : '') + n;
|
return (n < 10 ? '0' : '') + n;
|
||||||
}
|
}
|
||||||
|
|
||||||
function twelveHourTime(date) {
|
function twelveHourTime(date, showSeconds=false) {
|
||||||
let hours = date.getHours() % 12;
|
let hours = date.getHours() % 12;
|
||||||
const minutes = pad(date.getMinutes());
|
const minutes = pad(date.getMinutes());
|
||||||
const ampm = date.getHours() >= 12 ? _t('PM') : _t('AM');
|
const ampm = date.getHours() >= 12 ? _t('PM') : _t('AM');
|
||||||
hours = hours ? hours : 12; // convert 0 -> 12
|
hours = hours ? hours : 12; // convert 0 -> 12
|
||||||
|
if (showSeconds) {
|
||||||
|
const seconds = pad(date.getSeconds());
|
||||||
|
return `${hours}:${minutes}:${seconds}${ampm}`;
|
||||||
|
}
|
||||||
return `${hours}:${minutes}${ampm}`;
|
return `${hours}:${minutes}${ampm}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,10 +105,17 @@ export function formatFullDate(date, showTwelveHour=false) {
|
|||||||
monthName: months[date.getMonth()],
|
monthName: months[date.getMonth()],
|
||||||
day: date.getDate(),
|
day: date.getDate(),
|
||||||
fullYear: date.getFullYear(),
|
fullYear: date.getFullYear(),
|
||||||
time: formatTime(date, showTwelveHour),
|
time: formatFullTime(date, showTwelveHour),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatFullTime(date, showTwelveHour=false) {
|
||||||
|
if (showTwelveHour) {
|
||||||
|
return twelveHourTime(date, true);
|
||||||
|
}
|
||||||
|
return pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
export function formatTime(date, showTwelveHour=false) {
|
export function formatTime(date, showTwelveHour=false) {
|
||||||
if (showTwelveHour) {
|
if (showTwelveHour) {
|
||||||
return twelveHourTime(date);
|
return twelveHourTime(date);
|
||||||
|
Loading…
Reference in New Issue
Block a user