esoftplay 0.0.136-s → 0.0.136-t

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 +12 -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,6 +61,7 @@ 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
  },
@@ -68,16 +71,25 @@ export default function moment(date?: string | Date | any) {
68
71
  return out
69
72
  },
70
73
  format: (custom: string, ignoreTimezone?: boolean) => {
74
+ const currentLang = esp.modProp('lib/locale').default.state().get()
75
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
76
+ moment().locale(localeId)
71
77
  const _d = ignoreTimezone ? _date : resetTimeOffset(_date)
72
78
  const out = dayjs(_d).format(custom)
73
79
  return out
74
80
  },
75
81
  serverFormat: (custom: string) => {
82
+ const currentLang = esp.modProp('lib/locale').default.state().get()
83
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
84
+ moment().locale(localeId)
76
85
  const _d = resetTimeOffset(_date)
77
86
  const out = dayjs(_d).format(custom)
78
87
  return out
79
88
  },
80
89
  localeFormat: (custom: string, ignoreTimezone?: boolean) => {
90
+ const currentLang = esp.modProp('lib/locale').default.state().get()
91
+ const localeId = langData?.filter?.((x) => x.name == currentLang)?.[0]?.code
92
+ moment().locale(localeId)
81
93
  const _d = _date
82
94
  const out = dayjs(_d).format(custom)
83
95
  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-t",
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",