Skip to content

Commit 6ed3762

Browse files
committed
fix(web): show charging finish time in browser local time
The "Expected Finish Time" was formatted server-side with Timex.local/1, which uses the server's timezone (UTC in typical Docker deployments) rather than the user's. Render the UTC instant as ISO-8601 and convert it client-side with a new LocalDateTime hook, matching the existing pattern used by the Scheduled Charging row.
1 parent a115cc9 commit 6ed3762

3 files changed

Lines changed: 47 additions & 25 deletions

File tree

assets/js/hooks.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ export const LocalTime = {
4343
},
4444
};
4545

46+
export const LocalDateTime = {
47+
render() {
48+
const dateStr = this.el.dataset.date;
49+
const date = toLocalDate(dateStr, {
50+
year: "numeric",
51+
month: "2-digit",
52+
day: "2-digit",
53+
});
54+
const time = toLocalTime(dateStr);
55+
this.el.innerText = `${date}, ${time}`;
56+
},
57+
58+
mounted() {
59+
this.render();
60+
},
61+
62+
updated() {
63+
this.render();
64+
},
65+
};
66+
4667
export const LocalTimeRange = {
4768
exec() {
4869
const date = toLocalDate(this.el.dataset.startDate, {

lib/teslamate_web/live/car_live/summary.html.heex

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,7 @@
237237
<% current_time = Timex.now()
238238

239239
finish_time =
240-
Timex.add(current_time, Timex.Duration.from_hours(@summary.time_to_full_charge))
241-
242-
local_finish_time = Timex.local(finish_time)
243-
244-
formatted_finish_time =
245-
Timex.format!(local_finish_time, "%Y-%m-%d %H:%M:%S", :strftime) %>
240+
Timex.add(current_time, Timex.Duration.from_hours(@summary.time_to_full_charge)) %>
246241
<tr>
247242
<td class="has-text-weight-medium"><%= gettext("Remaining Time") %></td>
248243
<td>
@@ -254,7 +249,13 @@
254249
</tr>
255250
<tr>
256251
<td class="has-text-weight-medium"><%= gettext("Expected Finish Time") %></td>
257-
<td><%= formatted_finish_time %></td>
252+
<td>
253+
<%= tag(:span,
254+
data: [date: finish_time |> DateTime.to_iso8601()],
255+
phx_hook: "LocalDateTime",
256+
id: "expected_finish_time_#{@car.id}"
257+
) %>
258+
</td>
258259
</tr>
259260
<% end %>
260261
<%= unless is_nil(@summary.ideal_battery_range_km) do %>

priv/gettext/default.pot

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ msgstr ""
1515
msgid "Status"
1616
msgstr ""
1717

18-
#: lib/teslamate_web/live/car_live/summary.html.heex:374
18+
#: lib/teslamate_web/live/car_live/summary.html.heex:375
1919
#, elixir-autogen, elixir-format
2020
msgid "Speed"
2121
msgstr ""
2222

23-
#: lib/teslamate_web/live/car_live/summary.html.heex:364
23+
#: lib/teslamate_web/live/car_live/summary.html.heex:365
2424
#, elixir-autogen, elixir-format
2525
msgid "State of Charge"
2626
msgstr ""
2727

28-
#: lib/teslamate_web/live/car_live/summary.html.heex:298
28+
#: lib/teslamate_web/live/car_live/summary.html.heex:299
2929
#, elixir-autogen, elixir-format
3030
msgid "Charged"
3131
msgstr ""
@@ -87,7 +87,7 @@ msgstr ""
8787
msgid "Settings"
8888
msgstr ""
8989

90-
#: lib/teslamate_web/live/car_live/summary.html.heex:313
90+
#: lib/teslamate_web/live/car_live/summary.html.heex:314
9191
#, elixir-autogen, elixir-format
9292
msgid "Scheduled Charging"
9393
msgstr ""
@@ -97,7 +97,7 @@ msgstr ""
9797
msgid "Plugged In"
9898
msgstr ""
9999

100-
#: lib/teslamate_web/live/car_live/summary.html.heex:325
100+
#: lib/teslamate_web/live/car_live/summary.html.heex:326
101101
#, elixir-autogen, elixir-format
102102
msgid "Charge Limit"
103103
msgstr ""
@@ -226,17 +226,17 @@ msgstr ""
226226
msgid "Driver present"
227227
msgstr ""
228228

229-
#: lib/teslamate_web/live/car_live/summary.html.heex:459
229+
#: lib/teslamate_web/live/car_live/summary.html.heex:460
230230
#, elixir-autogen, elixir-format
231231
msgid "cancel sleep attempt"
232232
msgstr ""
233233

234-
#: lib/teslamate_web/live/car_live/summary.html.heex:450
234+
#: lib/teslamate_web/live/car_live/summary.html.heex:451
235235
#, elixir-autogen, elixir-format
236236
msgid "try to sleep"
237237
msgstr ""
238238

239-
#: lib/teslamate_web/live/car_live/summary.html.heex:285
239+
#: lib/teslamate_web/live/car_live/summary.html.heex:286
240240
#, elixir-autogen, elixir-format
241241
msgid "Range (est.)"
242242
msgstr ""
@@ -256,12 +256,12 @@ msgstr ""
256256
msgid "Vehicle must be locked"
257257
msgstr ""
258258

259-
#: lib/teslamate_web/live/car_live/summary.html.heex:265
259+
#: lib/teslamate_web/live/car_live/summary.html.heex:266
260260
#, elixir-autogen, elixir-format
261261
msgid "Range (rated)"
262262
msgstr ""
263263

264-
#: lib/teslamate_web/live/car_live/summary.html.heex:304
264+
#: lib/teslamate_web/live/car_live/summary.html.heex:305
265265
#, elixir-autogen, elixir-format
266266
msgid "Charger Power"
267267
msgstr ""
@@ -286,7 +286,7 @@ msgstr ""
286286
msgid "rated"
287287
msgstr ""
288288

289-
#: lib/teslamate_web/live/car_live/summary.html.heex:264
289+
#: lib/teslamate_web/live/car_live/summary.html.heex:265
290290
#, elixir-autogen, elixir-format
291291
msgid "Range (ideal)"
292292
msgstr ""
@@ -311,17 +311,17 @@ msgstr ""
311311
msgid "Delete '%{geo_fence}'?"
312312
msgstr ""
313313

314-
#: lib/teslamate_web/live/car_live/summary.html.heex:399
314+
#: lib/teslamate_web/live/car_live/summary.html.heex:400
315315
#, elixir-autogen, elixir-format
316316
msgid "Inside Temperature"
317317
msgstr ""
318318

319-
#: lib/teslamate_web/live/car_live/summary.html.heex:387
319+
#: lib/teslamate_web/live/car_live/summary.html.heex:388
320320
#, elixir-autogen, elixir-format
321321
msgid "Outside Temperature"
322322
msgstr ""
323323

324-
#: lib/teslamate_web/live/car_live/summary.html.heex:424
324+
#: lib/teslamate_web/live/car_live/summary.html.heex:425
325325
#: lib/teslamate_web/live/settings_live/index.html.heex:374
326326
#, elixir-autogen, elixir-format
327327
msgid "Version"
@@ -337,7 +337,7 @@ msgstr ""
337337
msgid "Unlocked"
338338
msgstr ""
339339

340-
#: lib/teslamate_web/live/car_live/summary.html.heex:247
340+
#: lib/teslamate_web/live/car_live/summary.html.heex:242
341341
#, elixir-autogen, elixir-format
342342
msgid "Remaining Time"
343343
msgstr ""
@@ -390,7 +390,7 @@ msgstr ""
390390
msgid "Reduced Battery Range"
391391
msgstr ""
392392

393-
#: lib/teslamate_web/live/car_live/summary.html.heex:358
393+
#: lib/teslamate_web/live/car_live/summary.html.heex:359
394394
#, elixir-autogen, elixir-format
395395
msgid "≈ %{range} at 100%"
396396
msgstr ""
@@ -524,7 +524,7 @@ msgstr ""
524524
msgid "Continue"
525525
msgstr ""
526526

527-
#: lib/teslamate_web/live/car_live/summary.html.heex:412
527+
#: lib/teslamate_web/live/car_live/summary.html.heex:413
528528
#, elixir-autogen, elixir-format
529529
msgid "Mileage"
530530
msgstr ""
@@ -646,7 +646,7 @@ msgstr ""
646646
msgid "Dog mode is enabled"
647647
msgstr ""
648648

649-
#: lib/teslamate_web/live/car_live/summary.html.heex:256
649+
#: lib/teslamate_web/live/car_live/summary.html.heex:251
650650
#, elixir-autogen, elixir-format
651651
msgid "Expected Finish Time"
652652
msgstr ""

0 commit comments

Comments
 (0)