Skip to content

Fix planted date saving one day off (#2388) - #2528

Open
David-VanAssche wants to merge 1 commit into
FarmBot:stagingfrom
David-VanAssche:fix/2388-planted-date-off-by-one
Open

David-VanAssche wants to merge 1 commit into
FarmBot:stagingfrom
David-VanAssche:fix/2388-planted-date-off-by-one

Conversation

@David-VanAssche

Copy link
Copy Markdown

Fixes #2388

Problem

The planted date inputs, EditDatePlanted and PlantDateBulkUpdate, parse the selected YYYY-MM-DD value with moment(value), which gives midnight in the browser's timezone. They then call .utcOffset(offset), which only changes the display offset; the instant stays the same. When the device's tz_offset_hrs is behind the browser's offset (e.g. a browser in Munich with the device offset at 0), the saved instant falls on the previous day in the device's timezone, so the input shows the selected date minus one. When the device offset is ahead of the browser's, the date can shift forward instead.

Fix

Parse the date as midnight in the device's UTC offset:

moment.utc(value).utcOffset(timeSettings.utcOffset, true).toISOString()

This doesn't depend on the browser's timezone at all.

Tests

  • Added it.each cases for UTC offsets -11, -5, 0, +5 and +13 to both components, each asserting the exact saved timestamp. Previously the tests only checked that the value contained "Z".
  • Ran the new cases under TZ=UTC, Europe/Berlin, America/Los_Angeles, Pacific/Kiritimati and Asia/Kolkata. All 10 fail without the fix and pass with it.
  • bun run typecheck and ESLint on the changed files are clean.
  • Full bun test run: 7460 pass. The 1 failure was <GardenModel /> loads sequence visualization when selected, which passes when run alone, so it looks flaky and unrelated.

Note: the existing <PlantDateBulkUpdate /> updates plant dates test fails under TZ=America/Los_Angeles on main too, because of the local-time formatting in the confirm message. I left it unchanged to keep this PR focused.

🤖 Generated with Claude Code

The planted date inputs parsed the selected YYYY-MM-DD date at midnight
in the browser's timezone, then only changed the display offset. When the
device's utc offset differed from the browser's, the saved timestamp fell
on the previous (or next) day in the device's timezone.

Parse the date as midnight in the device's utc offset instead, for both
the single-plant and bulk date inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Date set is not equal to date selected in datepicker

1 participant