feat: adding JS documentation
This commit is contained in:
26
index.js
26
index.js
@ -1,11 +1,28 @@
|
|||||||
const GMT = require('node-gmt')
|
const GMT = require('node-gmt')
|
||||||
const gmtHours = 'GMT-05:00'
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a 0 before the first digit when the number is less than 10
|
||||||
|
* @param {number} number
|
||||||
|
* @returns {String} string
|
||||||
|
*/
|
||||||
const addCero = (num) => {
|
const addCero = (num) => {
|
||||||
return num < 10 ? `0${num}` : num
|
return num < 10 ? `0${num}` : num
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDateNow = (dateGetThem) => {
|
/**
|
||||||
|
* Retrieve the date as format yyyy/mm/dd hh:mm:ss
|
||||||
|
* @param {timestamp} date
|
||||||
|
* @param {gmt hours} string
|
||||||
|
* @returns {String} string
|
||||||
|
*/
|
||||||
|
module.exports = (dateGetThem, gmtHours) => {
|
||||||
|
if (dateGetThem !== undefined || dateGetThem) {
|
||||||
|
if (typeof dateGetThem === 'number') return -1
|
||||||
|
const valid = (new Date(dateGetThem)).getTime() > 0;
|
||||||
|
if (!valid) return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
gmtHours = !gmtHours ? 'GMT-00:00' : gmtHours
|
||||||
const gmt = new GMT(gmtHours)
|
const gmt = new GMT(gmtHours)
|
||||||
let currentDate = (!dateGetThem) ? new Date() : new Date(dateGetThem)
|
let currentDate = (!dateGetThem) ? new Date() : new Date(dateGetThem)
|
||||||
currentDate = gmt.relativeDate(currentDate)
|
currentDate = gmt.relativeDate(currentDate)
|
||||||
@ -19,8 +36,3 @@ const getDateNow = (dateGetThem) => {
|
|||||||
const yearMonthDay = `${year}/${addCero(month + 1)}/${addCero(date)} ${addCero(hour)}:${addCero(minutes)}:${addCero(seconds)}`
|
const yearMonthDay = `${year}/${addCero(month + 1)}/${addCero(date)} ${addCero(hour)}:${addCero(minutes)}:${addCero(seconds)}`
|
||||||
return yearMonthDay
|
return yearMonthDay
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(getDateNow())
|
|
||||||
module.exports = {
|
|
||||||
getDateNow
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user