-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39.js
More file actions
86 lines (75 loc) · 1.78 KB
/
Copy path39.js
File metadata and controls
86 lines (75 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* DateHelper Helper
*
* @module greppy/helper/view/date
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
var util = require('util');
/**
* @constructor
*/
var DateHelper = function()
{
this.moment = require('moment');
};
/**
* Set the language of all date outputs.
*
* @param {String} lang - Language to set
*/
DateHelper.prototype.setLang = function(lang)
{
this.moment.lang(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
* @return {String}
*/
DateHelper.prototype.format = function(date, format)
{
if (!format) {
format = date;
date = new Date();
}
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
* @return {Integer}
*/
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
* @return {Boolean}
*/
DateHelper.prototype.equals = function(dateA, dateB)
{
if (util.isDate(dateA) && util.isDate(dateB)) {
return dateA.getTime() === dateB.getTime();
}
return false;
};
/**
* Check if the two given dates are different.
*
* @param {Date} dateA - The first date
* @param {Date} dateB - The second date
* @return {Boolean}
*/
DateHelper.prototype.different = function(dateA, dateB)
{
return (this.equals(dateA, dateB)) ? false : true;
};
module.exports = DateHelper;