generated from alphane/template
Initial commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { isNil, isEmpty } from "lodash"
|
||||
import { DateTime } from "luxon"
|
||||
|
||||
export function formatDate(input: string | Date | undefined): string {
|
||||
if (isNil(input) || isEmpty(input)) {
|
||||
return ""
|
||||
} else if (typeof input == "string") {
|
||||
const parsed = DateTime.fromISO(input, { zone: "utc" })
|
||||
const isMidnight = parsed.hour === 0 && parsed.minute === 0 && parsed.second === 0
|
||||
return isMidnight ? parsed.toFormat("yyyy-MM-dd") : parsed.toLocal().toFormat("yyyy-MM-dd")
|
||||
} else if (input instanceof Date) {
|
||||
return DateTime.fromJSDate(input).toLocal().toFormat("yyyy-MM-dd")
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
export default formatDate
|
||||
Reference in New Issue
Block a user