Skip to content
This repository was archived by the owner on Sep 25, 2021. It is now read-only.

Commit d81d0f1

Browse files
committed
hours format added, small fixes
1 parent e59a3ac commit d81d0f1

3 files changed

Lines changed: 18083 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ If you have any suggestions about design or functionality, please let me know, o
6262
| showLoader | boolean | optional | v0.7.0 | `true` Show animation, when events are being loaded from Google Calendar.
6363
| showDate | boolean | optional | v0.7.2 | `false` Show the date on the right side of the title
6464
| dateFormat | string | optional | v0.7.2 | `LL` Custom date format - see https://devhints.io/moment for examples
65+
| hoursFormat | string | optional | v0.7.3 | `default` Custom hours format - `12h` or `24h` or `default` (default for local HA language settings)
6566

6667

6768
### Text colors and fonts

app.js

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,33 @@ import moment from 'moment';
33
import 'moment/min/locales';
44

55
class AtomicCalendar extends LitElement {
6-
static get properties() {
76

7+
8+
set hass(hass) {
9+
this._hass=hass
10+
11+
let timeFormat = moment.localeData(this._hass.language).longDateFormat('LT')
12+
if (this.config.hoursFormat=='12h') timeFormat = 'h:mm A'
13+
else if (this.config.hoursFormat=='24h') timeFormat = 'hh:mm'
14+
moment.updateLocale(this._hass.language, {
15+
week: {
16+
dow: this.config.firstDayOfWeek
17+
},
18+
longDateFormat : {
19+
LT: timeFormat
20+
}
21+
});
22+
}
23+
24+
static get properties() {
825
return {
9-
hass: Object,
26+
_hass: {},
1027
config: Object,
1128
content: Object,
1229
selectedMonth: Object
1330
}
1431
}
15-
32+
1633
constructor() {
1734
super();
1835
this.lastCalendarUpdateTime;
@@ -34,11 +51,8 @@ class AtomicCalendar extends LitElement {
3451
updated() {}
3552

3653
render() {
37-
moment.updateLocale(this.hass.language, {
38-
week: {
39-
dow: this.config.firstDayOfWeek
40-
}
41-
});
54+
55+
4256
if (!this.isUpdating && this.modeToggle == 1) {
4357
if (!this.lastEventsUpdateTime || moment().diff(this.lastEventsUpdateTime, 'minutes') > 15)
4458
(async() => {
@@ -93,6 +107,12 @@ class AtomicCalendar extends LitElement {
93107
static get styles() {
94108

95109
}
110+
111+
firstTimeConfig() {
112+
113+
114+
}
115+
96116

97117

98118
handleToggle(e) {
@@ -384,6 +404,8 @@ class AtomicCalendar extends LitElement {
384404
showCurrentEventLine: false, // show a line between last and next event
385405
showDate: false,
386406
dateFormat: 'LL',
407+
hoursFormat: 'default', // 12h / 24h / default time format. Default is HA language setting.
408+
387409

388410
// color and font settings
389411
dateColor: 'var(--primary-text-color)', // Date text color (left side)
@@ -452,14 +474,15 @@ class AtomicCalendar extends LitElement {
452474
});
453475
}
454476

477+
455478
// The height of your card. Home Assistant uses this to automatically
456479
// distribute all cards over the available columns.
457480
getCardSize() {
458481
return this.config.entities.length + 1;
459482
}
460483

461484
_toggle(state) {
462-
this.hass.callService('homeassistant', 'toggle', {
485+
this._hass.callService('homeassistant', 'toggle', {
463486
entity_id: state.entity_id
464487
});
465488
}
@@ -656,7 +679,7 @@ class AtomicCalendar extends LitElement {
656679
`calendars/${entity.entity}?start=${start}Z&end=${end}Z`)
657680
try {
658681
return await (Promise.all(calendarUrlList.map(url =>
659-
this.hass.callApi('get', url))).then((result) => {
682+
this._hass.callApi('get', url))).then((result) => {
660683
let ev = [].concat.apply([], (result.map((singleCalEvents, i) => {
661684
return singleCalEvents.map(evt => new EventClass(evt, this.config.entities[i]))
662685
})))
@@ -702,7 +725,7 @@ class AtomicCalendar extends LitElement {
702725

703726

704727
Promise.all(calendarUrlList.map(url =>
705-
this.hass.callApi('get', url[0]))).then((result, i) => {
728+
this._hass.callApi('get', url[0]))).then((result, i) => {
706729
if (monthToGet == this.monthToGet)
707730
result.map((eventsArray, i) => {
708731
this.month.map(m => {
@@ -798,7 +821,7 @@ class AtomicCalendar extends LitElement {
798821
return html`
799822
<div class="calTitle">
800823
<a href="https://calendar.google.com/calendar/r/month/${moment(this.selectedMonth).format('YYYY')}/${moment(this.selectedMonth).format('MM')}/1" style="text-decoration: none; color: ${this.config.titleColor}" target="_blank">
801-
${moment(this.selectedMonth).locale(this.hass.language).format('MMMM')} ${moment(this.selectedMonth).format('YYYY')}
824+
${moment(this.selectedMonth).locale(this._hass.language).format('MMMM')} ${moment(this.selectedMonth).format('YYYY')}
802825
</a>
803826
</div>
804827
<div class="calButtons">
@@ -875,6 +898,7 @@ class AtomicCalendar extends LitElement {
875898
</div>
876899
`
877900
}
901+
878902
}
879903

880904

@@ -1041,4 +1065,24 @@ class EventClass {
10411065
get link() {
10421066
return this.eventClass.htmlLink
10431067
}
1068+
1069+
1070+
10441071
}
1072+
1073+
1074+
1075+
1076+
1077+
1078+
1079+
1080+
1081+
1082+
1083+
1084+
1085+
1086+
1087+
1088+

atomic-calendar.js

Lines changed: 18026 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)