befly 3.19.0 → 3.19.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ const visitStatsDateFormatter = new Intl.DateTimeFormat("en-CA", {
2
+ year: "numeric",
3
+ month: "2-digit",
4
+ day: "2-digit"
5
+ });
6
+
7
+ export const DAY_MS = 24 * 60 * 60 * 1000;
8
+
9
+ function toDate(value = Date.now()) {
10
+ if (value instanceof Date) {
11
+ return value;
12
+ }
13
+
14
+ return Reflect.construct(Date, [value]);
15
+ }
16
+
17
+ function padDatePart(value) {
18
+ if (value < 10) {
19
+ return `0${value}`;
20
+ }
21
+
22
+ return String(value);
23
+ }
24
+
25
+ export function addDays(timestamp = Date.now(), days = 0) {
26
+ return Number(timestamp || 0) + Number(days || 0) * DAY_MS;
27
+ }
28
+
29
+ export function getDateYmdNumber(timestamp = Date.now()) {
30
+ return Number(visitStatsDateFormatter.format(timestamp).replace(/[^0-9]/g, ""));
31
+ }
32
+
33
+ export function getDayStartTime(timestamp = Date.now()) {
34
+ const date = toDate(timestamp);
35
+ return Reflect.construct(Date, [date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0]).getTime();
36
+ }
37
+
38
+ export function getDayEndTime(timestamp = Date.now()) {
39
+ return getDayStartTime(timestamp) + DAY_MS - 1;
40
+ }
41
+
42
+ export function getTimeBucketStart(timestamp = Date.now(), bucketMs = 0) {
43
+ const bucket = Number(bucketMs || 0);
44
+ if (bucket <= 0) {
45
+ return Number(timestamp || 0);
46
+ }
47
+
48
+ const time = Number(timestamp || 0);
49
+ return time - (time % bucket);
50
+ }
51
+
52
+ export function formatYmdHms(value = Date.now(), format = "dateTime") {
53
+ const date = toDate(value);
54
+ const y = date.getFullYear();
55
+ const m = date.getMonth() + 1;
56
+ const d = date.getDate();
57
+ const h = date.getHours();
58
+ const mi = date.getMinutes();
59
+ const s = date.getSeconds();
60
+
61
+ const mm = padDatePart(m);
62
+ const dd = padDatePart(d);
63
+ const hh = padDatePart(h);
64
+ const mii = padDatePart(mi);
65
+ const ss = padDatePart(s);
66
+
67
+ if (format === "date") {
68
+ return `${y}-${mm}-${dd}`;
69
+ }
70
+
71
+ if (format === "time") {
72
+ return `${hh}:${mii}:${ss}`;
73
+ }
74
+
75
+ return `${y}-${mm}-${dd} ${hh}:${mii}:${ss}`;
76
+ }
@@ -1,23 +0,0 @@
1
- export function formatYmdHms(date, format = "dateTime") {
2
- const y = date.getFullYear();
3
- const m = date.getMonth() + 1;
4
- const d = date.getDate();
5
- const h = date.getHours();
6
- const mi = date.getMinutes();
7
- const s = date.getSeconds();
8
-
9
- const mm = m < 10 ? `0${m}` : String(m);
10
- const dd = d < 10 ? `0${d}` : String(d);
11
- const hh = h < 10 ? `0${h}` : String(h);
12
- const mii = mi < 10 ? `0${mi}` : String(mi);
13
- const ss = s < 10 ? `0${s}` : String(s);
14
-
15
- if (format === "date") {
16
- return `${y}-${mm}-${dd}`;
17
- }
18
- if (format === "time") {
19
- return `${hh}:${mii}:${ss}`;
20
- }
21
-
22
- return `${y}-${mm}-${dd} ${hh}:${mii}:${ss}`;
23
- }