diff --git a/lib/agent/dave-presence.mjs b/lib/agent/dave-presence.mjs index 5dee4eb..c069f0f 100644 --- a/lib/agent/dave-presence.mjs +++ b/lib/agent/dave-presence.mjs @@ -78,8 +78,12 @@ export class DavePresence { const profile = this.profileStore?.getAgentProfile(); if (!profile) return this._result(false, 'profile_missing'); - const timezone = profile.timezone || this.fallbackTimezone; - const clock = localClock(now, timezone); + let timezone = profile.timezone || this.fallbackTimezone; + let clock = localClock(now, timezone); + if (!clock && timezone !== this.fallbackTimezone) { + timezone = this.fallbackTimezone; + clock = localClock(now, timezone); + } if (!clock) return this._result(false, 'invalid_timezone'); this._rollDay(clock.day); if (this.state.sentCount >= this.maxPerDay) return this._result(false, 'daily_limit'); diff --git a/test/dave-presence.test.mjs b/test/dave-presence.test.mjs index a5decb9..830154b 100644 --- a/test/dave-presence.test.mjs +++ b/test/dave-presence.test.mjs @@ -89,3 +89,11 @@ test('local clock uses the profile timezone', () => { assert.deepEqual(localClock(new Date('2026-07-06T12:30:00Z'), 'Europe/Berlin'), { day: '2026-07-06', time: '14:30' }); assert.equal(localClock(new Date(), 'Invalid/Timezone'), null); }); + +test('invalid profile timezone falls back to configured operational timezone', async () => { + const { presence, messages, calls } = setup({ profile: { timezone: 'not-a-timezone' } }); + const outcome = await presence.tick(new Date('2026-07-06T12:00:00Z')); + assert.equal(outcome.reason, 'sent'); + assert.equal(messages.length, 1); + assert.match(calls[0].prompt, /timezone: UTC/); +});