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

Problem with format function: error with format 'dddo' #3765

Open
keesvandaalen-sd opened this issue Apr 12, 2024 · 2 comments
Open

Problem with format function: error with format 'dddo' #3765

keesvandaalen-sd opened this issue Apr 12, 2024 · 2 comments

Comments

@keesvandaalen-sd
Copy link

There is an issue with the format function

The problem

💻 Code demonstrating the problem

import { format } from 'date-fns';
import {enUs} from 'date-fns/locale';

format(new Date(2024, 3, 1), 'dddo', {locale: enUs});
//=> Problematic output

🙁 Actual behavior

RangeError: Format string contains an unescaped latin alphabet character o

🙂 Expected behavior

Output: 011st

Debug information

  • date-fns version: 3.6.0
  • Browser/Node.js version: Versie 123.0.6312.107 (Officiële build) (arm64) / v18.17.1
  • Your timezone: Central European Time
  • Your current time: 12:31
@MiguelAngeloBautista
Copy link

It seems the problem lays in format()'s pattern checking. If you add a space in between as so:

format(new Date(2024, 3, 1), 'dd do', {locale: enUS})

it should all work fine. This will however create an output of 01 1st. If you want to keep it in one word just use the .replace() function to remove the space in between:

format(new Date(2024, 3, 1), 'dd do', {locale: enUS}).replace(" ", "")

@keesvandaalen-sd
Copy link
Author

keesvandaalen-sd commented Apr 15, 2024 via email

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

No branches or pull requests

2 participants