esoftplay 0.0.124-e → 0.0.124-g
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.
- package/moment.ts +15 -5
- package/package.json +1 -1
package/moment.ts
CHANGED
|
@@ -16,8 +16,18 @@ const dayjsType: any = ["day", "week", "month", "quarter", "year", "hour", "minu
|
|
|
16
16
|
function isNumeric(n) {
|
|
17
17
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
export function setTimeOffset(date?: string | Date | any): Date {
|
|
20
|
+
const _date = date instanceof Date ? date : new Date(date)
|
|
21
|
+
let currentOffsetInMinutes = _date.getTimezoneOffset();
|
|
22
|
+
let currentOffsetInHours = currentOffsetInMinutes / 60;
|
|
23
|
+
let currentGMT = -currentOffsetInHours;
|
|
24
|
+
let currentOffset = currentGMT * 60 * 60 * 1000;
|
|
25
|
+
let targetOffset = 7/* Asia/Jakarta */ * 60 * 60 * 1000;
|
|
26
|
+
let gmtDiff = targetOffset - currentOffset;
|
|
27
|
+
let timeWithOffset = new Date(_date.getTime() + gmtDiff);
|
|
28
|
+
return timeWithOffset
|
|
29
|
+
}
|
|
30
|
+
export function resetTimeOffset(date: Date): Date {
|
|
21
31
|
if (!(date instanceof Date)) {
|
|
22
32
|
date = dayjs(date).toDate()
|
|
23
33
|
}
|
|
@@ -54,11 +64,11 @@ export default function moment(date?: string | Date | any) {
|
|
|
54
64
|
},
|
|
55
65
|
/* last chain */
|
|
56
66
|
fromNow: () => {
|
|
57
|
-
const out = dayjs(
|
|
67
|
+
const out = dayjs(resetTimeOffset(_date)).fromNow()
|
|
58
68
|
return out
|
|
59
69
|
},
|
|
60
70
|
format: (custom: string, ignoreTimezone?: boolean) => {
|
|
61
|
-
const _d = ignoreTimezone? _date :
|
|
71
|
+
const _d = ignoreTimezone ? _date : resetTimeOffset(_date)
|
|
62
72
|
const out = dayjs(_d).format(custom)
|
|
63
73
|
return out
|
|
64
74
|
},
|
|
@@ -67,7 +77,7 @@ export default function moment(date?: string | Date | any) {
|
|
|
67
77
|
return out
|
|
68
78
|
},
|
|
69
79
|
toMiliseconds: () => {
|
|
70
|
-
const out = String(dayjs(
|
|
80
|
+
const out = String(dayjs(resetTimeOffset(_date)).valueOf())
|
|
71
81
|
return out
|
|
72
82
|
},
|
|
73
83
|
duration: (other_date: string | Date) => {
|