Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

split the settings-backed timezone helpers out of lib

[._.]/ Adam Eivy0ed3abb6c2b6
diff --git a/server/lib/layering.test.js b/server/lib/layering.test.js
index 06e6ad3be7..3ece89d9ef 100644
--- a/server/lib/layering.test.js
+++ b/server/lib/layering.test.js
@@ -33,7 +33,6 @@ const PREEXISTING_LIB_TO_SERVICES_ALLOWLIST = new Set([
'promptRunner.js',
'spriteValidation.js',
'stageRunner.js',
- 'timezone.js',
'tuiPromptRunner.js',
]);
diff --git a/server/lib/timezone.js b/server/lib/timezone.js
index 02dafbafd5..8aea41a023 100644
--- a/server/lib/timezone.js
+++ b/server/lib/timezone.js
@@ -6,8 +6,6 @@
* These helpers convert between UTC and the user's local timezone.
*/
-import { getSettings } from '../services/settings.js'
-
const WEEKDAY_MAP = { Sun: 0, Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6 }
// Cache Intl.DateTimeFormat instances per timezone — these are expensive to construct
@@ -32,43 +30,6 @@ function getFormatter(timezone) {
return fmt
}
-/**
- * Get the user's configured timezone, falling back to system timezone.
- * @returns {Promise<string>} IANA timezone string (e.g., 'America/Los_Angeles')
- */
-export async function getUserTimezone() {
- const settings = await getSettings()
- const tz = settings.timezone
- if (tz) {
- // Validate the configured timezone; fall back to system timezone if invalid
- try {
- new Intl.DateTimeFormat('en-US', { timeZone: tz })
- return tz
- } catch {
- console.error(`❌ Invalid configured timezone "${tz}", falling back to system default`)
- }
- }
- return Intl.DateTimeFormat().resolvedOptions().timeZone
-}
-
-/**
- * Get the UTC-ms timestamp at which the user's `timezone` setting last actually
- * changed, or null when it has never been recorded. Stamped by settings.js's
- * write path (`save()`) only when the `timezone` value genuinely differs from
- * the prior on-disk value. Timezone-dependent schedulers use this to avoid
- * replaying a slot that "occurred" under a timezone that was no longer active —
- * see catchUpMissedSlot in meatspacePostReminder.js (#2040).
- *
- * Sentinel discipline: null (not a number, ≤ 0) means "never changed / unset",
- * so callers must NOT treat absence as a floor — an unset value gates nothing.
- * @returns {Promise<number|null>} UTC ms, or null when unset.
- */
-export async function getTimezoneUpdatedAt() {
- const settings = await getSettings()
- const ts = settings.timezoneUpdatedAt
- return typeof ts === 'number' && ts > 0 ? ts : null
-}
-
/**
* Get local date/time parts for a UTC Date in the given timezone.
* @param {Date} utcDate - Date object (interpreted as UTC since TZ=UTC)
@@ -148,27 +109,6 @@ export function todayInTimezone(timezone, atDate = new Date()) {
return `${parts.year}-${String(parts.month).padStart(2, '0')}-${String(parts.day).padStart(2, '0')}`
}
-/**
- * Today's `YYYY-MM-DD` in the USER's configured timezone — the resolve-tz-then-
- * derive-today combination that every per-day feature keying off the local day
- * needs (POST daily status/streaks in meatspacePost.js & meatspacePostTraining.js,
- * the Daily Driver). Kept here (in lib) so both the scored-session service and the
- * training-log service share ONE day boundary without importing each other (they
- * already have a mutual dependency; this avoids adding to it). The process runs
- * `TZ=UTC`, so deriving the day from a bare `new Date().toISOString()` would use
- * the server's UTC day and misfile activity around the local/UTC midnight boundary
- * for non-UTC users (issue #2681).
- * Pass `atDate` (the instant a writer already captured for its timestamp) so the
- * day key derives from the SAME instant, never a fresh `new Date()` sampled after
- * the awaited settings read — which could cross midnight and split the two fields
- * onto different days (issue #2681 r5).
- * @param {Date} [atDate] - instant to key (defaults to now)
- * @returns {Promise<string>}
- */
-export async function userLocalToday(atDate = new Date()) {
- return todayInTimezone(await getUserTimezone(), atDate)
-}
-
// ---------------------------------------------------------------------------
// HH:MM time-window primitives
//
diff --git a/server/lib/timezone.test.js b/server/lib/timezone.test.js
index 0031209e9d..7399135ecd 100644
--- a/server/lib/timezone.test.js
+++ b/server/lib/timezone.test.js
@@ -7,17 +7,8 @@ vi.mock('../services/settings.js', () => ({
}))
import { getSettings } from '../services/settings.js'
-import {
- getLocalParts,
- getUtcOffsetMs,
- nextLocalTime,
- todayInTimezone,
- getTimezoneUpdatedAt,
- HHMM_RE,
- HHMM_STRICT_RE,
- parseHHMM,
- isWithinTimeWindow,
-} from './timezone.js'
+import { getLocalParts, getUtcOffsetMs, nextLocalTime, todayInTimezone, HHMM_RE, HHMM_STRICT_RE, parseHHMM, isWithinTimeWindow } from './timezone.js'
+import { getTimezoneUpdatedAt } from '../services/userTimezone.js'
describe('timezone', () => {
describe('getLocalParts', () => {
diff --git a/server/routes/cosJobRoutes.js b/server/routes/cosJobRoutes.js
index a45fec89ab..ff9325ad39 100644
--- a/server/routes/cosJobRoutes.js
+++ b/server/routes/cosJobRoutes.js
@@ -8,7 +8,7 @@ import * as autonomousJobs from '../services/autonomousJobs.js';
import { checkJobGate, hasGate, getRegisteredGates } from '../services/jobGates.js';
import { computeNextJobRun } from '../services/autonomousJobs/scheduler.js';
import { parseCronToNextRun, isValidRecurrence } from '../services/eventScheduler.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from '../services/userTimezone.js';
import { asyncHandler, ServerError, failValidation } from '../lib/errorHandler.js';
import { createCosJobSchema, updateCosJobSchema } from '../lib/validation.js';
diff --git a/server/routes/cosJobRoutes.test.js b/server/routes/cosJobRoutes.test.js
index a08f2bb4b1..51d7105aa5 100644
--- a/server/routes/cosJobRoutes.test.js
+++ b/server/routes/cosJobRoutes.test.js
@@ -41,7 +41,7 @@ vi.mock('../services/autonomousJobs/scheduler.js', () => ({
computeNextJobRun: vi.fn(),
}));
-vi.mock('../lib/timezone.js', () => ({
+vi.mock('../services/userTimezone.js', () => ({
getUserTimezone: vi.fn(),
}));
@@ -50,7 +50,7 @@ import * as autonomousJobs from '../services/autonomousJobs.js';
import { checkJobGate, hasGate, getRegisteredGates } from '../services/jobGates.js';
import { parseCronToNextRun } from '../services/eventScheduler.js';
import { computeNextJobRun } from '../services/autonomousJobs/scheduler.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from '../services/userTimezone.js';
describe('CoS Job Routes', () => {
let app;
diff --git a/server/services/activityDigest.js b/server/services/activityDigest.js
index 02514b1743..36a4e07949 100644
--- a/server/services/activityDigest.js
+++ b/server/services/activityDigest.js
@@ -22,7 +22,7 @@
import { join } from 'path';
import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
import { buildMarkers } from '../lib/markedSection.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { getDaySummary } from './humanActivity.js';
import * as journal from './brainJournal.js';
import { getPerson } from './tribe.js';
diff --git a/server/services/activityDigestScheduler.js b/server/services/activityDigestScheduler.js
index 84c9280a48..a227377f8a 100644
--- a/server/services/activityDigestScheduler.js
+++ b/server/services/activityDigestScheduler.js
@@ -18,7 +18,8 @@
* - TODAY's draft waits until the configured evening `runTime`.
*/
-import { getLocalParts, getUserTimezone, parseHHMM, todayInTimezone } from '../lib/timezone.js';
+import { getLocalParts, parseHHMM, todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { getSettings, computeCatchUpDates, runDigestForDate } from './activityDigest.js';
let schedulerInterval = null;
diff --git a/server/services/automationScheduler.js b/server/services/automationScheduler.js
index 614c632b2f..e02d9d07fc 100644
--- a/server/services/automationScheduler.js
+++ b/server/services/automationScheduler.js
@@ -11,7 +11,7 @@ import EventEmitter from 'events';
import { PATHS, createCachedStore } from '../lib/fileUtils.js';
import * as eventScheduler from './eventScheduler.js';
import * as agentActivity from './agentActivity.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const SCHEDULES_FILE = join(PATHS.agentPersonalities, 'schedules.json');
const store = createCachedStore(SCHEDULES_FILE, { schedules: {} }, { context: 'automation schedules' });
diff --git a/server/services/autonomousJobs/scheduler.js b/server/services/autonomousJobs/scheduler.js
index ca60709fa2..29e6dcf0e4 100644
--- a/server/services/autonomousJobs/scheduler.js
+++ b/server/services/autonomousJobs/scheduler.js
@@ -6,7 +6,8 @@
* creating/updating jobs and rendering the UI's interval picker.
*/
-import { getUserTimezone, getLocalParts, nextLocalTime } from '../../lib/timezone.js'
+import { getLocalParts, nextLocalTime } from '../../lib/timezone.js'
+import { getUserTimezone } from '../userTimezone.js'
import { parseCronToNextRun, parseRecurrenceToNextRun } from '../eventScheduler.js'
import { DAY } from './constants.js'
import { loadJobs } from './store.js'
diff --git a/server/services/backupScheduler.js b/server/services/backupScheduler.js
index bf7c7f5843..e9b3a5e9ec 100644
--- a/server/services/backupScheduler.js
+++ b/server/services/backupScheduler.js
@@ -11,7 +11,7 @@
import { schedule, cancel } from './eventScheduler.js';
import { getSettings, settingsEvents } from './settings.js';
import { runBackup } from './backup.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const EVENT_ID = 'backup-daily';
const DEFAULT_CRON = '0 0 * * *';
diff --git a/server/services/backupScheduler.test.js b/server/services/backupScheduler.test.js
index 98eea96360..5a098f1c78 100644
--- a/server/services/backupScheduler.test.js
+++ b/server/services/backupScheduler.test.js
@@ -43,8 +43,8 @@ vi.mock('./backup.js', () => ({
runBackup: vi.fn().mockResolvedValue({ success: true })
}));
-vi.mock('../lib/timezone.js', () => ({
- getUserTimezone: vi.fn().mockResolvedValue('UTC')
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: vi.fn().mockResolvedValue('UTC'),
}));
import { schedule, cancel } from './eventScheduler.js';
diff --git a/server/services/brainJournal.js b/server/services/brainJournal.js
index 9686db6abb..23ccf27081 100644
--- a/server/services/brainJournal.js
+++ b/server/services/brainJournal.js
@@ -30,7 +30,8 @@ import { replaceMarkedSection } from '../lib/markedSection.js';
import * as brainStorage from './brainStorage.js';
import { brainEvents, now } from './brainStorage.js';
import * as obsidian from './obsidian.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const SETTINGS_FILE = join(PATHS.brain, 'journal-settings.json');
diff --git a/server/services/brainJournal.test.js b/server/services/brainJournal.test.js
index 08eeb31f82..66c7d473dc 100644
--- a/server/services/brainJournal.test.js
+++ b/server/services/brainJournal.test.js
@@ -20,10 +20,12 @@ vi.mock('../lib/fileUtils.js', async () => {
});
vi.mock('../lib/timezone.js', () => ({
-tryReadFile: vi.fn().mockResolvedValue(null),
- getUserTimezone: () => Promise.resolve('UTC'),
+ tryReadFile: vi.fn().mockResolvedValue(null),
todayInTimezone: () => '2026-04-17',
}));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: () => Promise.resolve('UTC'),
+}));
vi.mock('./obsidian.js', () => ({
getVaultById: vi.fn(),
diff --git a/server/services/calendarSync.js b/server/services/calendarSync.js
index 3e943ba4ac..fc357cf490 100644
--- a/server/services/calendarSync.js
+++ b/server/services/calendarSync.js
@@ -2,7 +2,7 @@ import { readdir, unlink } from 'fs/promises';
import { join } from 'path';
import { atomicWrite, ensureDir, filterBySearch as genericFilterBySearch, PATHS, readJSONFile, safeDate, UUID_RE } from '../lib/fileUtils.js';
import { ServerError } from '../lib/errorHandler.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { getAccount, updateSyncStatus } from './calendarAccounts.js';
export const CACHE_DIR = join(PATHS.calendar, 'cache');
diff --git a/server/services/characterMetrics.test.js b/server/services/characterMetrics.test.js
index 6ac0016926..5a1b1ebe33 100644
--- a/server/services/characterMetrics.test.js
+++ b/server/services/characterMetrics.test.js
@@ -40,7 +40,7 @@ vi.mock('./instanceFeatures.js', () => ({
// REAL — `lib/activeDays.js` (behind the daysActive tile) derives its day keys through it, and
// a factory that dropped it would leave that tile throwing on an undefined import and reading
// `unavailable` for reasons that have nothing to do with the behavior under test.
-vi.mock('../lib/timezone.js', async (importOriginal) => ({
+vi.mock('./userTimezone.js', async (importOriginal) => ({
...(await importOriginal()),
userLocalToday: vi.fn(async () => stats.today),
getUserTimezone: vi.fn(async () => stats.timezone),
@@ -58,7 +58,7 @@ import { countAssets } from './mediaAssetIndex/db.js';
import { countWorks } from './writersRoom/local.js';
import { getPostSessions } from './meatspacePost.js';
import { getAllTrainingEntries } from './meatspacePostTraining.js';
-import { userLocalToday, getUserTimezone } from '../lib/timezone.js';
+import { userLocalToday, getUserTimezone } from './userTimezone.js';
import { isInstanceFeatureEnabled } from './instanceFeatures.js';
const goal = (status) => ({ status });
diff --git a/server/services/characterSignals.js b/server/services/characterSignals.js
index 7a7a843553..31882afdf2 100644
--- a/server/services/characterSignals.js
+++ b/server/services/characterSignals.js
@@ -43,7 +43,7 @@ import { getGoals } from './identity/goals.js';
import { countMemories } from './memoryBackend.js';
import { countAssets } from './mediaAssetIndex/db.js';
import { isInstanceFeatureEnabled } from './instanceFeatures.js';
-import { getUserTimezone, userLocalToday } from '../lib/timezone.js';
+import { getUserTimezone, userLocalToday } from './userTimezone.js';
/**
* Every domain stat the derived Character surfaces are allowed to read, keyed by signal id.
diff --git a/server/services/characterSignals.test.js b/server/services/characterSignals.test.js
index 82bfb29943..582838c0f1 100644
--- a/server/services/characterSignals.test.js
+++ b/server/services/characterSignals.test.js
@@ -26,7 +26,7 @@ vi.mock('./instanceFeatures.js', () => ({
}));
// PARTIAL mock — only the settings-backed reads are stubbed, so the pure `todayInTimezone`
// that `lib/activeDays.js` derives day keys through stays real.
-vi.mock('../lib/timezone.js', async (importOriginal) => ({
+vi.mock('./userTimezone.js', async (importOriginal) => ({
...(await importOriginal()),
userLocalToday: vi.fn(async () => '2026-07-17'),
getUserTimezone: vi.fn(async () => 'America/Los_Angeles'),
diff --git a/server/services/cos.js b/server/services/cos.js
index 14bc239453..a86fd42e7e 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -31,7 +31,8 @@ import { recordJobExecution } from './autonomousJobs.js';
import { safeJSONParse, sleep, isTopLevelEntryName } from '../lib/fileUtils.js';
import { ServerError } from '../lib/errorHandler.js';
import { addNotification, NOTIFICATION_TYPES } from './notifications.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { normalizeDomainAutonomy, getDomainMode } from '../lib/domainAutonomy.js';
import { normalizeDomainBudgets, remainingActionBudget } from '../lib/domainBudgets.js';
import { getDomainBudgetStatus } from './domainUsage.js';
diff --git a/server/services/cosJobScheduler.js b/server/services/cosJobScheduler.js
index 3fe49effb2..d8c71ebcb0 100644
--- a/server/services/cosJobScheduler.js
+++ b/server/services/cosJobScheduler.js
@@ -22,7 +22,8 @@
*/
import { schedule as scheduleEvent, cancel as cancelEvent, parseCronToNextRun, parseRecurrenceToNextRun } from './eventScheduler.js';
-import { getUserTimezone, getLocalParts, nextLocalTime } from '../lib/timezone.js';
+import { getLocalParts, nextLocalTime } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { formatDuration } from '../lib/fileUtils.js';
import { loadState, isDaemonRunning, canQueueImprovementTasks } from './cosState.js';
import { getDomainMode } from '../lib/domainAutonomy.js';
diff --git a/server/services/cosJobScheduler.test.js b/server/services/cosJobScheduler.test.js
index 269c88c27e..ed4d7145b7 100644
--- a/server/services/cosJobScheduler.test.js
+++ b/server/services/cosJobScheduler.test.js
@@ -44,10 +44,12 @@ vi.mock('./eventScheduler.js', () => ({
parseCronToNextRun: vi.fn(() => new Date(0)),
}));
vi.mock('../lib/timezone.js', () => ({
- getUserTimezone: vi.fn().mockResolvedValue('UTC'),
getLocalParts: vi.fn(() => ({ dayOfWeek: 1 })),
nextLocalTime: vi.fn((ms) => ms),
}));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: vi.fn().mockResolvedValue('UTC'),
+}));
vi.mock('../lib/fileUtils.js', async (importOriginal) => ({
...(await importOriginal()),
formatDuration: vi.fn(() => '1h'),
diff --git a/server/services/creativeCommissions/scheduler.js b/server/services/creativeCommissions/scheduler.js
index 7f9b522b11..e1cd0b93bb 100644
--- a/server/services/creativeCommissions/scheduler.js
+++ b/server/services/creativeCommissions/scheduler.js
@@ -23,7 +23,7 @@
*/
import { schedule, cancel, isValidCron, isValidRecurrence } from '../eventScheduler.js';
-import { getUserTimezone } from '../../lib/timezone.js';
+import { getUserTimezone } from '../userTimezone.js';
import { getSettings, settingsEvents } from '../settings.js';
import { RENDER_TARGET } from '../../lib/renderTargets.js';
import { renderTargetDefaults } from '../imageGen/cloudProviderConfig.js';
diff --git a/server/services/creativeCommissions/scheduler.test.js b/server/services/creativeCommissions/scheduler.test.js
index aedf3afb4c..530c869bd0 100644
--- a/server/services/creativeCommissions/scheduler.test.js
+++ b/server/services/creativeCommissions/scheduler.test.js
@@ -11,7 +11,9 @@ vi.mock('../eventScheduler.js', () => ({
isValidRecurrence: (rule) => rule?.frequency === 'weekly' && Array.isArray(rule.weekdays) && rule.weekdays.length > 0,
}));
-vi.mock('../../lib/timezone.js', () => ({ getUserTimezone: async () => 'UTC' }));
+vi.mock('../userTimezone.js', () => ({
+ getUserTimezone: async () => 'UTC',
+}));
const settingsEvents = new EventEmitter();
vi.mock('../settings.js', () => ({ settingsEvents, getSettings: async () => ({}) }));
diff --git a/server/services/dailyDriver.js b/server/services/dailyDriver.js
index 04fb1e0567..c6b3224ec9 100644
--- a/server/services/dailyDriver.js
+++ b/server/services/dailyDriver.js
@@ -13,7 +13,8 @@
import { join } from 'path';
import { atomicWrite, ensureDir, PATHS, readJSONFile } from '../lib/fileUtils.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const FILE = join(PATHS.data, 'daily-driver.json');
diff --git a/server/services/dailyDriver.test.js b/server/services/dailyDriver.test.js
index ae0857616c..1ec9597f25 100644
--- a/server/services/dailyDriver.test.js
+++ b/server/services/dailyDriver.test.js
@@ -12,9 +12,11 @@ vi.mock('../lib/fileUtils.js', () => ({
let mockToday = '2026-07-16';
vi.mock('../lib/timezone.js', () => ({
- getUserTimezone: vi.fn(async () => 'UTC'),
todayInTimezone: vi.fn(() => mockToday),
}));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: vi.fn(async () => 'UTC'),
+}));
import {
computeDriverState,
diff --git a/server/services/goalScorecard.js b/server/services/goalScorecard.js
index 766b8b9884..cd45ae8023 100644
--- a/server/services/goalScorecard.js
+++ b/server/services/goalScorecard.js
@@ -27,7 +27,8 @@
import { join } from 'path';
import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { localDayRangeUtc, localDayKey, listEvents } from './humanActivity.js';
import * as journal from './brainJournal.js';
import { buildMarkers } from '../lib/markedSection.js';
diff --git a/server/services/humanActivity.js b/server/services/humanActivity.js
index 264b28759d..03369f1478 100644
--- a/server/services/humanActivity.js
+++ b/server/services/humanActivity.js
@@ -23,7 +23,8 @@
import { v4 as uuidv4 } from '../lib/uuid.js';
import { ensureSchema, query } from '../lib/db.js';
import { normalizeIdentifier } from '../lib/tribeMatch.js';
-import { getUserTimezone, getLocalParts, getUtcOffsetMs, todayInTimezone } from '../lib/timezone.js';
+import { getLocalParts, getUtcOffsetMs, todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
// ---------------------------------------------------------------------------
// Pure helpers (exported for unit tests — no DB, no side effects).
diff --git a/server/services/imessageSync.js b/server/services/imessageSync.js
index bdc6aa8ff2..482c0a351b 100644
--- a/server/services/imessageSync.js
+++ b/server/services/imessageSync.js
@@ -25,7 +25,7 @@ import { DatabaseSync } from 'node:sqlite';
import { statSync } from 'node:fs';
import { expandHome, dataPath, atomicWrite, tryReadFile, safeJSONParse } from '../lib/fileUtils.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { identityFromHandle } from '../lib/tribeMatch.js';
import { shortSummary, localDayKey } from './humanActivity.js';
import { getSettings } from './settings.js';
diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.js
index 8abb2b0007..c8f8524aaf 100644
--- a/server/services/meatspacePost.js
+++ b/server/services/meatspacePost.js
@@ -51,7 +51,8 @@ import { applySessionToReviewSchedule, getDueReviews, getRetentionReport } from
import { getAllTrainingEntries } from './postTrainingLogStore.js';
import { getMorseProgress, MAX_KOCH_LEVEL } from './meatspacePostMorse.js';
import { computePostStreaks, computeUnifiedStreak, normalizeYmd, recordDayKey, withDerivedDayKeys, ymdToUTC, ymdShift } from '../lib/postStreak.js';
-import { getUserTimezone, todayInTimezone, userLocalToday as localToday } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone, userLocalToday as localToday } from './userTimezone.js';
import { getStoredPostSession, listPostSessions, saveStoredPostSession } from './postRunStore.js';
import { ServerError } from '../lib/errorHandler.js';
import { getPostStats } from './meatspacePostStats.js';
diff --git a/server/services/meatspacePostMemory.js b/server/services/meatspacePostMemory.js
index c8cc164645..b0aa1af91d 100644
--- a/server/services/meatspacePostMemory.js
+++ b/server/services/meatspacePostMemory.js
@@ -10,7 +10,7 @@ import { randomUUID } from 'crypto';
import { atomicWrite, PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';
import { shuffle } from '../lib/arrayUtils.js';
import { isMemoryItemEnabled } from '../lib/postTopics.js';
-import { userLocalToday } from '../lib/timezone.js';
+import { userLocalToday } from './userTimezone.js';
import {
DEFAULT_EASE,
advanceSchedule,
diff --git a/server/services/meatspacePostMorse.js b/server/services/meatspacePostMorse.js
index 7ee9b858c7..828e2c0de2 100644
--- a/server/services/meatspacePostMorse.js
+++ b/server/services/meatspacePostMorse.js
@@ -25,7 +25,8 @@
import { join } from 'path';
import { randomUUID } from 'crypto';
import { atomicWrite, PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';
-import { getUserTimezone, todayInTimezone, userLocalToday } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone, userLocalToday } from './userTimezone.js';
import { withDerivedDayKeys, ymdShift } from '../lib/postStreak.js';
const MEATSPACE_DIR = PATHS.meatspace;
diff --git a/server/services/meatspacePostRecommendations.js b/server/services/meatspacePostRecommendations.js
index c937c47dea..19eccb3e93 100644
--- a/server/services/meatspacePostRecommendations.js
+++ b/server/services/meatspacePostRecommendations.js
@@ -25,7 +25,8 @@ import { getDueMemoryItems } from './meatspacePostMemory.js';
import { getDueReviews } from './meatspacePostReview.js';
import { getAllTrainingEntries } from './postTrainingLogStore.js';
import { getMorseProgress, MAX_KOCH_LEVEL } from './meatspacePostMorse.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const RECOMMENDATION_LIMIT = 5;
const recModuleForDrillType = (type, fallback) => {
diff --git a/server/services/meatspacePostReminder.js b/server/services/meatspacePostReminder.js
index 46d2aaf9e3..2abca1eb3f 100644
--- a/server/services/meatspacePostReminder.js
+++ b/server/services/meatspacePostReminder.js
@@ -24,7 +24,8 @@
*/
import { schedule, cancel, parseCronToPrevRun } from './eventScheduler.js';
-import { getUserTimezone, getTimezoneUpdatedAt, getLocalParts, todayInTimezone, HHMM_STRICT_RE } from '../lib/timezone.js';
+import { getLocalParts, todayInTimezone, HHMM_STRICT_RE } from '../lib/timezone.js';
+import { getUserTimezone, getTimezoneUpdatedAt } from './userTimezone.js';
import { getPostConfig, getPostSessions, postConfigEvents } from './meatspacePost.js';
import { isInstanceFeatureEnabled } from './instanceFeatures.js';
import { addNotification, getNotifications, NOTIFICATION_TYPES, PRIORITY_LEVELS } from './notifications.js';
diff --git a/server/services/meatspacePostReminder.test.js b/server/services/meatspacePostReminder.test.js
index 0b8f919459..0f134308cc 100644
--- a/server/services/meatspacePostReminder.test.js
+++ b/server/services/meatspacePostReminder.test.js
@@ -37,11 +37,13 @@ vi.mock('./eventScheduler.js', () => ({
}));
vi.mock('../lib/timezone.js', () => ({
- getUserTimezone: vi.fn().mockResolvedValue('UTC'),
- getTimezoneUpdatedAt: vi.fn().mockResolvedValue(null),
getLocalParts: vi.fn(),
todayInTimezone: vi.fn(),
- HHMM_STRICT_RE: /^([01]\d|2[0-3]):[0-5]\d$/
+ HHMM_STRICT_RE: /^([01]\d|2[0-3]):[0-5]\d$/,
+}));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: vi.fn().mockResolvedValue('UTC'),
+ getTimezoneUpdatedAt: vi.fn().mockResolvedValue(null),
}));
vi.mock('./meatspacePost.js', () => ({
@@ -66,7 +68,8 @@ vi.mock('./settings.js', () => ({
}));
import { schedule, cancel, parseCronToPrevRun } from './eventScheduler.js';
-import { getUserTimezone, getTimezoneUpdatedAt, getLocalParts, todayInTimezone } from '../lib/timezone.js';
+import { getLocalParts, todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone, getTimezoneUpdatedAt } from './userTimezone.js';
import { getPostConfig, getPostSessions } from './meatspacePost.js';
import { isInstanceFeatureEnabled } from './instanceFeatures.js';
import { addNotification, getNotifications } from './notifications.js';
diff --git a/server/services/meatspacePostStats.js b/server/services/meatspacePostStats.js
index ae72545f45..fe146721de 100644
--- a/server/services/meatspacePostStats.js
+++ b/server/services/meatspacePostStats.js
@@ -7,7 +7,8 @@
import { getPostSessions, deriveTaskAccuracy, deriveTaskCompletion } from './meatspacePost.js';
import { getAllTrainingEntries } from './postTrainingLogStore.js';
import { computePostStreaks, computeUnifiedStreak, recordDayKey, ymdShift } from '../lib/postStreak.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
function trainingEntryTask(entry) {
const rawQuestionCount = Number(entry?.questionCount);
diff --git a/server/services/meatspacePostTraining.js b/server/services/meatspacePostTraining.js
index 6fe6b95152..6e128d3690 100644
--- a/server/services/meatspacePostTraining.js
+++ b/server/services/meatspacePostTraining.js
@@ -6,7 +6,8 @@
*/
import { randomUUID } from 'crypto';
-import { getUserTimezone, todayInTimezone, userLocalToday } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone, userLocalToday } from './userTimezone.js';
import { recordDayKey, ymdShift } from '../lib/postStreak.js';
import { getUnifiedActivityStreak } from './postActivityStreak.js';
import { getAllTrainingEntries } from './postTrainingLogStore.js';
diff --git a/server/services/messageSync.js b/server/services/messageSync.js
index 0dd37f5674..c66d5609e3 100644
--- a/server/services/messageSync.js
+++ b/server/services/messageSync.js
@@ -3,7 +3,8 @@ import { createHash } from 'crypto';
import { join } from 'path';
import { atomicWrite, ensureDir, filterBySearch as genericFilterBySearch, PATHS, safeDate, safeJSONParse, UUID_RE, tryReadFile } from '../lib/fileUtils.js';
import { getAccount, updateSyncStatus, markSentIngested, updateSendAsAliases } from './messageAccounts.js';
-import { getUserTimezone, getLocalParts } from '../lib/timezone.js';
+import { getLocalParts } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { v4 as uuidv4 } from '../lib/uuid.js';
import { createKeyCachedQueue } from '../lib/createKeyCachedQueue.js';
diff --git a/server/services/messageSync.test.js b/server/services/messageSync.test.js
index 6e02ce35fb..31db0652bf 100644
--- a/server/services/messageSync.test.js
+++ b/server/services/messageSync.test.js
@@ -60,7 +60,6 @@ vi.mock('./tribe.js', () => ({
// fileUtils and fail on its settings read.
let mockTimezone = 'UTC';
vi.mock('../lib/timezone.js', () => ({
- getUserTimezone: vi.fn(async () => mockTimezone),
getLocalParts: (utcDate, timezone) => {
const parts = {};
const fmt = new Intl.DateTimeFormat('en-US', {
@@ -74,6 +73,9 @@ vi.mock('../lib/timezone.js', () => ({
};
},
}));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: vi.fn(async () => mockTimezone),
+}));
import { readdir, unlink } from 'fs/promises';
import { tryReadFile as readFile, atomicWrite } from '../lib/fileUtils.js';
diff --git a/server/services/portosProductMetrics.instanceFeatures.test.js b/server/services/portosProductMetrics.instanceFeatures.test.js
index 45708e7ca0..2b534aebdd 100644
--- a/server/services/portosProductMetrics.instanceFeatures.test.js
+++ b/server/services/portosProductMetrics.instanceFeatures.test.js
@@ -16,9 +16,11 @@ vi.mock('./creativeCommissions/store.js', () => ({ listCommissions: mock.listCom
vi.mock('./creativeDirector/local.js', () => ({ getProjectsByIds: mock.getProjectsByIds }));
vi.mock('./instanceFeatures.js', () => ({ isInstanceFeatureEnabled: mock.isInstanceFeatureEnabled }));
vi.mock('../lib/timezone.js', () => ({
- getUserTimezone: mock.getUserTimezone,
todayInTimezone: mock.todayInTimezone,
}));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: mock.getUserTimezone,
+}));
import { getProductEngagement } from './portosProductMetrics.js';
diff --git a/server/services/portosProductMetrics.js b/server/services/portosProductMetrics.js
index 387372eb1b..b65eba0e57 100644
--- a/server/services/portosProductMetrics.js
+++ b/server/services/portosProductMetrics.js
@@ -15,7 +15,8 @@ import { listCommissions } from './creativeCommissions/store.js';
import { getProjectsByIds } from './creativeDirector/local.js';
import { isInstanceFeatureEnabled } from './instanceFeatures.js';
import { computeUnifiedStreak, recordDayKey, ymdShift, ymdToUTC } from '../lib/postStreak.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const DAY_MS = 24 * 60 * 60 * 1000;
const FEEDBACK_WINDOW_DAYS = 30;
diff --git a/server/services/postActivityStreak.js b/server/services/postActivityStreak.js
index 1aa80cd785..57e4ed94af 100644
--- a/server/services/postActivityStreak.js
+++ b/server/services/postActivityStreak.js
@@ -15,7 +15,8 @@
*/
import { getPostSessions } from './meatspacePost.js';
import { computeUnifiedStreak } from '../lib/postStreak.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
/**
* ONE unified activity streak across scored sessions AND the training log — the
diff --git a/server/services/postTrainingLogStore.js b/server/services/postTrainingLogStore.js
index 2d86dc724b..3d523a13db 100644
--- a/server/services/postTrainingLogStore.js
+++ b/server/services/postTrainingLogStore.js
@@ -11,7 +11,7 @@
*/
import { withDerivedDayKeys } from '../lib/postStreak.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { listStoredTrainingEntries } from './postRunStore.js';
/**
diff --git a/server/services/privacyRecheckScheduler.js b/server/services/privacyRecheckScheduler.js
index e599e82a46..aea3811978 100644
--- a/server/services/privacyRecheckScheduler.js
+++ b/server/services/privacyRecheckScheduler.js
@@ -15,7 +15,7 @@
import { schedule, cancel, parseCronToNextRun } from './eventScheduler.js';
import { getSettings } from './settings.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { runScanPass } from './privacyScan.js';
import { runOptOutPass } from './privacyOptOut.js';
import { listSubjects } from './privacySubjects.js';
diff --git a/server/services/seriesAutopilotScheduler.js b/server/services/seriesAutopilotScheduler.js
index 6de437102c..ee591ea245 100644
--- a/server/services/seriesAutopilotScheduler.js
+++ b/server/services/seriesAutopilotScheduler.js
@@ -29,7 +29,7 @@ import { schedule, cancel, isValidCron } from './eventScheduler.js';
import { getSettings, settingsEvents } from './settings.js';
import { getSeries } from './pipeline/series.js';
import { startSeriesAutopilot } from './pipeline/seriesAutopilot.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
// eventScheduler id namespace for a per-series cron. One event per seriesId.
const eventId = (seriesId) => `series-autopilot-${seriesId}`;
diff --git a/server/services/seriesAutopilotScheduler.test.js b/server/services/seriesAutopilotScheduler.test.js
index 9f52ac53ea..b8934b1463 100644
--- a/server/services/seriesAutopilotScheduler.test.js
+++ b/server/services/seriesAutopilotScheduler.test.js
@@ -20,7 +20,9 @@ vi.mock('./eventScheduler.js', () => ({
vi.mock('./settings.js', () => ({ getSettings: vi.fn(), settingsEvents: { on: vi.fn() } }));
vi.mock('./pipeline/series.js', () => ({ getSeries: vi.fn() }));
vi.mock('./pipeline/seriesAutopilot.js', () => ({ startSeriesAutopilot: vi.fn() }));
-vi.mock('../lib/timezone.js', () => ({ getUserTimezone: vi.fn().mockResolvedValue('America/Los_Angeles') }));
+vi.mock('./userTimezone.js', () => ({
+ getUserTimezone: vi.fn().mockResolvedValue('America/Los_Angeles'),
+}));
import { schedule, cancel } from './eventScheduler.js';
import { getSettings } from './settings.js';
diff --git a/server/services/signalSync.js b/server/services/signalSync.js
index 0fe55e708b..e0fb242d52 100644
--- a/server/services/signalSync.js
+++ b/server/services/signalSync.js
@@ -41,7 +41,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { expandHome, dataPath, atomicWrite, tryReadFile, safeJSONParse } from '../lib/fileUtils.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { identityFromHandle } from '../lib/tribeMatch.js';
import { decryptSqlcipherDatabase, decryptSafeStorageValue, isRawHexKey } from '../lib/signalCrypto.js';
import { shortSummary, localDayKey } from './humanActivity.js';
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index 6bfcb32298..6c9fdd5f40 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -25,7 +25,8 @@ import { mapWithConcurrency } from '../lib/mapWithConcurrency.js';
import { getAdaptiveCooldownMultiplier } from './taskLearning.js';
import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getAppTaskTypeIntervalMs, getActiveApps, getAppTaskTypeOverrides, clearAllPrWatcherState } from './apps.js';
import { loadState, isImprovementEnabled } from './cosState.js';
-import { getUserTimezone, getLocalParts } from '../lib/timezone.js';
+import { getLocalParts } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { parseCronToNextRun, parseCronToPrevRun } from './eventScheduler.js';
import { isAuditTaskType, defaultFileIssuesFor } from '../lib/auditCatalog.js';
import { DEFAULT_TASK_PROMPTS } from './taskPromptDefaults.js';
diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.js
index 3f363538c0..090a9d0da3 100644
--- a/server/services/taskSchedule.test.js
+++ b/server/services/taskSchedule.test.js
@@ -70,8 +70,10 @@ vi.mock('../lib/ports.js', () => ({
}))
vi.mock('../lib/timezone.js', () => ({
+ getLocalParts: vi.fn(() => ({ dayOfWeek: 3 })),
+}))
+vi.mock('./userTimezone.js', () => ({
getUserTimezone: vi.fn().mockResolvedValue('America/Los_Angeles'),
- getLocalParts: vi.fn(() => ({ dayOfWeek: 3 }))
}))
vi.mock('./eventScheduler.js', () => ({
diff --git a/server/services/twinEnrichment.js b/server/services/twinEnrichment.js
index cfc8679f67..8a6206b547 100644
--- a/server/services/twinEnrichment.js
+++ b/server/services/twinEnrichment.js
@@ -29,7 +29,8 @@
import { join } from 'path';
import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
import { query, ensureSchema } from '../lib/db.js';
-import { getLocalParts, getUserTimezone } from '../lib/timezone.js';
+import { getLocalParts } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { getProviderById } from './providers.js';
import { runPromptThroughProvider } from '../lib/promptRunner.js';
diff --git a/server/services/twinEnrichmentScheduler.js b/server/services/twinEnrichmentScheduler.js
index 2d087b77a2..6ff9bbb105 100644
--- a/server/services/twinEnrichmentScheduler.js
+++ b/server/services/twinEnrichmentScheduler.js
@@ -16,7 +16,8 @@
* recomputes once per local calendar day.
*/
-import { todayInTimezone, getUserTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { aggregateTwinEvidence } from './twinEnrichment.js';
let schedulerInterval = null;
diff --git a/server/services/userTimezone.js b/server/services/userTimezone.js
new file mode 100644
index 0000000000..7cfe3fc284
--- /dev/null
+++ b/server/services/userTimezone.js
@@ -0,0 +1,73 @@
+/**
+ * The user's configured timezone — the settings-backed half of the timezone
+ * helpers.
+ *
+ * These three read `settings.json`, which is why they live in services: the
+ * pure conversion primitives they build on (`todayInTimezone`, `getLocalParts`,
+ * …) stay in `lib/timezone.js`, which must not import upward into services
+ * (issue #4901). Everything here takes its timezone from settings; everything
+ * in lib takes it as an argument.
+ */
+
+import { getSettings } from './settings.js'
+import { todayInTimezone } from '../lib/timezone.js'
+
+/**
+ * Get the user's configured timezone, falling back to system timezone.
+ * @returns {Promise<string>} IANA timezone string (e.g., 'America/Los_Angeles')
+ */
+export async function getUserTimezone() {
+ const settings = await getSettings()
+ const tz = settings.timezone
+ if (tz) {
+ // Validate the configured timezone; fall back to system timezone if invalid
+ try {
+ new Intl.DateTimeFormat('en-US', { timeZone: tz })
+ return tz
+ } catch {
+ console.error(`❌ Invalid configured timezone "${tz}", falling back to system default`)
+ }
+ }
+ return Intl.DateTimeFormat().resolvedOptions().timeZone
+}
+
+/**
+ * Get the UTC-ms timestamp at which the user's `timezone` setting last actually
+ * changed, or null when it has never been recorded. Stamped by settings.js's
+ * write path (`save()`) only when the `timezone` value genuinely differs from
+ * the prior on-disk value. Timezone-dependent schedulers use this to avoid
+ * replaying a slot that "occurred" under a timezone that was no longer active —
+ * see catchUpMissedSlot in meatspacePostReminder.js (#2040).
+ *
+ * Sentinel discipline: null (not a number, ≤ 0) means "never changed / unset",
+ * so callers must NOT treat absence as a floor — an unset value gates nothing.
+ * @returns {Promise<number|null>} UTC ms, or null when unset.
+ */
+export async function getTimezoneUpdatedAt() {
+ const settings = await getSettings()
+ const ts = settings.timezoneUpdatedAt
+ return typeof ts === 'number' && ts > 0 ? ts : null
+}
+
+/**
+ * Today's `YYYY-MM-DD` in the USER's configured timezone — the
+ * resolve-tz-then-derive-today combination every per-day feature keying off the
+ * local day needs (POST daily status/streaks in meatspacePost.js &
+ * meatspacePostTraining.js, the Daily Driver). It lives in this standalone
+ * module so the scored-session service and the training-log service share ONE
+ * day boundary without importing each other — they already have a mutual
+ * dependency and this avoids adding to it.
+ *
+ * The server runs `TZ=UTC`, so deriving the day from a bare
+ * `new Date().toISOString()` would use the server's UTC day and misfile activity
+ * around the local/UTC midnight boundary for non-UTC users (issue #2681).
+ * Pass `atDate` (the instant a writer already captured for its timestamp) so the
+ * day key derives from the SAME instant, never a fresh `new Date()` sampled after
+ * the awaited settings read — which could cross midnight and split the two fields
+ * onto different days (issue #2681 r5).
+ * @param {Date} [atDate] - instant to key (defaults to now)
+ * @returns {Promise<string>}
+ */
+export async function userLocalToday(atDate = new Date()) {
+ return todayInTimezone(await getUserTimezone(), atDate)
+}
diff --git a/server/services/voice/proactiveSpeech.js b/server/services/voice/proactiveSpeech.js
index 6964319b24..80d0904ee8 100644
--- a/server/services/voice/proactiveSpeech.js
+++ b/server/services/voice/proactiveSpeech.js
@@ -19,7 +19,8 @@ import { synthesize } from './tts.js';
import { getVoiceConfig } from './config.js';
import { rememberTtsForAllSockets } from './echo.js';
import { emitVoiceOutput } from './voiceOutput.js';
-import { getUserTimezone, getLocalParts, isWithinTimeWindow } from '../../lib/timezone.js';
+import { getLocalParts, isWithinTimeWindow } from '../../lib/timezone.js';
+import { getUserTimezone } from '../userTimezone.js';
// HH:MM helpers live in server/lib/timezone.js (single source of truth shared
// with the dashboard's time-window validator). Re-exported here so the
diff --git a/server/services/voice/proactiveSpeech.test.js b/server/services/voice/proactiveSpeech.test.js
index e2cc74c2c0..cc1698733e 100644
--- a/server/services/voice/proactiveSpeech.test.js
+++ b/server/services/voice/proactiveSpeech.test.js
@@ -15,9 +15,12 @@ vi.mock('./tts.js', () => ({
// here) and override only the timezone-lookup pair the integration path needs.
vi.mock('../../lib/timezone.js', async (importOriginal) => ({
...(await importOriginal()),
- getUserTimezone: vi.fn(async () => 'UTC'),
getLocalParts: vi.fn(() => ({ hour: 14, minute: 0 })),
}));
+vi.mock('../userTimezone.js', async (importOriginal) => ({
+ ...(await importOriginal()),
+ getUserTimezone: vi.fn(async () => 'UTC'),
+}));
const {
parseHHMM,
@@ -245,7 +248,8 @@ describe('speakProactive', () => {
// called. Skipping them removes a settings-file read + Intl call per
// proactive line and one async failure surface.
it('does not resolve local time when quiet hours are disabled', async () => {
- const { getUserTimezone, getLocalParts } = await import('../../lib/timezone.js');
+ const { getLocalParts } = await import('../../lib/timezone.js');
+ const { getUserTimezone } = await import('../userTimezone.js');
getUserTimezone.mockClear();
getLocalParts.mockClear();
const { io } = makeIo();
@@ -257,7 +261,8 @@ describe('speakProactive', () => {
it('resolves local time only when quiet hours are enabled', async () => {
const { getVoiceConfig } = await import('./config.js');
- const { getUserTimezone, getLocalParts } = await import('../../lib/timezone.js');
+ const { getLocalParts } = await import('../../lib/timezone.js');
+ const { getUserTimezone } = await import('../userTimezone.js');
getUserTimezone.mockClear();
getLocalParts.mockClear();
getVoiceConfig.mockResolvedValueOnce({
diff --git a/server/services/voice/tools.test.js b/server/services/voice/tools.test.js
index e5281d2353..8df5afdeaa 100644
--- a/server/services/voice/tools.test.js
+++ b/server/services/voice/tools.test.js
@@ -51,10 +51,12 @@ vi.mock('../../lib/fetchWithTimeout.js', () => ({
// Timezone — pin to deterministic values so calendar/time tests don't depend
// on the host TZ or settings file.
vi.mock('../../lib/timezone.js', () => ({
- getUserTimezone: vi.fn(async () => 'America/Los_Angeles'),
todayInTimezone: vi.fn(() => '2026-04-17'),
getLocalParts: vi.fn(() => ({ year: 2026, month: 4, day: 17 })),
- getUtcOffsetMs: vi.fn(() => -7 * 3600 * 1000), // PDT
+ getUtcOffsetMs: vi.fn(() => -7 * 3600 * 1000),
+}));
+vi.mock('../userTimezone.js', () => ({
+ getUserTimezone: vi.fn(async () => 'America/Los_Angeles'),
}));
vi.mock('../identity.js', () => ({
getGoals: vi.fn(async () => ({ goals: [] })),
diff --git a/server/services/voice/tools/ambient.js b/server/services/voice/tools/ambient.js
index 4ed7c34d11..ddb8afea27 100644
--- a/server/services/voice/tools/ambient.js
+++ b/server/services/voice/tools/ambient.js
@@ -5,7 +5,8 @@
import { getEvents as getCalendarEvents } from '../../calendarSync.js';
import { fetchWithTimeout } from '../../../lib/fetchWithTimeout.js';
-import { getUserTimezone, todayInTimezone, getLocalParts, getUtcOffsetMs } from '../../../lib/timezone.js';
+import { todayInTimezone, getLocalParts, getUtcOffsetMs } from '../../../lib/timezone.js';
+import { getUserTimezone } from '../../userTimezone.js';
import { getSettings } from '../../settings.js';
import { clampLimit } from './shared.js';
diff --git a/server/services/voice/tools/goals.js b/server/services/voice/tools/goals.js
index 40dd9ea588..88aa752c60 100644
--- a/server/services/voice/tools/goals.js
+++ b/server/services/voice/tools/goals.js
@@ -3,7 +3,8 @@
// property one" resolve from a distinctive word.
import { getGoals, updateGoalProgress, addProgressEntry } from '../../identity.js';
-import { getUserTimezone, todayInTimezone } from '../../../lib/timezone.js';
+import { todayInTimezone } from '../../../lib/timezone.js';
+import { getUserTimezone } from '../../userTimezone.js';
import { clampLimit } from './shared.js';
export const GOALS_INTENT_RE = /\b(goals?|progress|objective)\b/i;
diff --git a/server/services/whatsappImport.js b/server/services/whatsappImport.js
index dfaed77c4c..6693a7f9ea 100644
--- a/server/services/whatsappImport.js
+++ b/server/services/whatsappImport.js
@@ -53,7 +53,7 @@ import { readFile } from 'fs/promises';
import { createHash } from 'crypto';
import { collectZipEntries, isZipUpload } from '../lib/zipStream.js';
import { shortSummary, recordEvents, resolveEventInstant } from './humanActivity.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
// ---------------------------------------------------------------------------
// Pure helpers (exported for unit tests — no DB, no filesystem, no side effects).
diff --git a/server/services/workflow.js b/server/services/workflow.js
index e67b1b13ab..80e1aaa2ef 100644
--- a/server/services/workflow.js
+++ b/server/services/workflow.js
@@ -25,7 +25,8 @@ import { getScheduleStatus } from './taskSchedule.js';
import * as autonomousJobs from './autonomousJobs.js';
import { checkJobGate, hasGate, getRegisteredGates } from './jobGates.js';
import { parseCronToNextRun, parseRecurrenceToNextRun } from './eventScheduler.js';
-import { getLocalParts, getUserTimezone, nextLocalTime } from '../lib/timezone.js';
+import { getLocalParts, nextLocalTime } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
const HOUR = 3_600_000;
const DAY = 24 * HOUR;
diff --git a/server/services/youtubeImport.js b/server/services/youtubeImport.js
index 0426f2aade..13059b27c6 100644
--- a/server/services/youtubeImport.js
+++ b/server/services/youtubeImport.js
@@ -31,7 +31,7 @@
import { readFile } from 'fs/promises';
import { collectZipEntries, isZipUpload } from '../lib/zipStream.js';
import { shortSummary, recordEvents, localDayKey } from './humanActivity.js';
-import { getUserTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
// ---------------------------------------------------------------------------
// Pure helpers (exported for unit tests — no DB, no filesystem, no side effects).
diff --git a/server/services/youtubeSync.js b/server/services/youtubeSync.js
index 0a8f5bc39c..3da9d5b233 100644
--- a/server/services/youtubeSync.js
+++ b/server/services/youtubeSync.js
@@ -30,7 +30,8 @@
* exported and unit-tested against saved DOM-shaped fixtures — no browser or DB.
*/
import { dataPath, ensureDir, atomicWrite, tryReadFile, safeJSONParse, sleep } from '../lib/fileUtils.js';
-import { getUserTimezone, todayInTimezone } from '../lib/timezone.js';
+import { todayInTimezone } from '../lib/timezone.js';
+import { getUserTimezone } from './userTimezone.js';
import { getSettings } from './settings.js';
import { findOrOpenPage, listCdpPages, isAuthPage, evaluateOnPage } from './browserService.js';
import { localDayRangeUtc, shortSummary } from './humanActivity.js';