Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add displayTimezone option to datetime input #8181

Draft
wants to merge 87 commits into
base: next
Choose a base branch
from

Conversation

EoinFalconer
Copy link
Contributor

@EoinFalconer EoinFalconer commented Jan 4, 2025

Remaining work

  • Replace momentjs with date-fns but maintain backwards compatibility.
  • Load the time zone list using Intl.DateTimeFormat instead of the large dependency.
  • Land the UI of displayTimeZone option on datetime.
  • Add timeZoneScope as a concept to the codebase so that many different time zone scopes can be held.
  • Add allowTimeZoneSwitch to let devs decide whether the timezone is fixed or user decided.
  • Move useTimeZone out of the scheduledPublishing folder.
  • Fix Calendar.tsx to ensure month and year are respecting the time zone.
  • Fix the dropdown list of timezones to be more user friendly.

Description

Adding the ability to add a `displayTimezone` option to the `datetime` input. This allows you to specify the timezone in which the stored UTC string from content lake will be displayed. When enabled, a tooltip is shown at the bottom left of the input field which indicates the timezone the field is representing. When you start editing this disappears. Screenshot 2025-01-09 at 21 53 02

A common use case here could be anything local that you would be working on in another timezone, for example concert times, apartment viewing times etc. etc. which are hard to work with today as the studio (just like the Date API) respects only the browsers relative display of the UTC string.

We have lots of signal on this one in this thread, as well as directly from users.

In addition to this, I decided to give it a go of removing moment from the @sanity/util package as a testbed how we should go about removing it across the entire codebase.

I am using the new date-fns/tz and date-fns/utc packages from date-fns. The reason for these is that they are very lightweight, TZDateMini which I am using here is only 916 B, which is a whopper difference from the locale bloat from moment-timezone dep we would need to make this work with moment.

As we have the ability to add custom date formats via the options on the datetime input and this is documented as support moment.js formats, I decided to write a formatter that would use the Intl.DateTimeFormat.format functionality instead by mapping the moment formatting to that format object.

What to review

* The naming of `displayTimezone` is worth a discussion. * The UI that I have chosen, with the text below should also be taken into consideration as to whether that is the best approach. * Browser support, not baking locales and timezones into the package and instead relying on the `Intl.DateTimeFormat` browser API means that browser versions [outside the widely supported](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#browser_compatibility) will not work.

Testing

Notes for release

@EoinFalconer EoinFalconer requested a review from a team as a code owner January 4, 2025 23:17
@EoinFalconer EoinFalconer requested review from bjoerge and removed request for a team January 4, 2025 23:17
Copy link

vercel bot commented Jan 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 19, 2025 7:04pm
performance-studio ✅ Ready (Inspect) Visit Preview Feb 19, 2025 7:04pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 19, 2025 7:04pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Feb 19, 2025 7:04pm
test-next-studio ⬜️ Ignored (Inspect) Visit Preview Feb 19, 2025 7:04pm

@EoinFalconer EoinFalconer marked this pull request as draft January 4, 2025 23:17
Copy link
Contributor

github-actions bot commented Jan 4, 2025

No changes to documentation

Copy link
Contributor

github-actions bot commented Jan 4, 2025

Component Testing Report Updated Feb 19, 2025 7:09 PM (UTC)

❌ Failed Tests (5) -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 1m 21s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 14s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ❌ Failed (Inspect) 2m 40s 3 0 3
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 59s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 29s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 17s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 30s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ❌ Failed (Inspect) 1m 55s 14 0 1
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 49s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ❌ Failed (Inspect) 3m 4s 20 0 1
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 14s 3 9 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 30s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 59s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

github-actions bot commented Jan 4, 2025

⚡️ Editor Performance Report

Updated Tue, 14 Jan 2025 16:40:44 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
synthetic (title) 18.5 efps (54ms) 19.2 efps (52ms) -2ms (-3.7%)
synthetic (string inside object) 18.5 efps (54ms) 18.9 efps (53ms) -1ms (-1.9%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
synthetic (title) 54ms 57ms 59ms 267ms 1033ms 12.9s
synthetic (string inside object) 54ms 56ms 67ms 528ms 1313ms 8.6s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
synthetic (title) 52ms 55ms 65ms 289ms 902ms 13.3s
synthetic (string inside object) 53ms 55ms 64ms 476ms 1229ms 8.5s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

Copy link
Contributor

github-actions bot commented Feb 19, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.14% 55460 / 128534
🔵 Statements 43.14% 55460 / 128534
🔵 Functions 48.23% 2804 / 5813
🔵 Branches 79.59% 10837 / 13615
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/@sanity/types/src/schema/asserters.ts 90.67% 83.56% 91.66% 90.67% 38-39, 49-50, 131-135, 155-156
packages/@sanity/types/src/schema/definition/type/datetime.ts 0% 0% 0% 0%
packages/@sanity/util/src/legacyDateFormat.ts 100% 94.11% 100% 100%
packages/@sanity/util/src/datetime-formatter/formatter.ts 84.48% 86.48% 83.33% 84.48% 84-107, 119-120, 266, 273-274, 281-283
packages/@sanity/util/src/datetime-formatter/momentToDateFnsFormat.ts 100% 100% 100% 100%
packages/sanity/src/_singletons/context/FieldActionsContext.ts 100% 100% 50% 100%
packages/sanity/src/core/components/inputs/DateFilters/calendar/CalendarFilter.tsx 87.33% 95% 46.15% 87.33% 71, 81, 115-136, 153, 159-161
packages/sanity/src/core/components/inputs/DateFilters/calendar/CalendarMonth.tsx 100% 63.63% 100% 100%
packages/sanity/src/core/components/inputs/DateInputs/DatePicker.tsx 100% 100% 100% 100%
packages/sanity/src/core/components/inputs/DateInputs/DateTimeInput.tsx 64% 91.17% 62.5% 64% 95-96, 100-101, 140-175
packages/sanity/src/core/components/inputs/DateInputs/calendar/Calendar.tsx 65.08% 59.25% 25% 65.08% 31-61, 138, 142, 182-184, 197-199, 210-218, 232-255, 271-272, 331-351, 374-378, 466-480, 492-566
packages/sanity/src/core/components/timeZone/timeZoneButton/TimeZoneButton.tsx 75% 76.92% 100% 75% 77-95
packages/sanity/src/core/form/field/actions/FieldActionsProvider.tsx 96.42% 91.66% 75% 96.42% 54
packages/sanity/src/core/form/inputs/BooleanInput.tsx 100% 50% 100% 100%
packages/sanity/src/core/form/inputs/DateInputs/CommonDateTimeInput.tsx 93.33% 95.45% 80% 93.33% 72-77, 90
packages/sanity/src/core/form/inputs/DateInputs/DateInput.tsx 100% 46.15% 100% 100%
packages/sanity/src/core/form/inputs/DateInputs/DateTimeInput.tsx 88.88% 70% 87.5% 88.88% 74-77, 96-114
packages/sanity/src/core/form/inputs/DateInputs/types.ts 0% 0% 0% 0%
packages/sanity/src/core/form/studio/inputResolver/fieldResolver.tsx 26.14% 60% 28.57% 26.14% 23-88, 100-106, 143-251, 261-262, 265-266, 271-272, 275-276, 279-280, 283-284, 290-291
packages/sanity/src/core/hooks/useTimeZone.tsx 72.85% 83.72% 66.66% 72.85% 147-160, 163-165, 171-172, 186-187, 197-215, 226, 232-266
packages/sanity/src/core/i18n/bundles/studio.ts 100% 100% 100% 100%
packages/sanity/src/core/releases/components/ScheduleDatePicker.tsx 23.52% 100% 0% 23.52% 28-76
packages/sanity/src/core/releases/components/dialog/ReleaseForm.tsx 76.1% 76.92% 50% 76.1% 33-34, 41-58, 82-85, 137-149
packages/sanity/src/core/releases/hooks/useCreateReleaseMetadata.ts 93.75% 85.71% 100% 93.75% 13
packages/sanity/src/core/releases/hooks/useReleaseTime.ts 100% 100% 100% 100%
packages/sanity/src/core/releases/tool/components/releaseCTAButtons/ReleaseScheduleButton.tsx 65.38% 42.1% 50% 65.38% 68, 72-113, 130-133, 139-145, 152-174, 183-185, 237-242, 250-261
packages/sanity/src/core/releases/tool/detail/ReleaseTypePicker.tsx 87.65% 93.33% 100% 87.65% 84-95, 109-112, 125-126, 151-160, 206, 249-251
packages/sanity/src/core/releases/tool/overview/ReleasesOverview.tsx 95.96% 86.74% 75% 95.96% 100, 134-135, 153, 169, 260-262, 269-273
packages/sanity/src/core/releases/tool/overview/useTimezoneAdjustedDateTimeRange.ts 100% 100% 100% 100%
packages/sanity/src/core/scheduledPublishing/constants.tsx 100% 100% 100% 100%
packages/sanity/src/core/scheduledPublishing/types.ts 0% 0% 0% 0%
packages/sanity/src/core/scheduledPublishing/components/dateInputs/CommonDateTimeInput.tsx 7.5% 100% 0% 7.5% 40-167
packages/sanity/src/core/scheduledPublishing/components/dateInputs/DateTimeInput.tsx 8.98% 100% 0% 8.98% 35-74, 80-154
packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/DatePicker.tsx 14.28% 100% 0% 14.28% 7-41
packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/DateTimeInput.tsx 10% 100% 0% 10% 46-151
packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/calendar/Calendar.tsx 6.85% 100% 0% 6.85% 61-389
packages/sanity/src/core/scheduledPublishing/components/dateInputs/base/calendar/CalendarMonth.tsx 18.42% 100% 0% 18.42% 20-57
packages/sanity/src/core/scheduledPublishing/components/dialogs/DialogHeader.tsx 28% 100% 0% 28% 14-41
packages/sanity/src/core/scheduledPublishing/components/dialogs/DialogScheduleEdit.tsx 21.62% 100% 0% 21.62% 16-51
packages/sanity/src/core/scheduledPublishing/components/editScheduleForm/ScheduleForm.tsx 17.64% 100% 0% 17.64% 14-55
packages/sanity/src/core/scheduledPublishing/components/scheduleItem/DocumentPreview.tsx 21.87% 100% 0% 21.87% 17-50
packages/sanity/src/core/scheduledPublishing/components/scheduleItem/PreviewWrapper.tsx 14.7% 100% 0% 14.7% 44-206
packages/sanity/src/core/scheduledPublishing/components/scheduleItem/ToolPreview.tsx 17.46% 100% 0% 17.46% 22-87
packages/sanity/src/core/scheduledPublishing/components/scheduleItem/dateWithTooltip/DateWithTooltip.tsx 26.92% 100% 0% 26.92% 18-46
packages/sanity/src/core/scheduledPublishing/hooks/useDialogScheduleEdit.ts 30.76% 100% 0% 30.76% 6-21
packages/sanity/src/core/scheduledPublishing/hooks/useDialogTimeZone.ts 100% 100% 100% 100%
packages/sanity/src/core/scheduledPublishing/hooks/useDialogVisibile.ts 91.66% 100% 66.66% 91.66% 16
packages/sanity/src/core/scheduledPublishing/hooks/useScheduleOperation.tsx 5.28% 100% 0% 5.28% 53-55, 62-328
packages/sanity/src/core/scheduledPublishing/hooks/__tests__/__mocks__/useTimeZone.mock.ts 100% 100% 100% 100%
packages/sanity/src/core/scheduledPublishing/plugin/documentActions/schedule/ScheduleAction.tsx 17.85% 100% 0% 17.85% 47-167
packages/sanity/src/core/scheduledPublishing/tool/Tool.tsx 17.73% 100% 0% 17.73% 36-207
packages/sanity/src/core/scheduledPublishing/tool/contexts/schedules.tsx 12.72% 100% 0% 12.72% 25-149
packages/sanity/src/core/scheduledPublishing/tool/toolCalendar/CalendarDay.tsx 8.27% 100% 0% 8.27% 24-192
packages/sanity/src/core/scheduledPublishing/tool/toolCalendar/ToolCalendar.tsx 23.8% 100% 0% 23.8% 14-36
packages/sanity/src/core/tasks/components/form/fields/DateEditFormField.tsx 15.15% 100% 0% 15.15% 24-119
packages/sanity/src/core/validation/validators/dateValidator.ts 86.07% 69.69% 100% 86.07% 45-46, 59, 67-68, 75-76, 99-100, 107-108
packages/sanity/src/structure/panes/document/documentPanel/DocumentPanel.tsx 13.49% 100% 0% 13.49% 45-56, 59-267
Generated in workflow #30727 for commit 1b5dad6 by the Vitest Coverage Report Action

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.