gadgetchnnel / lovelace-home-feed-card

A custom Lovelace card for displaying a combination of persistent notifications, calendar events, and entities in the style of a feed.
275 stars 24 forks source link

Fixes related timestamp #65

Open teibaz opened 3 years ago

teibaz commented 3 years ago

Hi guys, I really needed to user timestamp_property for non multi-entities. So I came up with solution to modify getItemTimestamp() with this line:

return ( item.attributes[this._config.timestamp_property] ) ? item.attributes[this._config.timestamp_property] : (item.attributes.last_changed ? item.attributes.last_changed : item.last_changed);

It would take timestamp_property from attributes if it is set one;


Another issue I had: if i use state directly from DB - it is not up to ISO standad, so I had to fix it in getFeedItems() method by these:

let timeStamp = this.getItemTimestamp(item);

// if timestamp is from SQLite state table, it's without T and timezone, so we need to fix that
if ( typeof timeStamp === 'string' && timeStamp.indexOf("T") == -1 && timeStamp.indexOf("+") == -1 ) {
    timeStamp = timeStamp.replace( " ", "T" ) + '+00:00';
}

let tsDate = new Date(timeStamp);

it would set SQLite state table value into ISO format and then everything starts working. Hope these changes might end up in the next release.