From 9cb74e22f61116b01395f649ce5c7fc59a33204a Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 13 Sep 2026 21:38:20 +0200 Subject: [PATCH] fix(dawarich): a stay's length was sixty times too short Dawarich's `duration` is minutes. It writes the column as `duration_minutes = ((ended_at - started_at) / 60).to_i` in `app/services/visits/create.rb` and serialises it straight through; the merge service rounds the same way. TREK read it as seconds and divided by sixty again, so an eighteen-minute stop reached the suggestion panel as "0 min" and an afternoon somewhere as "2 min". Found by connecting a real Dawarich 1.14.5 and comparing: a visit spanning 11:00:00 to 11:18:45 reports `duration: 18`. The span between the two timestamps is what the panel uses now. It agrees with the arrival and departure shown beside it and it survives whatever unit a future Dawarich picks; the reported figure only stands in when `ended_at` could not be parsed, and is read as minutes there too. --- .../src/nest/integrations/dawarich.helpers.ts | Bin 19215 -> 19897 bytes .../tests/unit/nest/dawarich.helpers.test.ts | 13 ++++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/nest/integrations/dawarich.helpers.ts b/server/src/nest/integrations/dawarich.helpers.ts index 0285e252383bc3c871ab4384d563913b0c0e148b..f00218024d75dd32988c747e24ec36c0d499428b 100644 GIT binary patch delta 985 zcmY*YJ!{-R6vTlvA%!6hCcYw%YhoK)It4oznZ!jtAcajxoHE?)N$;cuX;s5l(6~uBB>y(QDe>WtDS27LE?dI$>P+ z*`t_VjrJm^$8tha-2#YZ)5Mm|TxM+JxwO*RI5R99M`k)9p>o0&SQ#lQ`GXBL!rDLw z9jr4#7NzUaTxoP$l&67e&8A>~&qEUqFjP3OqGsyEBBIYM@+F43n;D%bmvagFJ>Yaf zR(^L261OGfWX%U;HHZ=W&dlntA0A|ML!h3OoQF=0P+YCW8jc8s!!QzVibev)@h(;F8lvD*JNje(gBd7g3 zIZ2O>!K%>)GOi6vDLI)$fO-PA0exrW2gy}_bG?1>;9*#mbVN-_F*u18oYE&0!n@gb}4BtvK~sV~M?fp1G)6#xG12g<%-n zNmm9Lg)tJxLAab7B&r3DEp_L+S=a@zgWIU|Xr->;_Ob&U`_`>OJ3+HHTwNzS=M1+! zp@{qdy-ZMiCJWy~t7_2$BFH{JQu%QdP3|&2L6R)sTPvm&lF{eYPX@1J|0KM~_ccCW wzZIZ-5(a5T4bj=^+hBhyEYtfsdlw$BT|mVu89dtz8+)OiD5cTO&%v+wKaKcD+5i9m delta 341 zcma)%y-veG5QG&(MUN0t5)Dlt5yEkk0?F_M(9lw3gID+@`_8)E!_YuWM`4L3PXHBC zD&CGGKTT-pc1E9OcE0DGxA)H1{9ymiSyAM{lNx7lIO<#$pNH2w*;?Qz%V0xUVldbS zae*-||F|QhZQ4D4nQn5YFalYHBh;dvsXE0hCx zDjRwd(7k6CG)9Xhrj3J|ibbiaV@cr}3(JoR-E}b9KKHt}n?L?JDHbBmx*{#kybCrz V*$zlB84s7(dHc~DEz { expect(normalizeVisit(visit({ status: null }))?.status).toBe('suggested'); }); - it('DAWARICH-VISIT-007: a positive duration is read as seconds', () => { + it('DAWARICH-VISIT-007: the span between the timestamps is the length, whatever duration says', () => { + // 18:30 to 20:00. The reported figure is ignored while there are two usable + // timestamps, because that is the pair shown beside it in the panel. It used + // to win and to be read as seconds, which divided Dawarich's minutes by sixty + // a second time and turned an eighteen-minute stop into "0 min". expect(normalizeVisit(visit({ duration: 5400 }))?.durationMinutes).toBe(90); - expect(normalizeVisit(visit({ duration: '120' }))?.durationMinutes).toBe(2); + expect(normalizeVisit(visit({ duration: '120' }))?.durationMinutes).toBe(90); + expect(normalizeVisit(visit({ duration: 18 }))?.durationMinutes).toBe(90); }); it('DAWARICH-VISIT-008: a missing or zero duration is recomputed from the two timestamps', () => { @@ -385,7 +390,9 @@ describe('normalizeVisit', () => { it('DAWARICH-VISIT-016: an unreadable end falls back to the reported duration', () => { // With a duration to go on, the end is the arrival plus that span — which is // what the stay actually was, and what the two timestamps then agree on. - const result = normalizeVisit(visit({ duration: 1800, ended_at: 'sometime' })); + // Minutes: Dawarich writes `duration_minutes = ((ended_at - started_at) / 60)` + // into this column (app/services/visits/create.rb). + const result = normalizeVisit(visit({ duration: 30, ended_at: 'sometime' })); expect(Date.parse(result!.endedAt) - Date.parse(result!.startedAt)).toBe(1_800_000); expect(result?.durationMinutes).toBe(30); });