Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

ThisMonth in Query Expression fails on last day after midday #587

Open
Skubakoob opened this issue Feb 1, 2022 · 0 comments
Open

ThisMonth in Query Expression fails on last day after midday #587

Skubakoob opened this issue Feb 1, 2022 · 0 comments
Labels

Comments

@Skubakoob
Copy link

Skubakoob commented Feb 1, 2022

Describe the bug
When running a test with a query for DateTime = ThisMonth on the last day of the month after midday, the test can fail

To Reproduce
The code from repo as below sets the to Date to something like "1/31/2022 12:00:00 AM"
This means when querying on something like created on, it will not include items created after midday

i.e.
query.Criteria.AddCondition("createdon", ConditionOperator.ThisMonth);

Repo code:

case ConditionOperator.ThisMonth: // From first day of this month to last day of this month                    
fromDate = new DateTime(thisYear, thisMonth, 1);
// Last day of this month: Add one month to the first of this month, and then remove one day
toDate = new DateTime(thisYear, thisMonth, 1).AddMonths(1).AddDays(-1);

Expected behavior
Should include items created after midday, i.e. this should resolve it:

var toDate = new DateTime(thisYear, thisMonth, 1, 23,59,59).AddMonths(1).AddDays(-1);

When I get a minute today I can create a PR, I guess it will probably affect some of the other date queries i.e. LastMonth.

And I guess if we are being really pedantic, it should take into account millisends too so maybe this
new DateTime(thisYear, thisMonth, 1).Date.AddDays(1).AddTicks(-1);

@Skubakoob Skubakoob added the bug label Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant