forked from marcomerens/anniversarymodule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBIRTHDAYQ.INI
59 lines (46 loc) · 1.28 KB
/
BIRTHDAYQ.INI
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
/* Magic Mirror
* Module: BIRTHDAYS
*
* By Marco Merens
* MIT Licensed.
*/
Module.register("BIRTHDAYS", {
defaults: {
limit:4,
people:[{name:"Marco",birthdate:"1973-12-30"}]
},
start:function() {
this.calculate()
var self=this
setInterval(function(){
self.calculate()
self.updateDom()
},60*60*1000) // update every hour
},
calculate : function(){
var now=new Date(new Date().toLocaleString("sv").substring(0,10))
var thisyear=now.getUTCFullYear()
var today=new Date(thisyear,now.getUTCMonth(),now.getUTCDate()).getTime()
Log.log(now)
var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
this.config.people.forEach(function(p){
var bdate=new Date(p.birthdate)
var bmonth=bdate.getUTCMonth()
var bday=bdate.getUTCDate()
var byear=bdate.getUTCFullYear()
var diff=new Date(thisyear,bmonth,bday).getTime()-today
if (diff< 0) {diff=new Date(thisyear+1,bmonth,bday).getTime()-today}
p.days=Math.floor(diff/1000/60/60/24)
p.date=bday+" "+months[bmonth]
p.age=thisyear-byear
p.birthyear=byear
})
this.config.people.sort(function(a,b){return a.days-b.days})
},
getTemplate: function () {
return "BIRTHDAYS.njk";
},
getTemplateData: function () {
return this.config;
}
});