2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-15 18:12:46 +00:00
thumbsup/themes/base/helpers/date.js
Romain 03a9c9a319 refactor: themes are now standalone folders, to prepare for external loading
Every theme is made of { Handlebars + Less + Partials + Helpers + Public }
2018-06-01 23:49:53 +02:00

22 lines
466 B
JavaScript

const moment = require('moment')
/*
Render a date in a legible format
Usage:
{{date taken}}
{{date taken "MMMM YYYY"}}
{{date taken "ago"}}
*/
module.exports = (date, format) => {
if (typeof format !== 'string') {
// default format
return moment(date).format('DD MMM YYYY')
} else if (format === 'ago') {
// some time ago
return moment(date).fromNow()
} else {
// custom format
return moment(date).format(format)
}
}