From 5701c5d8787a1b26ead28a509c6aa1290130515b Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Mon, 22 Nov 2021 11:29:47 -0600 Subject: [PATCH] feat: adding JS documentation --- index.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 886312c..513b6c0 100644 --- a/index.js +++ b/index.js @@ -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 -}