signalk-wmo-gust 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project are documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## [0.4.1] - 2026-11-19
7
+
8
+ ### Added
9
+ - The onboard time zone is published as `environment.time.timezoneOffset` and `environment.time.timezoneRegion` (setting **Onboard time zone**; empty uses the server's time zone, `none` turns it off).
10
+
11
+ ### Fixed
12
+ - The wind history app shows local time on chartplotters whose browser runs on UTC, such as Garmin OneHelm: it uses the onboard time zone from Signal K.
13
+ - The app no longer shows stale data on browsers that cache requests, and reloads the charts when it comes back to the foreground.
14
+
6
15
  ## [0.4.0] - 2026-11-19
7
16
 
8
17
  ### Added
package/README.md CHANGED
@@ -130,6 +130,7 @@ Then go to **Server → Plugin Config → WMO Wind**, and enable the plugin.
130
130
  | Anemometer distance below `design.airHeight` (m) | 0.3 | Allows for the sensor sitting below the top of the mast |
131
131
  | Wind profile exponent | 0.11 | 0.11 for open sea, 0.143 for open land, 0 for no correction |
132
132
  | Publish interval (s) | 1 | How often values are published |
133
+ | Onboard time zone | empty | IANA name such as `Europe/Madrid`, published as `environment.time.timezoneOffset` and `timezoneRegion` so that displays running on UTC show local time. Empty: the server's time zone; `none`: not published |
133
134
 
134
135
  The height is re-read on every publish, so a change to `design.airHeight` takes effect without a restart.
135
136
 
package/index.js CHANGED
@@ -39,6 +39,25 @@ const DIR_MAX_AGE_MS = 5000 // a direction older than this is not paired with a
39
39
  const TWO_PI = 2 * Math.PI
40
40
  const FACTOR_PATH = 'environment.wind.heightFactorWMO'
41
41
 
42
+ /** Offset of an IANA time zone from UTC at a moment, as Signal K's (-)hhmm number, e.g. 100 or -530. */
43
+ function timezoneOffset (zone, date) {
44
+ let parts
45
+ try {
46
+ parts = new Intl.DateTimeFormat('en-GB', {
47
+ timeZone: zone, hourCycle: 'h23', year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric'
48
+ }).formatToParts(date)
49
+ } catch (e) {
50
+ return null
51
+ }
52
+ const get = (t) => Number(parts.find((p) => p.type === t).value)
53
+ const local = Date.UTC(get('year'), get('month') - 1, get('day'), get('hour'), get('minute'))
54
+ const utc = Math.floor(date.getTime() / 60000) * 60000
55
+ const min = Math.round((local - utc) / 60000)
56
+ const sign = min < 0 ? -1 : 1
57
+ const a = Math.abs(min)
58
+ return sign * (Math.floor(a / 60) * 100 + (a % 60))
59
+ }
60
+
42
61
  module.exports = function (app) {
43
62
  const plugin = {
44
63
  id: 'signalk-wmo-gust',
@@ -48,6 +67,7 @@ module.exports = function (app) {
48
67
 
49
68
  let unsubscribes = []
50
69
  let timer = null
70
+ let clockTimer = null
51
71
 
52
72
  /*
53
73
  * Published paths: the reference of the source wind, then the quantity,
@@ -111,6 +131,12 @@ module.exports = function (app) {
111
131
  type: 'number',
112
132
  title: 'Publish interval (s)',
113
133
  default: 1
134
+ },
135
+ timezone: {
136
+ type: 'string',
137
+ title: 'Onboard time zone (IANA name, e.g. Europe/Madrid)',
138
+ description: 'Published as environment.time.timezoneOffset and timezoneRegion, so that displays without their own time zone, such as Garmin OneHelm, show local time. Empty: the server\'s time zone. "none": do not publish.',
139
+ default: ''
114
140
  }
115
141
  }
116
142
  }
@@ -264,14 +290,36 @@ module.exports = function (app) {
264
290
  `${rateHz.toFixed(1)} Hz, sensor ${height.h.toFixed(1)} m (${height.src})${filling}${warn}`
265
291
  )
266
292
  }, (options.publishInterval > 0 ? options.publishInterval : 1) * 1000)
293
+
294
+ if (options.timezone !== 'none') {
295
+ const zone = options.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone
296
+ const publishClock = () => {
297
+ const off = timezoneOffset(zone, new Date())
298
+ if (off === null) return app.error(`Unknown time zone ${zone}`)
299
+ app.handleMessage(plugin.id, {
300
+ updates: [{
301
+ values: [
302
+ { path: 'environment.time.timezoneOffset', value: off },
303
+ { path: 'environment.time.timezoneRegion', value: zone }
304
+ ]
305
+ }]
306
+ })
307
+ }
308
+ publishClock()
309
+ clockTimer = setInterval(publishClock, 60000)
310
+ }
267
311
  }
268
312
 
269
313
  plugin.stop = function () {
270
314
  unsubscribes.forEach((f) => f())
271
315
  unsubscribes = []
272
316
  if (timer) clearInterval(timer)
317
+ if (clockTimer) clearInterval(clockTimer)
273
318
  timer = null
319
+ clockTimer = null
274
320
  }
275
321
 
276
322
  return plugin
277
323
  }
324
+
325
+ module.exports.timezoneOffset = timezoneOffset
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-wmo-gust",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "WMO-standard 10-minute mean wind, mean direction and 3-second gust for Signal K, with 1/3/6-hour gust maxima, and a web app charting the last 1, 3, 24 and 72 hours",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/public/index.html CHANGED
@@ -253,8 +253,21 @@
253
253
  function pad3 (n) { return ('00' + n).slice(-3) }
254
254
  function compass (rad) { return COMPASS[Math.round(deg(rad) / 22.5) % 16] }
255
255
  function two (n) { return (n < 10 ? '0' : '') + n }
256
- function hm (t) { var d = new Date(t); return two(d.getHours()) + ':' + two(d.getMinutes()) }
257
- function dm (t) { var d = new Date(t); return two(d.getDate()) + '/' + two(d.getMonth() + 1) }
256
+ // Onboard time zone from Signal K (environment.time.timezoneOffset): chartplotter
257
+ // browsers often run on UTC. Without it, the browser's own time zone is used.
258
+ var tzMs = null
259
+ function offsetAt (t) { return tzMs !== null ? tzMs : -new Date(t).getTimezoneOffset() * 60000 }
260
+ function local (t) { return new Date(t + offsetAt(t)) }
261
+ function hm (t) { var d = local(t); return two(d.getUTCHours()) + ':' + two(d.getUTCMinutes()) }
262
+ function dm (t) { var d = local(t); return two(d.getUTCDate()) + '/' + two(d.getUTCMonth() + 1) }
263
+ function loadClock () {
264
+ getJSON('/signalk/v1/api/vessels/self/environment/time', function (err, tm) {
265
+ setTimeout(loadClock, 60000)
266
+ var v = !err && tm && tm.timezoneOffset && num(tm.timezoneOffset.value) ? tm.timezoneOffset.value : null
267
+ var ms = v === null ? null : (v < 0 ? -1 : 1) * (Math.floor(Math.abs(v) / 100) * 60 + Math.abs(v) % 100) * 60000
268
+ if (ms !== tzMs) { tzMs = ms; draw() }
269
+ })
270
+ }
258
271
 
259
272
  // ---- series -------------------------------------------------------------
260
273
 
@@ -386,7 +399,7 @@
386
399
  }
387
400
 
388
401
  function timeAxis (c, r, start, end, X, yTop, yBottom, rule, muted, labels) {
389
- var off = -new Date(start).getTimezoneOffset() * 60000
402
+ var off = offsetAt(end)
390
403
  var t = Math.ceil((start + off) / r.tick) * r.tick - off
391
404
  c.textAlign = 'center'; c.textBaseline = 'top'
392
405
  for (; t <= end; t += r.tick) {
@@ -574,6 +587,7 @@
574
587
 
575
588
  syncButtons()
576
589
  draw()
590
+ loadClock()
577
591
  loadLive()
578
592
  loadHistory()
579
593
  })()