Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new time zone (local/server time) feature released in 2023.7 #579

Closed
jrb80 opened this issue Jul 6, 2023 · 25 comments
Closed

Support new time zone (local/server time) feature released in 2023.7 #579

jrb80 opened this issue Jul 6, 2023 · 25 comments
Labels

Comments

@jrb80
Copy link

jrb80 commented Jul 6, 2023

HA have just released an awesome new feature in 2023.7 which provides the option to select how you display time on the UI, either using the local time (default) or the server time (new). This is incredibly useful if the HA instance is in another country/time zone or if you are travelling abroad.

However, my initial testing suggests this feature isn't supported by this custom card. I show an example below showing the Apex Chart and HA History card using the server time option. The HA History (bottom) card is correctly displaying the server time, whereas the Apex Chart is still using the local client time.

image

@jrb80 jrb80 added the bug Something isn't working label Jul 6, 2023
@jpettitt
Copy link

jpettitt commented Jul 9, 2023

This particularly annoying if you have charts that use end of day / week / month as it currently uses the browser local time and yields confusing results.

@GitHubGoody
Copy link

+1

@Lenbok
Copy link

Lenbok commented Aug 20, 2023

I am guessing that

private _getSpanDates(): { start: Date; end: Date } {
let end = new Date();
let start = new Date(end.getTime() - this._graphSpan + 1);
// Span
if (this._config?.span?.start) {
// Just Span
const startM = moment().startOf(this._config.span.start);
start = startM.toDate();
end = new Date(start.getTime() + this._graphSpan);
} else if (this._config?.span?.end) {
const endM = moment().endOf(this._config.span.end);
end = new Date(endM.toDate().getTime() + 1);
start = new Date(end.getTime() - this._graphSpan + 1);
}
if (this._offset) {
end.setTime(end.getTime() + this._offset);
start.setTime(start.getTime() + this._offset);
}
return { start, end };
}
needs to be updated, either with an explicit property like the clock weather card guys do in https://github.com/pkissling/clock-weather-card/blob/2e536aecefabf6096a4bc048b5d61736a55c348d/src/clock-weather-card.ts#L511 or by checking the 2023.7 hass preference. I don't know any typescript/javascript so am not up for it myself.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Oct 20, 2023
@Lenbok
Copy link

Lenbok commented Oct 20, 2023

bump to keep alive

@github-actions github-actions bot removed the Stale label Oct 21, 2023
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Dec 21, 2023
@Lenbok
Copy link

Lenbok commented Dec 21, 2023

Still an issue.

@github-actions github-actions bot removed the Stale label Dec 22, 2023
@martin3000
Copy link

Discovered this today while I am in Asia and my home is in Europe.

@markcocker
Copy link

markcocker commented Feb 18, 2024

Under my HA user profile I have Time Zone set to Use server time zone (Europe/London).
When I am travelling my machine + browser changes to another time zone, eg. GMT-5. The following keeps the ApexChart card xaxis showing GMT. For details see datetimeUTC - https://apexcharts.com/docs/options/xaxis/
I set this using config_templates so all my charts take on this config.

apex_config:
  xaxis:
    labels:
      datetimeUTC: true

@martin3000
Copy link

Since I do not live in the UTC (GMT+0) time zone, this does not make sense for me.

@budisek
Copy link

budisek commented Mar 19, 2024

I've set Server time zone and add datetimeUTC: true but i need to set UTC+8 because my iOS HA app shows wrong values on apexchart. I can only change time zone on my iPhone but it is not a solution.

@DamienGdn
Copy link

+1

@jrb80
Copy link
Author

jrb80 commented Apr 4, 2024

Here is an example of the problem using the Sun2 integration. This apexchart is viewed locally, in the same timezone as the Home Assistant server. The sunrise is shown correctly
Local_View

Here is the same apexchart, viewed at the same time but from a different timezone from the Home Assistant server. You will not the sunrise is not shown correctly as the client time is used, rather than the server time
Remote_View

Copy link

github-actions bot commented Jun 4, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Jun 4, 2024
@Lenbok
Copy link

Lenbok commented Jun 4, 2024

+1 still an issue.

@github-actions github-actions bot removed the Stale label Jun 5, 2024
@NikolajChristensen
Copy link

+1 still an issue.

@RomRider
Copy link
Owner

RomRider commented Jul 4, 2024

Working on it, but it's quite painful as the apexcharts library only supports displaying in browser's localtime or UTC. But I'll get there eventually.

@RomRider RomRider added feature-request New feature or request and removed bug Something isn't working labels Jul 4, 2024
github-actions bot pushed a commit that referenced this issue Jul 4, 2024
## [2.1.0-dev.1](v2.0.4...v2.1.0-dev.1) (2024-07-04)

### Features

* Add change type for statistics ([#555](#555)) ([608fbe5](608fbe5)), closes [#552](#552)
* **statistics:** add weekly statistics period ([#680](#680)) ([e923126](e923126))
* support for server time ([55c8f97](55c8f97)), closes [#709](#709) [#579](#579)
Copy link

github-actions bot commented Jul 4, 2024

🎉 This issue has been resolved in version 2.1.0-dev.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@RomRider
Copy link
Owner

RomRider commented Jul 4, 2024

Please test this extensively with your setup as I might have missed edge cases !

github-actions bot pushed a commit that referenced this issue Jul 4, 2024
## [2.1.0-dev.2](v2.1.0-dev.1...v2.1.0-dev.2) (2024-07-04)

### Bug Fixes

* `extremas` with `time_delta` would generate wrong results ([f7ab3e8](f7ab3e8)), closes [#713](#713)
* display was wrong when using server time + serie offset ([84357f9](84357f9)), closes [#579](#579)
Copy link

github-actions bot commented Jul 4, 2024

🎉 This issue has been resolved in version 2.1.0-dev.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@Lenbok
Copy link

Lenbok commented Jul 5, 2024

This is working well for me so far, thanks!

@NikolajChristensen
Copy link

Works well here too. Much much better experience. Thanks!

@jrb80
Copy link
Author

jrb80 commented Jul 5, 2024

@RomRider it works great, I've been waiting so long for this update, many thanks! Here is the same graph comparison from the original issue report, the Apex chart correctly displays the server time, brilliant!

After

github-actions bot pushed a commit that referenced this issue Jul 9, 2024
## [2.1.0](v2.0.4...v2.1.0) (2024-07-09)

### Features

* Add change type for statistics ([#555](#555)) ([608fbe5](608fbe5)), closes [#552](#552)
* **locales:** Support for new locales ([2fca527](2fca527))
* **series:** Direct support for dashed lines ([29aad77](29aad77)), closes [#413](#413)
* **series:** hide specific serie in legend with `in_legend: false` ([12cb893](12cb893)), closes [#74](#74)
* **series:** support for `monotoneCubic` curves ([998cb99](998cb99))
* **series:** Support for stack group of columns ([2935b4e](2935b4e)), closes [#673](#673) [#550](#550)
* **statistics:** add weekly statistics period ([#680](#680)) ([e923126](e923126))
* support for server time ([55c8f97](55c8f97)), closes [#709](#709) [#579](#579)

### Bug Fixes

* `extremas` with `time_delta` would generate wrong results ([f7ab3e8](f7ab3e8)), closes [#713](#713)
* display was wrong when using server time + serie offset ([84357f9](84357f9)), closes [#579](#579)
* **series:** fix `in_legend` for apexcharts.js v3.50.0 ([221b0a5](221b0a5))
@Sammy990
Copy link

Not sure if this is my "homemade" issue, or a general one. I have a apex card for Tibber prices forecast. Since the update it now correctly uses the server time in the card, but the chart is placed wrong. It should starting the graph from midnight, but it does start much later...


type: custom:apexcharts-card
experimental:
  color_threshold: true
all_series_config:
  unit: Cent/kWh
apex_config:
  grid:
    show: true
    borderColor: '#E0E0E0'
  chart:
    height: 250px
  tooltip:
    enabled: true
    followCursor: false
    x:
      show: false
    fixed:
      enabled: true
header:
  show: true
  title: Strompreis
  show_states: true
  colorize_states: true
  standard_format: false
graph_span: 48h
now:
  show: true
  color: 9E9E9E
span:
  start: day
series:
  - entity: sensor.tibber_prices
    show:
      in_header: before_now
      name_in_header: false
    color_threshold:
      - value: 0
        color: 4DD0E1
      - value: 10
        color: 26A69A
      - value: 15
        color: 4CAF50
      - value: 20
        color: 7CB342
      - value: 25
        color: FBC02D
      - value: 30
        color: EF6C00
      - value: 40
        color: B71C1C
    type: line
    curve: stepline
    extend_to: false
    stroke_width: 4
    float_precision: 2
    data_generator: |
      const noon = new Date()
      noon.setHours(0, 0, 0, 0)
      const prices = entity.attributes.today.concat(entity.attributes.tomorrow);
      const data = [];
      for(let i = 0; i < prices.length; i++) {
        data.push([noon.getTime() + i * 1000 * 3600, prices[i].total * 100])
      }
      return data;

image

@RomRider
Copy link
Owner

Because new Date() followed by setHours uses your local time and not the server time.
Use moment.js with moment.tz instead of the date object.
Or maybe you can even use start instead.

data.push([start.getTime() + i * 1000 * 3600, prices[i].total * 100])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests