feat: adding JS documentation

This commit is contained in:
Carlos Gutierrez
2021-11-22 11:29:47 -06:00
parent b369bcfda0
commit 5701c5d878

View File

@ -1,11 +1,28 @@
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) => {
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)
let currentDate = (!dateGetThem) ? new Date() : new Date(dateGetThem)
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)}`
return yearMonthDay
}
console.log(getDateNow())
module.exports = {
getDateNow
}