mirror of
https://github.com/andatoshiki/toshiki-notebook.git
synced 2026-06-06 06:25:55 +00:00
27 lines
759 B
TypeScript
27 lines
759 B
TypeScript
// data format transofmation utility for both feed and pageinfo generation
|
|
import dayjs from 'dayjs'
|
|
import utc from 'dayjs/plugin/utc.js'
|
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
|
import 'dayjs/locale/en'
|
|
|
|
dayjs.extend(utc)
|
|
dayjs.locale('en')
|
|
dayjs.extend(relativeTime)
|
|
|
|
export function getDate(date: string | Date | undefined): string | null {
|
|
if (date) {
|
|
const time = dayjs(date instanceof Date ? date : date.trim())
|
|
if (time.isValid()) {
|
|
const currentTime = dayjs(date).utc().local().format('YYYY-MM-DD')
|
|
return currentTime
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function getFromNow(date: string | Date): string | null {
|
|
if (date) return dayjs(date).utc().local().fromNow()
|
|
|
|
return null
|
|
}
|