Skip to content

Ordinals numbers don't work in ParseByFormat #302

Closed
@brandonfake69

Description

@brandonfake69

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReport a reproducible bug or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions