Skip to content

Conversation

@RosnelOn
Copy link

Description

Fixes a bug where the dateFormat option doesn't respect custom separators. Dates are always formatted with dots (.) regardless of the separator specified in the format string.

Problem

{ "dateFormat": "DD-MM-YYYY" }
  • Expected: 19-10-2025
  • Actual: 19.10.2025

Solution

  • Added extractSeparatorFromFormat() method to auto-detect separator from format
  • Updated setInputValue() to use extracted separator as priority
  • Changed default separator from . to - for better international compatibility
  • Updated formatDate() method for consistency

Testing

Tested with multiple formats:

  • DD-MM-YYYY19-10-2025
  • DD/MM/YYYY19/10/2025
  • DD.MM.YYYY19.10.2025
  • YYYY-MM-DD2025-10-19
  • MM/DD/YYYY10/19/2025

Backward Compatibility

  • ✅ Existing code without dateFormat continues working
  • ✅ Existing code with dateSeparator override continues working
  • ✅ Only improves behavior for dateFormat usage
  • ✅ No breaking changes

Priority Order

The fix implements the following priority for separator selection:

  1. Separator extracted from dateFormat (if present)
  2. Manual dateSeparator from inputModeOptions (if specified)
  3. Default separator - (dash)

Checklist

  • Code follows project style guidelines
  • Self-reviewed the code
  • Tested locally
  • Build passes
  • Documentation is accurate
  • Maintains backward compatibility

Closes #716

This pull request improves how the date separator is determined and handled throughout the HSDatepicker plugin. The main change is the introduction of logic to automatically extract the separator from the provided date format, ensuring consistency and reducing manual configuration. Default separators have also been standardized.

Date separator extraction and handling:

  • Added a private method extractSeparatorFromFormat to automatically determine the separator from a date format string, defaulting to "-" if none is found.
  • Updated setInputValue to use the extracted separator from the date format, falling back to configuration or "-" as needed.
  • Standardized the default separator in changeDateSeparator and related logic from "." to "-", ensuring consistency. [1] [2]

Added logic to extract the date separator from the date format string, defaulting to '-' if not found. Updated default separators throughout to ensure consistency and improved flexibility when handling different date formats.
fix(datepicker): respect custom separators in dateFormat

- Add extractSeparatorFromFormat() to auto-detect separator from format
- Update setInputValue() to prioritize extracted separator over defaults
- Change default separator from '.' to '-' for better i18n support
- Maintains 100% backward compatibility

Fixes htmlstreamofficial#716
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.

Tailwind CSS Advanced Datepicker dot separator

1 participant