dynamic-linq-query-builder
dynamic-linq-query-builder copied to clipboard
Setting CultureInfo does not work for Date
First of all, thanks for the great library!
I'm stumbling over an issue where I cannot set the CultureInfo, as the documentation suggests.
My code looks something like that:
IEnumerable<CaseFilter> cases = _repository.Get() // Pseudocode, the Repository returns a List<CaseFilter>.
cases
.AsQueryable()
.BuildQuery<CaseFilter>(
filterRule: filter.QueryBuilderFilterRule,
options: new BuildExpressionOptions() {
CultureInfo = new CultureInfo("de-CH", true)
})
This works if I search on a string or on numbers. It also works for Dates, but only in the american format (MM/dd/yyyy). Interestingly, if I submit with dots instead of slashes, it works as well.
When setting CultureInfo to "de-CH" (I've also tried "de-DE") I would expect it to work with dates in dd.MM.yyyy-Format.
Works: 02/15/2024 Works: 02.15.2024 Does not work: 15.02.2024
filter.QueryBuilderFilterRule is of class QueryBuilderFilterRule
As a workaround, I simply switch the month and day part of the date in the UI, but it would be nice if this wasn't necessary.
If I misunderstood something, I would be grateful for a pointer in the right direction :)
Edit
Now I've just realized that my workaround works for single values, but not for multiple. I'm using 'Between' with the following Values:
Does not work: ["10/15/2015", "10/15/2024"] Works: ["15/10/2015", "10/15/2024"] Does not work: ["15/10/2015", "15/10/2024"]
I would at least expect it to be consistent 😅 It does not make sense that one value is read as MM.dd.yyyy while the other is read as dd.MM.yyyy