Skip to content

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

Draft
odzhychko wants to merge 3 commits into
mainfrom
8635-NcDateTimePicker-text-input
Draft

fix(NcDateTimePicker): handle text input for default formatting#8657
odzhychko wants to merge 3 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 some locales, the default formatting changed to accommodate the used parsing solution (locale information available in date-fns/locale)

Builds upon #8644.
Waiting for #8644 to be merged, to remove the Draft status.
Code is still close to the final proposed fixed and might help understanding the changes in #8644.

☑️ 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 54.06%. Comparing base (c77e363) to head (141b4e8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8657   +/-   ##
=======================================
  Coverage   54.06%   54.06%           
=======================================
  Files         106      106           
  Lines        3479     3479           
  Branches     1009     1008    -1     
=======================================
  Hits         1881     1881           
  Misses       1354     1354           
  Partials      244      244           

☔ 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.

*
* @param locale locale code (e.g., 'de-DE')
*/
export default function useDateFnsLocale(locale: MaybeRefOrGetter<string>): Ref<Locale> {

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.

Instead of loading locales, we could construct them by:

  • using tokens from https://github.com/nextcloud-libraries/nextcloud-l10n/blob/main/lib/date.ts
    • translation for tokens not yet in nextcloud-l10n (e.g., quarters and genitive case for month names) could have some fallback logic or be added to be translated

    • also we might want to disable implicit support for tokens that are specific to date-fns

      • These patterns are not in the Unicode Technical Standard #5:

        • ...
        • o: ordinal number modifier
        • ...

      https://date-fns.org/v4.4.0/docs/format

  • and extracting format strings with parseFormatForOpts for { dateStyle: 'medium' } and { dateStyle: 'short' }

But that would require more code to get right, so I went with the build in locales for now.

//
// 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:

@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 #8657 (comment) fixed (or update to a version that fixes it) and the feature is still available in 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:

@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
… format string

Signed-off-by: Oleksandr Dzhychko <hey@oleks.dev>
Signed-off-by: Oleksandr Dzhychko <hey@oleks.dev>
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 f103fd8 to 141b4e8 Compare June 29, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress 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

2 participants