Skip to content

Commit f57d757

Browse files
KAMI911claude
andcommitted
feat(calendarium@kami911): use primary location timezone for Sun/Moon times
The primary-location sunrise/sunset and moonrise/moonset calculations called Sun.getSunTimes()/getMoonTimes() without a UTC offset, so they were always rendered in the computer's system timezone even when the primary location sits in a different one (e.g. Marmaris, Turkey on a CET machine). Add a "primary-tz" IANA timezone setting, populated automatically by the city search (alongside latitude/longitude) just like the additional cities. When set, its current UTC offset is passed to the Sun/Moon calculations; when empty the behaviour is unchanged and the system timezone is used. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PNasJnrStmVjJgJ8MULzcG
1 parent 15a6335 commit f57d757

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

calendarium@kami911/files/calendarium@kami911/desklet.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ CalendariumDesklet.prototype = {
171171
() => this._onLocationSearchChanged());
172172
s.bind("latitude", "latitude", cb);
173173
s.bind("longitude", "longitude", cb);
174+
s.bind("primary-tz", "primary_tz", cb);
174175
s.bind("city1-name", "city1_name",
175176
() => this._onCityNameChanged(1));
176177
s.bind("city1-lat", "city1_lat", cb);
@@ -281,6 +282,7 @@ CalendariumDesklet.prototype = {
281282
let r = results[0];
282283
self.settings.setValue("latitude", r.lat);
283284
self.settings.setValue("longitude", r.lon);
285+
self.settings.setValue("primary-tz", r.tz || "");
284286
self.settings.setValue("use-manual-location", true);
285287
return false;
286288
});
@@ -320,6 +322,16 @@ CalendariumDesklet.prototype = {
320322
}
321323
},
322324

325+
/**
326+
* UTC offset in hours to use for the primary location's Sun/Moon times.
327+
* Uses the explicitly configured IANA timezone when set; otherwise returns
328+
* null so the calculations fall back to the computer's system timezone
329+
* (the default behaviour).
330+
*/
331+
_getPrimaryUtcOffsetHours: function() {
332+
return this._getCityUtcOffsetHours(this.primary_tz);
333+
},
334+
323335
/**
324336
* Format a UTC offset in hours as a "UTC±H" or "UTC±H:MM" string.
325337
*/
@@ -1105,7 +1117,7 @@ CalendariumDesklet.prototype = {
11051117
// Primary location
11061118
let lat = this.use_manual_location ? this.latitude : DEFAULT_LAT;
11071119
let lon = this.use_manual_location ? this.longitude : DEFAULT_LON;
1108-
let sun = Sun.getSunTimes(now, lat, lon);
1120+
let sun = Sun.getSunTimes(now, lat, lon, this._getPrimaryUtcOffsetHours());
11091121

11101122
let sunriseStr = this._sunStr(sun, "sunrise");
11111123
let sunsetStr = this._sunStr(sun, "sunset");
@@ -1250,7 +1262,7 @@ CalendariumDesklet.prototype = {
12501262

12511263
let lat = this.use_manual_location ? this.latitude : DEFAULT_LAT;
12521264
let lon = this.use_manual_location ? this.longitude : DEFAULT_LON;
1253-
let mt = Sun.getMoonTimes(now, lat, lon);
1265+
let mt = Sun.getMoonTimes(now, lat, lon, this._getPrimaryUtcOffsetHours());
12541266

12551267
let riseStr = mt.moonrise || _("No data");
12561268
let setStr = mt.moonset || _("No data");

calendarium@kami911/files/calendarium@kami911/po/calendarium@kami911.pot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,17 @@ msgstr ""
683683
msgid "Longitude (positive = East)"
684684
msgstr ""
685685

686+
#. settings-schema.json->primary-tz->description
687+
msgid "Primary location timezone (IANA, e.g. Europe/Budapest)"
688+
msgstr ""
689+
690+
#. settings-schema.json->primary-tz->tooltip
691+
msgid ""
692+
"Timezone used for the primary location's sunrise/sunset and moonrise/moonset "
693+
"times. Filled automatically when using city search. Leave empty to use the "
694+
"computer's system timezone."
695+
msgstr ""
696+
686697
#. settings-schema.json->city1-name->description
687698
msgid "City 1 name (leave empty to disable)"
688699
msgstr ""

calendarium@kami911/files/calendarium@kami911/po/hu.po

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,20 @@ msgstr "Szélességi fok (pozitív = Észak)"
700700
msgid "Longitude (positive = East)"
701701
msgstr "Hosszúsági fok (pozitív = Kelet)"
702702

703+
#. settings-schema.json->primary-tz->description
704+
msgid "Primary location timezone (IANA, e.g. Europe/Budapest)"
705+
msgstr "Elsődleges helyszín időzónája (IANA, pl. Europe/Budapest)"
706+
707+
#. settings-schema.json->primary-tz->tooltip
708+
msgid ""
709+
"Timezone used for the primary location's sunrise/sunset and moonrise/moonset "
710+
"times. Filled automatically when using city search. Leave empty to use the "
711+
"computer's system timezone."
712+
msgstr ""
713+
"Az elsődleges helyszín nap- és holdkelte/-nyugta időpontjaihoz használt "
714+
"időzóna. A városkereső használatakor automatikusan kitöltődik. Üresen hagyva a "
715+
"számítógép rendszeridőzónája lesz érvényes."
716+
703717
#. settings-schema.json->city1-name->description
704718
msgid "City 1 name (leave empty to disable)"
705719
msgstr "1. város neve (üresen hagyva kikapcsolt)"

calendarium@kami911/files/calendarium@kami911/settings-schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"keys": [
9595
"use-manual-location",
9696
"location-search",
97-
"latitude", "longitude",
97+
"latitude", "longitude", "primary-tz",
9898
"city1-name", "city1-lat", "city1-lon", "city1-tz",
9999
"city2-name", "city2-lat", "city2-lon", "city2-tz",
100100
"city3-name", "city3-lat", "city3-lon", "city3-tz",
@@ -386,6 +386,14 @@
386386
"dependency": "use-manual-location",
387387
"indent": true
388388
},
389+
"primary-tz": {
390+
"type": "entry",
391+
"default": "",
392+
"description": "Primary location timezone (IANA, e.g. Europe/Budapest)",
393+
"tooltip": "Timezone used for the primary location's sunrise/sunset and moonrise/moonset times. Filled automatically when using city search. Leave empty to use the computer's system timezone.",
394+
"dependency": "use-manual-location",
395+
"indent": true
396+
},
389397
"city1-name": {
390398
"type": "entry",
391399
"default": "",

0 commit comments

Comments
 (0)