Moved date helper funcs to utils.js
This commit is contained in:
16
src/utils.js
16
src/utils.js
@@ -7,6 +7,18 @@ const dateString = (date) => {
|
||||
return `${ye}-${mo}-${da}`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
dateString
|
||||
function humanReadableDate(date) {
|
||||
const options = { year: 'numeric', month: 'long', day: 'numeric' };
|
||||
return new Date(date).toLocaleDateString(undefined, options);
|
||||
}
|
||||
|
||||
function daysAgo(date) {
|
||||
const day = 24 * 60 * 60 * 1000;
|
||||
return Math.round(Math.abs((new Date() - new Date(date)) / day));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
dateString,
|
||||
humanReadableDate,
|
||||
daysAgo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user