mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #1380] [MERGED] Propagate user timezone into generation prompt assembly #5050
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5050
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1380
Author: @Romuromylus
Created: 5/27/2026
Status: ✅ Merged
Merged: 5/27/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/refactor-issue-1356-user-timezone📝 Commits (4)
3313dc9Propagate user timezone into generation prompt assembly9e16666Merge branch 'refactor' into fix/refactor-issue-1356-user-timezonee012a21Merge branch 'refactor' into fix/refactor-issue-1356-user-timezonead42e15Address review: centralize timezone fallback so all generation paths inherit📊 Changes
6 files changed (+257 additions, -5 deletions)
View changed files
📝
src/engine/generation/prompt-assembly.ts(+27 -0)📝
src/engine/generation/start-generation.ts(+7 -0)➕
src/engine/shared/macros/macro-engine.test.ts(+71 -0)📝
src/engine/shared/macros/macro-engine.ts(+21 -5)➕
src/engine/shared/time/timezone.ts(+122 -0)📝
src/features/runtime/generation/hooks/use-generate.ts(+9 -0)📄 Description
Why this change
Closes #1356.
The legacy generation flow shipped the browser's resolved IANA timezone (
userTimeZone) into prompt assembly so prompt-time macros ({{date}},{{time}},{{datetime}},{{isotime}},{{weekday}}) and any prompt code relying on local date context resolved in the user's local frame. The refactor's macro engine resolves{{date}}/{{datetime}}/{{isotime}}fromDate.prototype.toISOStringand so produces UTC, which silently drifts a calendar day for users west of UTC late at night and east of UTC early in the morning. No timezone string flows from the UI into the engine at all today.What changed
src/engine/shared/time/timezone.ts(new): IANA-tz normalizer plus zoned-parts/date/time/weekday/ISO-with-offset helpers built onIntl.DateTimeFormat. The normalizer trims, length-caps to 100, and probes the value viaIntl.DateTimeFormatso invalid strings drop quietly toundefined.src/engine/shared/macros/macro-engine.ts: addsMacroContext.timeZone?: stringand routes{{date}} / {{time}} / {{datetime}} / {{isotime}} / {{weekday}}through the new helpers. All helpers fall back to the host machine's local zone viaIntlwhen no zone is provided, so a caller that skips the input plumbing never lands in UTC.src/engine/generation/start-generation.ts: addsuserTimeZone?: stringtoStartGenerationInput.src/engine/generation/prompt-assembly.ts:resolvePromptTimeZoneresolves in preference order persistedchat.metadata.promptTimeZone→ caller-suppliedrequest.userTimeZone→ liveIntl.DateTimeFormat().resolvedOptions().timeZone. The live fallback is the load-bearing piece — engine code runs in the user's Tauri webview, soIntlalways reflects the user's OS. This means everystartGenerationentry point (the chat hook here, the game-turn service, the background-autonomous chat hook, andpreviewGenerationPrompt) resolves macros in the user's local frame without per-callsite plumbing.src/features/runtime/generation/hooks/use-generate.ts: resolves the live browser timezone viaIntl.DateTimeFormat().resolvedOptions().timeZoneand threads it into thestartGenerationinput. With the engine-side fallback in place this is explicit-intent rather than load-bearing; it stays for clarity and to keep an override surface for future non-default callers (e.g. remote runtime).Two commits:
resolvePromptTimeZoneso game-mode and background-autonomous callers (which build their ownstartGenerationargs withoutuserTimeZone) and the prompt-preview UI all pick up the fix automatically. Also fixesformatZonedIsoDateTime(date, undefined)returning UTC (it now matches the host-local behavior of the other helpers) and extends the macro-engine fallback test with a{{datetime}}assertion.Verification
pnpm check✅ (architecture / dependency-cruiser, frontendtsc -b,cargo check, docs)pnpm test✅ (21 suites / 106 tests, including 6 Vitest specs for the macro engine that pin both the zoned-tz case and the host-local fallback)pnpm devconfirms RED → GREEN: pre-fix the macro engine returned2026-05-27(UTC) for an instant that is2026-05-26in LA-local; post-fix it returns the LA-local date.pnpm tauri dev:{{date}}/{{time}}/{{weekday}}now render in the user's local zone in real chat output, and a chat reply that includes those macros resolves correctly under normal usage.Risks called out
{{date}}returned UTC, new default returns host-local. This is the bug being fixed, but it does change observable output for any preset that depended on the old UTC behavior. Couldn't find such a preset in the repo.chat.metadata.promptTimeZoneprecedence: persisted overrides on legacy chats win over the live browser value. Intentional — matches the legacy server'schatMeta.promptTimeZone ?? input.userTimeZoneorder. Normalization rejects invalid stored strings so they fall through to the live host zone rather than producing UTC.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.