A birthday card for TileBoard to users that are intrested.
i use hassio.
the code is modified from a original birthday-card for Lovelace, to be used with TileBoard template
the birthdays-tileboard.js file must be uploaded in /config/www/tileboard/
birthdays-tileboard.js content:
var bdMarriedSymbol = "mdi-cards-heart";
var bdCake = "mdi-cake-variant";
// String translations (translate these to your own language) //
var bdTextToday = "Today"; // Today
var bdTextTomorrow = "Tomorrow"; // Tomorrow
var bdTextNone = "No birthdays in the next"; // No birthdays during next
var bdTextDays = "days"; // days
var bdTextYears = "years"; // years
var bdTextIn = "in"; // in
var bdNextMonth= "";
///// BIRTHDAY REGISTRY ////////////////////////////////////////////////////
// ,s:1 at the end to add a heart as symbol
var birthdayList=[
{name:"Vasilica", day:14, month:7, year:1984},
{name:"Costel", day:17, month:7, year:1984},
{name:"Sorin R", day:26, month:7, year:1984},
{name:"costel R", day:27, month:7, year:1984},
{name:"Pisica A", day:9, month:8, year:1973},
{name:"Luca", day:4, month:9, year:2005},
{name:"Geoege", day:7, month:10, year:1973},
{name:"Gabita", day:20, month:12, year:1981},
{name:"Casatorie", day:30, month:8, year:2008, s:1},
];
//Number of days from today upcomming birthdays will be displayed - default 14
const numberOfDays = 14;
var current = new Date();
var currentMonth = current.getMonth();
var currentDay = current.getDate();
var currentYear = current.getFullYear();
var currentDayTS = new Date(currentYear, currentMonth, currentDay).getTime();
var oneDay = 24*60*60*1000;
for(var i = 0; i < birthdayList.length; i++) {
var obj = birthdayList[i];
if ( ((obj.month-1) < currentMonth) || ( ((obj.month-1) == currentMonth) && (obj.day < currentDay) ) ) {
// Birthday passed in current year - add one year to throw date to next birthday
obj.ts = new Date((currentYear+1), (obj.month-1), obj.day).getTime();
obj.aPlus = 1;
} else {
// Birthday to come current year
obj.ts = new Date(currentYear, (obj.month-1), obj.day).getTime();
obj.aPlus = 0;
}
obj.diff = Math.round( Math.abs( (currentDayTS - obj.ts)/(oneDay) ) );
if ( obj.diff > numberOfDays) { obj.ts = 0; }
}
var sortertListe = birthdayList.sort(
function(a, b){return a.ts > b.ts});
// (a, b) => (a.ts > b.ts) ? 1 : ((b.ts > a.ts) ? -1 : 0)
//);
var birthdayToday = "";
var birthdayNext = "";
var names = [];
var icons = [];
var dates = [];
for(var i = 0; i < sortertListe.length; i++) {
var obj = sortertListe[i];
if ((obj.month-1) == currentMonth){
bdNextMonth="";
} else{
bdNextMonth="next month";
}
if (obj.year > 0) {
var age = "(" + (currentYear - obj.year + obj.aPlus) + " " + bdTextYears + ")";
} else {
var age = "";
}
var bdSymbol = "";
if (obj.s == 1) { bdSymbol = " " + bdMarriedSymbol; }
else { bdSymbol = " " + bdCake; }
if (((obj.month-1) == currentMonth) && (obj.day == currentDay)) {
names.push(obj.name + " " + age);
icons.push(bdSymbol);
dates.push(bdTextToday);
} else if (obj.ts !== 0) {
if( obj.diff == 1) bdNextMonth = bdTextTomorrow;
else bdNextMonth = " on "+ obj.day+" "+bdNextMonth;
names.push(obj.name + " " + age);
icons.push(bdSymbol);
dates.push(bdNextMonth);
}
}
var CONFIG_bds = {
bd_name: names,
bd_date: dates,
bd_icon: icons,
}
in the tileboard index.html file we must put this line:
‘birthdays-tileboard.js’,
before line:
‘config.js’, // <----- NOT config.example.js !!
And the card is something like this:
////////////////////////birthdays
{
position: [2.2, 1],
width: 2,
type :TYPES.TEXT_LIST,
id:{},
title: 'Birthdays',
list: [0,1,2,3,4,5].map(function (id) {
return {
title: CONFIG_bds.bd_name[id],
icon: CONFIG_bds.bd_icon[id],
value: CONFIG_bds.bd_date[id]
}
})
},
the birtdays well be added in birthdays-tileboard.js, you will see where
hope is usefull for some of you guys.
p.s. not an javascript expert…