date.js
* @module greppy/helper/view/date
* @author Hermann Mayer <hermann.mayer92@gmail.com>
this.moment = require('moment');
* Set the language of all date outputs.
* @param {String} lang - Language to set
DateHelper.prototype.setLang = function(lang)
* Format a date with the help of moment.
* @param {Date} [date] - The date to format, if ommited it's now
* @param {String} format - Format string which will be processed by moment
DateHelper.prototype.format = function(date, format)
return this.moment(date).format(format);
* Calculate the difference from date to now in minutes or another unit.
* @param {Date} date - The first date
* @param {String} [unit] - Unit of the difference, default: minutes
DateHelper.prototype.diffToNow = function(date, unit)
return this.moment(date).diff(this.moment(new Date()), unit || 'minutes');
* Check if the two given dates are equals.
* @param {Date} dateA - The first date
* @param {Date} dateB - The second date
DateHelper.prototype.equals = function(dateA, dateB)
if (util.isDate(dateA) && util.isDate(dateB)) {
return dateA.getTime() === dateB.getTime();
* Check if the two given dates are different.
* @param {Date} dateA - The first date
* @param {Date} dateB - The second date
DateHelper.prototype.different = function(dateA, dateB)