bchavez / bchavez/Bogus

Parsing date expression leads to incorrect format

Open
#408 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
9.7k
Forks
538
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/bchavez/Bogus/blob/59985ee11fb2a34b89d940d5da8b34617f6f9f6f/Source/Bogus/Tokenizer.cs#L80). 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

Contributor guide

Open the contributing guide

Research direction

Start with Source/Bogus/Tokenizer.cs at the linked call site around line 80 and trace how date.soon(10) results are converted to text. Confirm the expected locale-sensitive output for fr, including 26/01/2022 for date.soon(0), and ensure the completed behavior is covered without changing unrelated expression parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.