forked from plausible-yeti/rappo.rt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
30 lines (22 loc) · 893 Bytes
/
test.js
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
var moment = require('moment');
module.exports = function(date){
var birthday = date;
var todayMonth = moment(Date.now()).month();
var todayDay = moment(Date.now()).day();
var eventDateMonth = moment(birthday).month();
var eventDateDay = moment(birthday).day();
// Check if month is in past, same, future
if(eventDateMonth < todayMonth){
return 'in ' + moment(eventDate).year(moment(Date.now()).year()+1).fromNow();
} else if (eventDateMonth === todayMonth){
if(eventDateDay < todayDay){
return 'in ' + moment(eventDate).year(moment(Date.now()).year()+1).fromNow();
} else if (eventDateDay === todayDay){
return 'today'
} else if (eventDateDay > todayDay){
return 'in ' + moment(eventDate).year(moment(Date.now()).year()).fromNow();
}
} else if (eventDateMonth > todayMonth){
return 'in ' + moment(eventDate).year(moment(Date.now()).year()).fromNow();
}
}