esoftplay 0.0.124-b → 0.0.124-d

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.
@@ -6,8 +6,8 @@ import { LibNet_status } from 'esoftplay/cache/lib/net_status/import';
6
6
  import { LibProgress } from 'esoftplay/cache/lib/progress/import';
7
7
  import { LibToastProperty } from 'esoftplay/cache/lib/toast/import';
8
8
  import { LibUtils } from 'esoftplay/cache/lib/utils/import';
9
- import esp from 'esoftplay/esp';
10
9
  import { reportApiError } from "esoftplay/error";
10
+ import esp from 'esoftplay/esp';
11
11
  import Constants from 'expo-constants';
12
12
 
13
13
  //api_logger_import
@@ -441,16 +441,14 @@ export default class m {
441
441
  LibProgress.hide()
442
442
  }
443
443
 
444
- protected getTimeByTimeZone(timeZone: string): number {
445
- let localTimezoneOffset = new Date().getTimezoneOffset()
446
- let serverTimezoneOffset = -420 // -420 for Asia/Jakarta
447
- let diff
448
- if (localTimezoneOffset < serverTimezoneOffset) {
449
- diff = localTimezoneOffset - serverTimezoneOffset
450
- } else {
451
- diff = (serverTimezoneOffset - localTimezoneOffset) * -1
452
- }
453
- let time = new Date().getTime() + (diff * 60 * 1000 * -1);
454
- return time;
444
+ protected getTimeByTimeZone(GMT: number): number {
445
+ const date = new Date()
446
+ let currentOffsetInMinutes = date.getTimezoneOffset();
447
+ let currentOffsetInHours = currentOffsetInMinutes / 60;
448
+ let currentGMT = -currentOffsetInHours;
449
+ let currentOffset = currentGMT * 60 * 60 * 1000;
450
+ let targetOffset = 7/* Asia/Jakarta */ * 60 * 60 * 1000;
451
+ let gmtDiff = targetOffset - currentOffset;
452
+ return date.getTime() + gmtDiff
455
453
  }
456
454
  }
package/moment.ts CHANGED
@@ -17,6 +17,20 @@ function isNumeric(n) {
17
17
  return !isNaN(parseFloat(n)) && isFinite(n);
18
18
  }
19
19
 
20
+ function normalizeTimeOffset(date: Date) {
21
+ if (!(date instanceof Date)) {
22
+ date = dayjs(date).toDate()
23
+ }
24
+ let currentOffsetInMinutes = date.getTimezoneOffset();
25
+ let currentOffsetInHours = currentOffsetInMinutes / 60;
26
+ let currentGMT = -currentOffsetInHours;
27
+ let currentOffset = currentGMT * 60 * 60 * 1000;
28
+ let targetOffset = 7/* Asia/Jakarta */ * 60 * 60 * 1000;
29
+ let gmtDiff = targetOffset - currentOffset;
30
+ let originalTime = new Date(date.getTime() - gmtDiff);
31
+ return originalTime;
32
+ }
33
+
20
34
  export default function moment(date?: string | Date | any) {
21
35
  let _date = isNumeric(date) ? new Date(date * 1000) : date
22
36
  return {
@@ -40,11 +54,12 @@ export default function moment(date?: string | Date | any) {
40
54
  },
41
55
  /* last chain */
42
56
  fromNow: () => {
43
- const out = dayjs(_date).fromNow()
57
+ const out = dayjs(normalizeTimeOffset(_date)).fromNow()
44
58
  return out
45
59
  },
46
- format: (custom: string) => {
47
- const out = dayjs(_date).format(custom)
60
+ format: (custom: string, ignoreTimezone?: boolean) => {
61
+ const _d = ignoreTimezone? _date : normalizeTimeOffset(_date)
62
+ const out = dayjs(_d).format(custom)
48
63
  return out
49
64
  },
50
65
  toDate: () => {
@@ -52,7 +67,7 @@ export default function moment(date?: string | Date | any) {
52
67
  return out
53
68
  },
54
69
  toMiliseconds: () => {
55
- const out = String(dayjs(_date).valueOf())
70
+ const out = String(dayjs(normalizeTimeOffset(_date)).valueOf())
56
71
  return out
57
72
  },
58
73
  duration: (other_date: string | Date) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.124-b",
3
+ "version": "0.0.124-d",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",