-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathformat-date.ts
More file actions
30 lines (25 loc) · 1.05 KB
/
format-date.ts
File metadata and controls
30 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as glide from "../glide";
import { DateTime } from "luxon";
export default glide
.columnNamed("Format Date")
.withDescription(`Powerful date and time formatting with [luxon](https://moment.github.io/luxon/#/formatting?id=table-of-tokens).`)
.withReleased("direct")
.withCategory("Date & Time")
.withAuthor("luxon", "https://moment.github.io/luxon")
.withAbout(
`
Learn about date formatting in [luxon's documentation](https://moment.github.io/luxon/#/formatting?id=table-of-tokens).
`
)
.withStringResult()
.withRequiredDateParam("date")
.withRequiredStringParam("format")
.withTest({ date: "2021-10-21T14:35:46.216Z", format: "cccc" }, "Thursday")
.withTest({ date: "10/21/2021", format: "cccc" }, "Thursday")
.withTest({ date: "Invalid date!", format: "cccc" }, undefined)
.run(({ date, format }) => {
const millis = Date.parse(date);
if (isNaN(millis)) return undefined;
const dateTime = DateTime.fromMillis(millis);
return dateTime.toFormat(format);
});