@mojaloop/central-services-shared
Version:
Shared code for mojaloop central services
51 lines (42 loc) • 1.02 kB
JavaScript
const sleep = (milliseconds = 10) => {
const start = new Date().getTime()
while (true) {
if ((new Date().getTime() - start) > milliseconds) {
break
}
}
}
const msCurrentYear = () => {
const now = new Date()
const pastDate = new Date(now.getFullYear(), 0)
return now - pastDate
}
const msCurrentMonth = () => {
const now = new Date()
const pastDate = new Date(now.getFullYear(), now.getMonth())
return now - pastDate
}
const msToday = () => {
const now = new Date()
const pastDate = new Date(now.getFullYear(), now.getMonth(), now.getDate())
return now - pastDate
}
const getCurrentUTCTimeInMilliseconds = () => {
return new Date().getTime()
}
const getUTCString = (d) => {
return d.toISOString().replace(/[TZ]/g, ' ').trim()
}
const getYMDString = (d) => {
return d.toISOString().replace(/-/g, '').substr(0, 8)
}
module.exports = {
sleep,
msCurrentYear,
msCurrentMonth,
msToday,
getCurrentUTCTimeInMilliseconds,
getUTCString,
getYMDString
}