Skip to content

Ordinals numbers don't work in ParseByFormat #302

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

Open
brandonfake69 opened this issue May 3, 2025 · 2 comments
Open

Ordinals numbers don't work in ParseByFormat #302

brandonfake69 opened this issue May 3, 2025 · 2 comments
Labels
Bug Report a reproducible bug or regression

Comments

@brandonfake69
Copy link

Hello,

I encountered an issue with the following code:

// Output a datetime as a string with an ordinal number (example from README.md)
fmt.Println(carbon.Parse("2020-08-05 13:14:15").Format("l jK \\o\\f F Y h:i:s A")) 
// Wednesday 5th of August 2020 01:14:15 PM

// Parsing that output doesn't seem to work
fmt.Println(carbon.ParseByFormat("Wednesday 5th of August 2020 01:14:15 PM", "l jK \\o\\f F Y h:i:s A"))
// Nothing

// If we simply remove the ordinal (e.g. the K) it works!
fmt.Println(carbon.ParseByFormat("Wednesday 5 of August 2020 01:14:15 PM", "l j \\o\\f F Y h:i:s A"))
// Wednesday 5 of August 2020 01:14:15 PM

golang version: 1.24.2

carbon version: 2.6.4

time zone: United States

Please see the above example. Looks like carbon is able to format a datetime using ordinals but it is unable to parse a string that has ordinals.
@brandonfake69 brandonfake69 added the Bug Report a reproducible bug or regression label May 3, 2025
@brandonfake69 brandonfake69 changed the title Ordinals don't work as expected Ordinals numbers don't work in ParseByFormat May 3, 2025
@kuafuRace
Copy link
Collaborator

Not all formats are reversible, as some formats are custom and do not have corresponding symbols in standard time library

@kuafuRace
Copy link
Collaborator

If you have any good plans, welcome to PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report a reproducible bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants