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

Commit bf00591

Browse files
committed
0.7.3 added time shift, timezone correction, hour format
1 parent d81d0f1 commit bf00591

3 files changed

Lines changed: 17 additions & 18036 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# atomic calendar card v0.7.2
1+
# atomic calendar card v0.7.3
22
Advanced calendar card for Home Assistant with Lovelace
33

44
Calendar card with advanced settings. It loads calendar events from Home Assistant - Google calendar component.
@@ -35,7 +35,7 @@ If you have any suggestions about design or functionality, please let me know, o
3535

3636
## 1. Installation
3737
1. You need to have the ![Google calendar](https://www.home-assistant.io/components/calendar.google/) component configured in Home Assistant.
38-
2. Download `atomic-calendar.js` file to `/www` directory in your Home Assistant - [latest release](https://github.com/atomic7777/atomic_calendar/releases/download/v0.7.2/atomic-calendar.js) - link not working (in development)
38+
2. Download `atomic-calendar.js` file to `/www` directory in your Home Assistant - [latest release](https://github.com/atomic7777/atomic_calendar/releases/download/v0.7.3/atomic-calendar.js) - link not working (in development)
3939
3. Add this reference to your `ui-lovelace.yaml` file:
4040
```yaml
4141
resources:
@@ -62,8 +62,8 @@ 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)
66-
65+
| hoursFormat | string | optional | v0.7.3 | `default` Custom hours format - you can set `12h` or `24h` or `default` (default for local HA language settings) or even provide your custom, like `HH:mm` or `h:mm A` - see https://devhints.io/moment for examples
66+
| startDaysAhead | integer | optional | v0.7.3 | `0` If you set more than 0, events will be loaded starting `x` days from today. For example `1` - the component will show events starting from tomorrow.
6767

6868
### Text colors and fonts
6969
| Name | Type | Since | Description |

app.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class AtomicCalendar extends LitElement {
1010

1111
let timeFormat = moment.localeData(this._hass.language).longDateFormat('LT')
1212
if (this.config.hoursFormat=='12h') timeFormat = 'h:mm A'
13-
else if (this.config.hoursFormat=='24h') timeFormat = 'hh:mm'
13+
else if (this.config.hoursFormat=='24h') timeFormat = 'H:mm'
14+
else if(this.config.hoursFormat!='default') timeFormat = this.config.hoursFormat
1415
moment.updateLocale(this._hass.language, {
1516
week: {
1617
dow: this.config.firstDayOfWeek
@@ -61,6 +62,7 @@ class AtomicCalendar extends LitElement {
6162
try {
6263
this.events = await this.getEvents()
6364
} catch (error) {
65+
console.log(error)
6466
this.errorMessage = 'The calendar can\'t be loaded from Home Assistant component'
6567
}
6668

@@ -405,7 +407,7 @@ class AtomicCalendar extends LitElement {
405407
showDate: false,
406408
dateFormat: 'LL',
407409
hoursFormat: 'default', // 12h / 24h / default time format. Default is HA language setting.
408-
410+
startDaysAhead: 0, // shows the events starting on x days from today. Default 0.
409411

410412
// color and font settings
411413
dateColor: 'var(--primary-text-color)', // Date text color (left side)
@@ -673,8 +675,11 @@ class AtomicCalendar extends LitElement {
673675
*
674676
*/
675677
async getEvents() {
676-
let start = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss');
677-
let end = moment().add(this.config.maxDaysToShow, 'days').format('YYYY-MM-DDTHH:mm:ss');
678+
679+
680+
let timeOffset = new Date().getTimezoneOffset()
681+
let start = moment().add(this.config.startDaysAhead, 'days').startOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
682+
let end = moment().add((this.config.maxDaysToShow + this.config.startDaysAhead), 'days').endOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
678683
let calendarUrlList = this.config.entities.map(entity =>
679684
`calendars/${entity.entity}?start=${start}Z&end=${end}Z`)
680685
try {
@@ -713,8 +718,9 @@ class AtomicCalendar extends LitElement {
713718
*/
714719
getCalendarEvents(startDay, endDay, monthToGet, month) {
715720
this.refreshCalEvents = false
716-
let start = moment(startDay).startOf('day').format('YYYY-MM-DDTHH:mm:ss');
717-
let end = moment(endDay).endOf('day').format('YYYY-MM-DDTHH:mm:ss');
721+
let timeOffset = new Date().getTimezoneOffset()
722+
let start = moment(startDay).startOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
723+
let end = moment(endDay).endOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
718724
// calendarUrlList[url, type of event configured for this callendar,filters]
719725
let calendarUrlList = []
720726
this.config.entities.map(entity => {

0 commit comments

Comments
 (0)