stepanbenes / api-for-nopcommerce

API plugin for nopCommerce 4.50
MIT License
141 stars 93 forks source link

Date Parameter Issue #57

Open brandon71 opened 2 years ago

brandon71 commented 2 years ago

We are testing the API and came across an issue with dates. We were testing both GetCustomers and GetOrders with the CreatedAtMin parameter and are seeing the same issue with both.

When we pass a date in the format specified, the property is not being parsed and is set to null. If we send the date with out the time (2008-12-31) the date is parsed with the time set to 12:00am. ///

/// Show orders created after date (format: 2008-12-31 03:00) /// [JsonProperty("created_at_min")] public DateTime? CreatedAtMin { get; set; }

i.e https://localhost:44369/api/orders?status=pending&CreatedAtMin=2008-12-31 03:00

If we remove the model binder attribute from the OrdersParametersModel the datetime (2008-12-31 03:00) is parsed as expected. [ModelBinder(typeof(ParametersModelBinder))]

It appears the model binder attribute is causing issues with datetimes.

brandon71 commented 2 years ago

Digging into the code we found that the date format in the documentation is not one of the valid formats. Putting the date into the format 2008-12-31T03:00 allows the CreatedAtMin date value to function as expected.

Valid Date formats are identified in the APITypeConverter Class are: var formats = new[] { "yyyy", "yyyy-MM", "yyyy-MM-dd", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm:sszzz", "yyyy-MM-ddTHH:mm:ss.FFFFFFFK" };