allows scrolling backwards through history
This commit is contained in:
49
frontend/src/datetime.ts
Normal file
49
frontend/src/datetime.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// This function is slow
|
||||
export function getDateString(date: Date, utc: boolean, millis: boolean) {
|
||||
const year = utc ? date.getUTCFullYear() : date.getFullYear();
|
||||
const month = (
|
||||
(utc ? date.getMonth() : date.getMonth()) + 1
|
||||
).toLocaleString('en-US', {
|
||||
minimumIntegerDigits: 2,
|
||||
useGrouping: false,
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
const day = (utc ? date.getUTCDate() : date.getDate()).toLocaleString(
|
||||
'en-US',
|
||||
{
|
||||
minimumIntegerDigits: 2,
|
||||
useGrouping: false,
|
||||
maximumFractionDigits: 0,
|
||||
},
|
||||
);
|
||||
const hour = (utc ? date.getUTCHours() : date.getHours()).toLocaleString(
|
||||
'en-US',
|
||||
{
|
||||
minimumIntegerDigits: 2,
|
||||
useGrouping: false,
|
||||
maximumFractionDigits: 0,
|
||||
},
|
||||
);
|
||||
const minute = (
|
||||
utc ? date.getUTCMinutes() : date.getMinutes()
|
||||
).toLocaleString('en-US', {
|
||||
minimumIntegerDigits: 2,
|
||||
useGrouping: false,
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
const second = (
|
||||
utc ? date.getUTCSeconds() : date.getSeconds()
|
||||
).toLocaleString('en-US', {
|
||||
minimumIntegerDigits: 2,
|
||||
useGrouping: false,
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
const milliseconds = (
|
||||
utc ? date.getUTCMilliseconds() : date.getMilliseconds()
|
||||
).toLocaleString('en-US', {
|
||||
minimumIntegerDigits: 3,
|
||||
useGrouping: false,
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
return `${year}/${month}/${day} ${hour}:${minute}:${second}${millis ? `.${milliseconds}` : ''}${utc ? 'Z' : ''}`;
|
||||
}
|
||||
Reference in New Issue
Block a user