mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-30 19:07:39 +03:00
refactor(server): replace Moment.js by Day.js
This commit is contained in:
parent
ebe31f4b60
commit
da0233495d
40
package-lock.json
generated
40
package-lock.json
generated
@ -23,13 +23,13 @@
|
|||||||
"archiver": "^5.3.0",
|
"archiver": "^5.3.0",
|
||||||
"async": "^3.2.0",
|
"async": "^3.2.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
"dayjs": "^1.11.5",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"execa": "^5.0.0",
|
"execa": "^5.0.0",
|
||||||
"fastify": "^4.5.3",
|
"fastify": "^4.5.3",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"googleapis": "^67.1.1",
|
"googleapis": "^67.1.1",
|
||||||
"ibm-watson": "^6.1.1",
|
"ibm-watson": "^6.1.1",
|
||||||
"moment-timezone": "^0.5.37",
|
|
||||||
"node-wav": "0.0.2",
|
"node-wav": "0.0.2",
|
||||||
"socket.io": "^4.5.2",
|
"socket.io": "^4.5.2",
|
||||||
"socket.io-client": "^4.5.2",
|
"socket.io-client": "^4.5.2",
|
||||||
@ -5751,8 +5751,7 @@
|
|||||||
"node_modules/dayjs": {
|
"node_modules/dayjs": {
|
||||||
"version": "1.11.5",
|
"version": "1.11.5",
|
||||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.5.tgz",
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.5.tgz",
|
||||||
"integrity": "sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==",
|
"integrity": "sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
@ -11011,25 +11010,6 @@
|
|||||||
"mkdirp": "bin/cmd.js"
|
"mkdirp": "bin/cmd.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/moment": {
|
|
||||||
"version": "2.29.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
|
||||||
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/moment-timezone": {
|
|
||||||
"version": "0.5.37",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.37.tgz",
|
|
||||||
"integrity": "sha512-uEDzDNFhfaywRl+vwXxffjjq1q0Vzr+fcQpQ1bU0kbzorfS7zVtZnCnGc8mhWmF39d4g4YriF6kwA75mJKE/Zg==",
|
|
||||||
"dependencies": {
|
|
||||||
"moment": ">= 2.9.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/moo-color": {
|
"node_modules/moo-color": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/moo-color/-/moo-color-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/moo-color/-/moo-color-1.0.3.tgz",
|
||||||
@ -18753,8 +18733,7 @@
|
|||||||
"dayjs": {
|
"dayjs": {
|
||||||
"version": "1.11.5",
|
"version": "1.11.5",
|
||||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.5.tgz",
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.5.tgz",
|
||||||
"integrity": "sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==",
|
"integrity": "sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
@ -22816,19 +22795,6 @@
|
|||||||
"minimist": "^1.2.6"
|
"minimist": "^1.2.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"moment": {
|
|
||||||
"version": "2.29.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
|
||||||
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
|
|
||||||
},
|
|
||||||
"moment-timezone": {
|
|
||||||
"version": "0.5.37",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.37.tgz",
|
|
||||||
"integrity": "sha512-uEDzDNFhfaywRl+vwXxffjjq1q0Vzr+fcQpQ1bU0kbzorfS7zVtZnCnGc8mhWmF39d4g4YriF6kwA75mJKE/Zg==",
|
|
||||||
"requires": {
|
|
||||||
"moment": ">= 2.9.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"moo-color": {
|
"moo-color": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/moo-color/-/moo-color-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/moo-color/-/moo-color-1.0.3.tgz",
|
||||||
|
@ -70,13 +70,13 @@
|
|||||||
"archiver": "^5.3.0",
|
"archiver": "^5.3.0",
|
||||||
"async": "^3.2.0",
|
"async": "^3.2.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
"dayjs": "^1.11.5",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"execa": "^5.0.0",
|
"execa": "^5.0.0",
|
||||||
"fastify": "^4.5.3",
|
"fastify": "^4.5.3",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"googleapis": "^67.1.1",
|
"googleapis": "^67.1.1",
|
||||||
"ibm-watson": "^6.1.1",
|
"ibm-watson": "^6.1.1",
|
||||||
"moment-timezone": "^0.5.37",
|
|
||||||
"node-wav": "0.0.2",
|
"node-wav": "0.0.2",
|
||||||
"socket.io": "^4.5.2",
|
"socket.io": "^4.5.2",
|
||||||
"socket.io-client": "^4.5.2",
|
"socket.io-client": "^4.5.2",
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
import moment from 'moment-timezone'
|
import dayjs from 'dayjs'
|
||||||
|
import utc from 'dayjs/plugin/utc'
|
||||||
|
import timezone from 'dayjs/plugin/timezone'
|
||||||
|
|
||||||
import { TIME_ZONE } from '@/constants'
|
import { TIME_ZONE } from '@/constants'
|
||||||
|
import log from '@/helpers/log'
|
||||||
|
|
||||||
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
|
|
||||||
export function getDateTime() {
|
export function getDateTime() {
|
||||||
return moment().tz(getTimeZone()).format()
|
return dayjs().tz(getTimeZone()).format()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTimeZone() {
|
export function getTimeZone() {
|
||||||
let timeZone = moment.tz.guess()
|
let { timeZone } = Intl.DateTimeFormat().resolvedOptions()
|
||||||
|
|
||||||
if (TIME_ZONE && !!moment.tz.zone(TIME_ZONE)) {
|
if (TIME_ZONE) {
|
||||||
|
// Verify if the time zone is valid
|
||||||
|
try {
|
||||||
|
Intl.DateTimeFormat(undefined, { timeZone: TIME_ZONE })
|
||||||
timeZone = TIME_ZONE
|
timeZone = TIME_ZONE
|
||||||
|
} catch (e) {
|
||||||
|
log.warning(
|
||||||
|
`The time zone "${TIME_ZONE}" is not valid. Falling back to "${timeZone}"`
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeZone
|
return timeZone
|
||||||
|
Loading…
Reference in New Issue
Block a user