forked from moment/luxon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatetime.js
79 lines (74 loc) · 2.26 KB
/
datetime.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import Benchmark from "benchmark";
import DateTime from "../src/datetime";
import Settings from "../src/settings";
function runDateTimeSuite() {
return new Promise((resolve, reject) => {
const suite = new Benchmark.Suite();
const dt = DateTime.now();
suite
.add("DateTime.local", () => {
DateTime.now();
})
.add("DateTime.fromObject with locale", () => {
DateTime.fromObject({}, { locale: "fr" });
})
.add("DateTime.local with numbers", () => {
DateTime.local(2017, 5, 15);
})
.add("DateTime.fromISO", () => {
DateTime.fromISO("1982-05-25T09:10:11.445Z");
})
.add("DateTime.fromSQL", () => {
DateTime.fromSQL("2016-05-14 10:23:54.2346");
})
.add("DateTime.fromString", () => {
DateTime.fromString("1982/05/25 09:10:11.445", "yyyy/MM/dd HH:mm:ss.SSS");
})
.add("DateTime.fromString with zone", () => {
DateTime.fromString("1982/05/25 09:10:11.445", "yyyy/MM/dd HH:mm:ss.SSS", {
zone: "America/Los_Angeles",
});
})
.add("DateTime#setZone", () => {
dt.setZone("America/Los_Angeles");
})
.add("DateTime#toFormat", () => {
dt.toFormat("yyyy-MM-dd");
})
.add("DateTime#toFormat with macro", () => {
dt.toFormat("T");
})
.add("DateTime#toFormat with macro no cache", () => {
dt.toFormat("T");
Settings.resetCaches();
})
.add("DateTime#add", () => {
dt.plus({ milliseconds: 3434 });
})
.add("DateTime#toISO", () => {
dt.toISO();
})
.add("DateTime#toLocaleString", () => {
dt.toLocaleString();
})
.add("DateTime#toLocaleString in utc", () => {
dt.toUTC().toLocaleString();
})
.add("DateTime#toRelativeCalendar", () => {
dt.toRelativeCalendar({ base: DateTime.now(), locale: "fi" });
})
.on("cycle", (event) => {
console.log(String(event.target));
})
.on("complete", function () {
console.log("Fastest is " + this.filter("fastest").map("name"));
resolve();
})
.on("error", function () {
reject(this.error);
})
.run();
});
}
const allSuites = [runDateTimeSuite];
export default allSuites;