mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 14:27:54 +00:00
feat(dashboard): timestamp parsing (#461)
This commit is contained in:
parent
62c5c3865a
commit
33b77470ee
4 changed files with 36 additions and 7 deletions
26
dashboard/src/api/parse-timestamps.ts
Normal file
26
dashboard/src/api/parse-timestamps.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import moment from 'moment'
|
||||
|
||||
const timestampRegex = /<t:(\d{10})(:[tTdDfFR])?>/g
|
||||
const parseTimestamps = (html: string) => {
|
||||
return html.replaceAll(
|
||||
timestampRegex,
|
||||
(match, p1, p2) => {
|
||||
const timestamp = moment.unix(parseInt(p1))
|
||||
const format: string = p2 ? p2[1] : 'f'
|
||||
if (format !== 'R') {
|
||||
let dateTimeFormatOptions = {
|
||||
t: 'HH:mm',
|
||||
T: 'HH:mm:ss',
|
||||
d: 'DD/MM/YYYY',
|
||||
D: 'DD MMMM YYYY',
|
||||
f: 'DD MMMM YYYY HH:mm',
|
||||
F: 'dddd, DD MMMM YYYY HH:mm',
|
||||
}[format]
|
||||
return timestamp.format(dateTimeFormatOptions)
|
||||
}
|
||||
return timestamp.fromNow()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export default parseTimestamps
|
||||
Loading…
Add table
Add a link
Reference in a new issue