feat: adding testing for the function

This commit is contained in:
Carlos Gutierrez
2021-11-22 12:36:40 -06:00
parent 5701c5d878
commit 56f287d54e
5 changed files with 9544 additions and 5 deletions

View File

@ -9,6 +9,45 @@ const addCero = (num) => {
return num < 10 ? `0${num}` : num
}
const gmtChecker = (gmt) => {
const array = [
'GMT+00:00',
'GMT-00:00',
'GMT+01:00',
'GMT+02:00',
'GMT+02:00',
'GMT+03:00',
'GMT+03:30',
'GMT+04:00',
'GMT+05:00',
'GMT+05:30',
'GMT+06:00',
'GMT+07:00',
'GMT+08:00',
'GMT+09:00',
'GMT+09:30',
'GMT+10:00',
'GMT+11:00',
'GMT+12:00',
'GMT-11:00',
'GMT-10:00',
'GMT-09:00',
'GMT-08:00',
'GMT-07:00',
'GMT-07:00',
'GMT-06:00',
'GMT-05:00',
'GMT-05:00',
'GMT-04:00',
'GMT-03:30',
'GMT-03:00',
'GMT-03:00',
'GMT-01:00'
]
if (gmt === undefined) return true
return array.includes(gmt)
}
/**
* Retrieve the date as format yyyy/mm/dd hh:mm:ss
* @param {timestamp} date
@ -21,8 +60,10 @@ module.exports = (dateGetThem, gmtHours) => {
const valid = (new Date(dateGetThem)).getTime() > 0;
if (!valid) return -1
}
gmtHours = !gmtHours ? 'GMT-00:00' : gmtHours
if (!gmtChecker(gmtHours)) 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)
@ -36,3 +77,4 @@ module.exports = (dateGetThem, gmtHours) => {
const yearMonthDay = `${year}/${addCero(month + 1)}/${addCero(date)} ${addCero(hour)}:${addCero(minutes)}:${addCero(seconds)}`
return yearMonthDay
}