feat: adding function to convert

This commit is contained in:
Carlos Gutierrez 2021-11-22 09:52:22 -06:00
parent e4a9cfd403
commit b369bcfda0
4 changed files with 47 additions and 0 deletions

26
index.js Normal file
View File

@ -0,0 +1,26 @@
const GMT = require('node-gmt')
const gmtHours = 'GMT-05:00'
const addCero = (num) => {
return num < 10 ? `0${num}` : num
}
const getDateNow = (dateGetThem) => {
const gmt = new GMT(gmtHours)
let currentDate = (!dateGetThem) ? new Date() : new Date(dateGetThem)
currentDate = gmt.relativeDate(currentDate)
const date = currentDate.getDate()
const month = currentDate.getMonth()
const year = currentDate.getFullYear()
const hour = currentDate.getHours()
const minutes = currentDate.getMinutes()
const seconds = currentDate.getSeconds()
const yearMonthDay = `${year}/${addCero(month + 1)}/${addCero(date)} ${addCero(hour)}:${addCero(minutes)}:${addCero(seconds)}`
return yearMonthDay
}
console.log(getDateNow())
module.exports = {
getDateNow
}

5
node_modules/.package-lock.json generated vendored
View File

@ -1205,6 +1205,11 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/node-gmt": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/node-gmt/-/node-gmt-0.0.2.tgz",
"integrity": "sha512-v8WiPWqVlG3+rMskh9EUu8Y4ZmxGIY7AG8z6rPXKWBXuv5FetHRzOmVyQRyW7x6FsZPtshFvzJjXI2aeDAaSJg=="
},
"node_modules/normalize-package-data": { "node_modules/normalize-package-data": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz",

13
package-lock.json generated
View File

@ -8,6 +8,9 @@
"name": "time-function", "name": "time-function",
"version": "0.0.1", "version": "0.0.1",
"license": "MIT", "license": "MIT",
"dependencies": {
"node-gmt": "^0.0.2"
},
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^15.0.0", "@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0", "@commitlint/config-conventional": "^15.0.0",
@ -1215,6 +1218,11 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/node-gmt": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/node-gmt/-/node-gmt-0.0.2.tgz",
"integrity": "sha512-v8WiPWqVlG3+rMskh9EUu8Y4ZmxGIY7AG8z6rPXKWBXuv5FetHRzOmVyQRyW7x6FsZPtshFvzJjXI2aeDAaSJg=="
},
"node_modules/normalize-package-data": { "node_modules/normalize-package-data": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz",
@ -2962,6 +2970,11 @@
"kind-of": "^6.0.3" "kind-of": "^6.0.3"
} }
}, },
"node-gmt": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/node-gmt/-/node-gmt-0.0.2.tgz",
"integrity": "sha512-v8WiPWqVlG3+rMskh9EUu8Y4ZmxGIY7AG8z6rPXKWBXuv5FetHRzOmVyQRyW7x6FsZPtshFvzJjXI2aeDAaSJg=="
},
"normalize-package-data": { "normalize-package-data": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz",

View File

@ -24,5 +24,8 @@
"@commitlint/cli": "^15.0.0", "@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0", "@commitlint/config-conventional": "^15.0.0",
"husky": "^4.3.8" "husky": "^4.3.8"
},
"dependencies": {
"node-gmt": "^0.0.2"
} }
} }