Bogus
Bogus copied to clipboard
Parsing date expression leads to incorrect format
Hello,
I created a Bug ticket, but it might be a bug/feature request
Version Information
Software | Version(s) |
---|---|
Bogus NuGet Package | 34.0.1 |
.NET Core? | 5.0 |
.NET Full Framework? | N/A |
Windows OS? | N/A |
Linux OS? | Ubuntu 20.04.3 LTS |
Visual Studio? | VSCode 1.63.2 |
What locale are you using with Bogus?
fr
What's the problem?
When parsing a like "{{date.soon(10)}}", the output date does not take care of the culture.
Using fr as locale, dates should follow this pattern: day/month/year instead of the us format month/day/year.
What is the expected behavior?
Using fr locale Today is January 26th 2022, the expected result of "{{date.soon(0)}}" should be 26/01/2022
What is the actual behavior?
Using fr locale Today is January 26th 2022, the expected result of "{{date.soon(0)}}" should be 01/26/2022
Any possible solutions?
Well, since ToString() method is called no matter what the return type is. I'm not sure how this can be easily fixed, as ToString from Object does not accept culture info (which makes sense), whereas DateTime does.
An option could be to add a part to the expression => date.soon(10).toString(dd/mm/yyyy) that would override the default behavior.
Another option would be to duplicate Date dataset methods like SoonStr(int days...., string format) that would call the original Soon() and return the expected str.
If the bug is confirmed, would you be willing to submit a PR?
That's possible