react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Escape characters with square brackets not working in dateFormat prop

Open RSchneider94 opened this issue 3 years ago • 5 comments

Describe the bug As I understood, react-datepicker uses date-fns under the hood for formatting dates, localization and so on. I'm trying to escape some characters in the dateFormat prop but it's not working. I tried to scape using square brackets (as described here in date-fns doc) but also with: \\, {} and ().

Example

<DatePicker
  selected={parseISO(date)}
  maxDate={maxDate}
  locale="pt"
  customInput={<CustomInput />}
  dateFormat="dd [de] MMMM [de] yyyy"
  onChange={(date) =>
    Array.isArray(date)
      ? onChangeDateRequest(date[0])
      : onChangeDateRequest(date)
  }
  {...rest}
/>

Additional context It is a bug or react-datepicker doesn't support this? Because I think it's something worth to support.

RSchneider94 avatar Jan 05 '21 13:01 RSchneider94

Were you able to solve this problem?

Gonzalo9823 avatar Apr 06 '21 18:04 Gonzalo9823

Were you able to solve this problem?

Unfortunately no, I decided to go for "dd/MM/yyyy" 😢 and no answers at all too. Bad.

RSchneider94 avatar Apr 06 '21 19:04 RSchneider94

can this feature be added?

Cintrust avatar Oct 06 '21 01:10 Cintrust

seems like we can use single quotes to escape characters, according to docs: https://date-fns.org/v2.0.0-alpha.27/docs/format

The characters wrapped between two single quotes characters (') are escaped. Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. (see the last example)

That worked for me:

        <DatePicker dateFormat="yyyy-MM-dd'T'HH:mm" ... />

dranitski avatar Dec 14 '21 14:12 dranitski

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 12 '22 16:06 stale[bot]