Skip to content

fix(NcDateTimePicker): handle text input for default formatting - #8657

Merged
odzhychko merged 2 commits into
mainfrom
8635-NcDateTimePicker-text-input
Aug 7, 2026
Merged

fix(NcDateTimePicker): handle text input for default formatting#8657
odzhychko merged 2 commits into
mainfrom
8635-NcDateTimePicker-text-input

Conversation

@odzhychko

@odzhychko odzhychko commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Handle text input when default formatting is used.

I tried not to change the existing formatting.
But the default formatting needed to change to accommodate the used parsing solution (locale information available in date-fns/locale)

Notable changes in the formatting are:

  • changing separator between date and time for some languages
    e.g., "02.01.2000, 03:04" becomes "02.01.2000 03:04" for "de" (comma is removed)
  • no shortened form for duration
    e.g., "Jan 1 – 7, 2000" becomes "Jan 1, 2000 - Jan 7, 2000" for "en-US"
  • "-" becomes the delimiter for duration instead of "–"
  • some languages use simplified/fallback local forms
    • e.g.,"2000年1月2日 03:04" becomes "Jan 2, 2000, 3:04 AM" for Chinese "zh"
    • e.g., "١‏/١‏/٢٠٠٠ – ٧‏/١‏/٢٠٠٠" becomes "1 يناير 2000 - 7 يناير 2000" for Arabic (Bahrain) "ar-BH"

This could be considered a breaking change, because things are now displayed differently.
But it could also be considered not to be breaking, because we still display the same information but in a new format, that is improved to accommodate text input. I consider it non-breaking and better than not allowing text input.

More details on how we could accommodate parsing without changing the preview format at all can be found in #8657 (comment)

☑️ Resolves

🖼️ Screenshots

Before

Screencast.from.2026-06-03.16-17-41.webm

After

Screencast.from.2026-06-03.16-16-14.webm

🚧 Tasks

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable
  • 2️⃣ Backport to stable8 for maintained Vue 2 version or not applicable

Comment thread src/components/NcDateTimePicker/format.ts Fixed
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.31%. Comparing base (0dad83c) to head (0a44a84).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8657   +/-   ##
=======================================
  Coverage   53.31%   53.31%           
=======================================
  Files         109      109           
  Lines        3697     3697           
  Branches     1083     1082    -1     
=======================================
  Hits         1971     1971           
  Misses       1472     1472           
  Partials      254      254           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/components/NcDateTimePicker/useDateFnsLocale.ts Outdated
//
// One big snapshot test to not infalte number of test cases.
// This keeps reporting clean and runs faster.
test('all locales format', async ({ mount }) => {

@odzhychko odzhychko Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to keep this snapshots tests?

I found them useful when developing to understand the:

  • edge cases related to different locales (and sometimes browsers)
  • impact of formatting changes
    • e.g., by diffing them between the two commits of this PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably expect them to fail for certain languages? so we can maybe limit snapshots to these one, to not commit 15K lines?

@odzhychko
odzhychko force-pushed the 8635-NcDateTimePicker-text-input branch from 496104b to 9a35785 Compare June 19, 2026 14:33
@odzhychko odzhychko added bug Something isn't working 2. developing Work in progress labels Jun 23, 2026
Comment thread src/components/NcDateTimePicker/NcDateTimePicker.vue
Comment thread src/components/NcDateTimePicker/NcDateTimePicker.vue Outdated
return (input: Date | [Date, Date]) => Array.isArray(input)
? formatter.formatRange(input[0], input[1])
: formatter.format(input)
switch (props.type) {

@odzhychko odzhychko Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get Vuepic/vue-datepicker#1286 fixed update to a newer versions of Vuepic, we can use textInput.format to specify a format that only applies when the user focuses the input.

With that, we could keep using Intl.DateTimeFormat for formatting the text that is shown by default. And with that, do not change the behavior at all.

So the decision would be between:

  1. Using same format for preview and input
  • Drawbacks
    • for some languages, the format changes (compared to impl. on main)
      • e.g., "02.01.2000, 03:04" becomes "02.01.2000 03:04" for "de" (comma is removed)
    • no shortend form for durations
      • e.g., "Jan 1 – 7, 2000" becomes "Jan 1, 2000 - Jan 7, 2000" for "en-US"
  1. Using different (but mostly similar) for formats for preview and input
  • Drawbacks
    • Text input changes/flickers when use focuses/leaves the text input

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR implements solution 1..
Solution 2. would be blocked by Vuepic/vue-datepicker#1286

@odzhychko
odzhychko force-pushed the 8635-NcDateTimePicker-text-input branch from 9a35785 to f103fd8 Compare June 23, 2026 12:43
@odzhychko odzhychko added the feature: datepicker Related to the date/time picker component label Jun 26, 2026
@odzhychko
odzhychko force-pushed the 8635-NcDateTimePicker-text-input branch from f103fd8 to 141b4e8 Compare June 29, 2026 08:51
@odzhychko
odzhychko force-pushed the 8635-NcDateTimePicker-text-input branch from 141b4e8 to e416fa9 Compare July 30, 2026 08:34
Signed-off-by: Oleksandr Dzhychko <hey@oleks.dev>
@odzhychko
odzhychko force-pushed the 8635-NcDateTimePicker-text-input branch from e416fa9 to 30ff669 Compare July 30, 2026 08:54
For some locales, the default formatting changes to accommodate the used parsing solution.

Fixes #8635

Signed-off-by: Oleksandr Dzhychko <hey@oleks.dev>
@odzhychko
odzhychko force-pushed the 8635-NcDateTimePicker-text-input branch from 30ff669 to 0a44a84 Compare July 30, 2026 09:00
@odzhychko
odzhychko marked this pull request as ready for review July 30, 2026 09:51
@odzhychko odzhychko added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Aug 3, 2026
@ShGKme ShGKme added this to the 9.9.1 milestone Aug 4, 2026
@odzhychko
odzhychko requested a review from kra-mo August 6, 2026 10:35

@kra-mo kra-mo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an expert in localization specifically, it looks good from what I understand, so unless someone else has feedback, consider it approved from the design side.

@hamza221
hamza221 requested a review from Antreesy August 7, 2026 11:05
@odzhychko
odzhychko merged commit 5f6ae35 into main Aug 7, 2026
29 checks passed
@odzhychko
odzhychko deleted the 8635-NcDateTimePicker-text-input branch August 7, 2026 11:09
@odzhychko

Copy link
Copy Markdown
Contributor Author

@hamza221 Sorry, merged without noticing that you requested a review from @Antreesy .

Let me know, if I'm to rollback this merge.

@odzhychko
odzhychko restored the 8635-NcDateTimePicker-text-input branch August 7, 2026 11:12
@Antreesy

Antreesy commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I'll check now, maybe it's okay)

@Antreesy Antreesy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code change itself it fine IMO

//
// One big snapshot test to not infalte number of test cases.
// This keeps reporting clean and runs faster.
test('all locales format', async ({ mount }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably expect them to fail for certain languages? so we can maybe limit snapshots to these one, to not commit 15K lines?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can maybe keep it as .json file - Vite/Playwright should support importing and using it fine?

@odzhychko odzhychko Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it again. I think we can limit it now to the locales supported by date-fns. Including all locales supported by Nextcloud was only interesting from the migration from Intl.DateFormat to localization by date-fns.

Applied in #8825 (removes ~20k lines from snapshots)

@odzhychko

Copy link
Copy Markdown
Contributor Author

we probably expect them to fail for certain languages? so we can maybe limit snapshots to these one, to not commit 15K lines?

@Antreesy No, none of them is expected to fail immediately. They should only fail if the formatting changes. This can happen if (a) the date-fns package is update and changes locales or (b) we start reworking local formatting again. In both cases, it helps with tracking what actually changed in between versions.


But I did what is described in #8657 (comment)

@Antreesy

Antreesy commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

They should only fail if the formatting changes.

What I meant under 'language that fails' is more 'language that caused issues on parsing'. But agree in general that limiting to date-fns available locales sounds ok to me. By the diff, I see that some secondary locales were dropped from snapshots, they would probably fall back to more generic locales anyway

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

Labels

3. to review Waiting for reviews bug Something isn't working feature: datepicker Related to the date/time picker component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NcDateTimePicker]: text input gets discarded since v9

6 participants