Skip to content

Fix "time by azimuth" crash: Cannot read properties of undefined (reading 'latitude') - #565

Open
b3nj1 wants to merge 2 commits into
rdmtc:masterfrom
b3nj1:fix/time-by-azimuth-561
Open

Fix "time by azimuth" crash: Cannot read properties of undefined (reading 'latitude')#565
b3nj1 wants to merge 2 commits into
rdmtc:masterfrom
b3nj1:fix/time-by-azimuth-561

Conversation

@b3nj1

@b3nj1 b3nj1 commented Aug 15, 2026

Copy link
Copy Markdown

Summary

Fixes #561 and #557 — every use of "time by azimuth" (the time-inject node's schedule type, and the node editor's live preview for that field) throws:

Error "Cannot read properties of undefined (reading 'latitude')", could not evaluate pdsTimeByAzimuth.<value>

While testing this, found and fixed the same class of bug for "time by elevation" (#466).

Root cause 1: _getSunTimeByAzimuth crash (#561, #557)

_getSunTimeByAzimuth(dNow, azimuthAngle, degree, tprop, latitude, longitude) takes a degree parameter ahead of tprop, but its only caller (getPropValue()'s pdsTimeByAzimuth case) calls it as this._getSunTimeByAzimuth(dNow, parseFloat(data.value), data) — 3 arguments. That leaves tprop undefined inside the function, so tprop.latitude throws a TypeError. This has apparently been present since degree was added back in 2022, but only reached users once 3.0.1 became the first non-alpha/beta release on npm (2026-06-24), which lines up with reports of this breaking around end of June.

The fix drops the unused degree parameter and derives it from this.angleType, the same way the sibling _getSunTimeByElevation() already does — no caller needs to change.

Root cause 2: getDateOfText mangles Date input (surfaced by fixing #1)

Once the crash above is fixed, getTimeProp()'s generic fallback branch (used by pdsTimeByAzimuth, which has no dedicated branch there) still produced a wrong date: it passes the Date object returned by getPropValue() into dateTimeHelper.getDateOfText(), which round-trips any object input through String() and re-parses it — silently discarding the date portion and keeping only the time of day. getDateOfText() now returns a Date it's given as-is instead of re-stringifying it.

Root cause 3: getTimeProp generic branch mishandles pdsTimeByElevation* results (#466)

getTimeProp() has no dedicated branch for pdsTimeByElevation/pdsTimeByElevationRise/pdsTimeByElevationSet/pdsTimeByElevationNext either, so they also fall through to the generic branch. Unlike azimuth, getPropValue() returns a full ISunTimeSingle object ({value: Date, name, ts, ...}) for the Rise/Set/Next variants — passing that into getDateOfText() stringifies it to "[object Object]" and throws, reproducing #466 ("Error using inject with 'next rise time by elevation': could not evaluate pdsTimeByElevationRise"). The generic branch now unwraps res.value when it's already a valid Date, before falling back to getDateOfText().

Test plan

🤖 Generated with Claude Code

https://claude.ai/code/session_01UJCVNfqxyRfmyJZKAVWjCG

b3nj1 and others added 2 commits August 14, 2026 17:14
…ding 'latitude')

_getSunTimeByAzimuth() took a `degree` parameter ahead of `tprop`, but its
only caller (getPropValue()'s pdsTimeByAzimuth case) never passed it,
so `tprop` was actually undefined inside the function and any access to
`tprop.latitude` threw. This broke every "time by azimuth" use of the
time-inject node (main schedule and node-editor preview) as soon as a
stable 3.0.x release reached npm.

Drop the unused `degree` parameter and derive it from `this.angleType`,
matching the equivalent _getSunTimeByElevation() implementation.

Also fix dateTimeHelper.getDateOfText() to return a Date it is given
as-is instead of round-tripping it through String()/getTimeOfText(),
which silently discarded the date portion and only kept the time of
day. This surfaced once the crash above was fixed: pdsTimeByAzimuth
(and pdsTimeByElevation, which shares the same code path) return a
Date object from getPropValue(), and getTimeProp()'s generic branch
passes that Date through getDateOfText().

Fixes rdmtc#561, rdmtc#557.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJCVNfqxyRfmyJZKAVWjCG
)

getTimeProp() has no dedicated branch for pdsTimeByElevation,
pdsTimeByElevationRise/Set/Next, so they fell through to the generic
branch, which passes whatever getPropValue() returns into
getDateOfText(). getPropValue() returns an ISunTimeSingle object
({value: Date, name, ts, ...}) for the Rise/Set/Next variants, and
getDateOfText() stringifies non-Date objects before parsing them,
turning it into "[object Object]" and throwing - reproducing rdmtc#466
("Error using inject with 'next rise time by elevation': could not
evaluate pdsTimeByElevationRise").

Unwrap the Date from such result objects before falling back to
getDateOfText(), the same way the existing pdsTime/pdmTime branches
already do via Object.assign(result, ...).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJCVNfqxyRfmyJZKAVWjCG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

internal error sun-position

1 participant