esoftplay 0.0.136-s → 0.0.136-u

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.
Files changed (2) hide show
  1. package/moment.ts +15 -0
  2. package/package.json +1 -1
package/moment.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  //@ts-nocheck
2
2
 
3
3
  import dayjs from 'dayjs'
4
+ import esp from 'esoftplay/esp'
4
5
  const utc = require('dayjs/plugin/utc')
5
6
  const timezone = require('dayjs/plugin/timezone') // dependent on utc plugin
6
7
  const relativeTime = require('dayjs/plugin/relativeTime')
@@ -43,6 +44,7 @@ export function resetTimeOffset(date: Date): Date {
43
44
 
44
45
  export default function moment(date?: string | Date | any) {
45
46
  let _date = isNumeric(date) ? new Date(date * 1000) : date
47
+ const langData = Object.values(esp.config('lang'))
46
48
  return {
47
49
  add: (count: number, type: "days" | "weeks" | "months" | "quarters" | "years" | "hours" | "minutes" | "seconds" | "milliseconds") => {
48
50
  const out = dayjs(_date).add(count, (dayjsType[momentType.indexOf(type)]))
@@ -59,25 +61,38 @@ export default function moment(date?: string | Date | any) {
59
61
  locale: (locale_id: string) => {
60
62
  require('dayjs/locale/en')
61
63
  require('dayjs/locale/id')
64
+ require('dayjs/locale/zh-cn')
62
65
  const out = dayjs.locale(locale_id)
63
66
  return moment(out)
64
67
  },
65
68
  /* last chain */
66
69
  fromNow: () => {
70
+ const currentLang = esp.modProp('lib/locale').default.state().get()
71
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
72
+ moment().locale(localeId)
67
73
  const out = dayjs(resetTimeOffset(_date)).fromNow()
68
74
  return out
69
75
  },
70
76
  format: (custom: string, ignoreTimezone?: boolean) => {
77
+ const currentLang = esp.modProp('lib/locale').default.state().get()
78
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
79
+ moment().locale(localeId)
71
80
  const _d = ignoreTimezone ? _date : resetTimeOffset(_date)
72
81
  const out = dayjs(_d).format(custom)
73
82
  return out
74
83
  },
75
84
  serverFormat: (custom: string) => {
85
+ const currentLang = esp.modProp('lib/locale').default.state().get()
86
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
87
+ moment().locale(localeId)
76
88
  const _d = resetTimeOffset(_date)
77
89
  const out = dayjs(_d).format(custom)
78
90
  return out
79
91
  },
80
92
  localeFormat: (custom: string, ignoreTimezone?: boolean) => {
93
+ const currentLang = esp.modProp('lib/locale').default.state().get()
94
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
95
+ moment().locale(localeId)
81
96
  const _d = _date
82
97
  const out = dayjs(_d).format(custom)
83
98
  return out
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.136-s",
3
+ "version": "0.0.136-u",
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",