-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PBL-9276 Orders Missed When Filtered by UTC Date/Time (#66)
* PBL-9276 Pass dates_are_gmt : "1" when get orders by dates * PBL-9276 Update package version to 1.11.7-alpha.1 * PBL-9276 Add TODOs * PBL-9276 [v.1.11.8-alpha.1] Extract OrdersFiltersBuilder; add unit tests
- Loading branch information
1 parent
64c1687
commit 5041b32
Showing
5 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace WooCommerceAccess.Helpers | ||
{ | ||
public static class OrdersFiltersBuilder | ||
{ | ||
public const string DatesAreGmt = "dates_are_gmt"; | ||
|
||
public static Dictionary<string, string> CreateModifiedDateRangeFilters( DateTime startDate, DateTime endDate ) | ||
{ | ||
const string dateFilterAfter = "modified_after"; | ||
const string dateFilterBefore = "modified_before"; | ||
var orderFilters = new Dictionary< string, string > | ||
{ | ||
//Sortable "s" format: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#the-sortable-s-format-specifier | ||
{ dateFilterAfter, startDate.RoundDateDownToTopOfMinute().ToString( "s" ) }, | ||
{ dateFilterBefore, endDate.RoundDateUpToTopOfMinute().ToString( "s" ) } | ||
}; | ||
if ( startDate.Kind == DateTimeKind.Utc && endDate.Kind == DateTimeKind.Utc ) | ||
{ | ||
orderFilters.Add( DatesAreGmt, "1" ); | ||
} | ||
|
||
return orderFilters; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using WooCommerceAccess.Helpers; | ||
|
||
namespace WooCommerceTests.Helpers | ||
{ | ||
public class OrdersFiltersBuilderTests | ||
{ | ||
[ Test ] | ||
public void CreateModifiedDateRangeFilters_ShouldSetDatesAreGmtToTrue_WhenBothDatesAreUtc() | ||
{ | ||
var startDate = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Utc); | ||
var endDate = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Utc); | ||
|
||
var result = OrdersFiltersBuilder.CreateModifiedDateRangeFilters(startDate, endDate); | ||
|
||
Assert.That( result[OrdersFiltersBuilder.DatesAreGmt], Is.EqualTo( "1" ) ); | ||
} | ||
|
||
[ TestCase( DateTimeKind.Utc, DateTimeKind.Unspecified ) ] | ||
[ TestCase( DateTimeKind.Unspecified, DateTimeKind.Utc ) ] | ||
[ TestCase( DateTimeKind.Unspecified, DateTimeKind.Unspecified ) ] | ||
[ TestCase( DateTimeKind.Utc, DateTimeKind.Local ) ] | ||
[ TestCase( DateTimeKind.Local, DateTimeKind.Utc ) ] | ||
[ TestCase( DateTimeKind.Local, DateTimeKind.Local ) ] | ||
public void CreateModifiedDateRangeFilters_ShouldNotSetDatesAreGmtToTrue_WhenOneDateIsNotUtc( DateTimeKind startDateKind, DateTimeKind endDateKind ) | ||
{ | ||
var startDate = new DateTime(2001, 1, 1, 1, 1, 1, startDateKind); | ||
var endDate = new DateTime(2001, 1, 1, 1, 1, 1, endDateKind); | ||
|
||
var result = OrdersFiltersBuilder.CreateModifiedDateRangeFilters(startDate, endDate); | ||
|
||
Assert.That( result.ContainsKey( OrdersFiltersBuilder.DatesAreGmt ), Is.False ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters