-
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.
fixed issue with datetime types in date filter
- Loading branch information
1 parent
d23bcea
commit 2850568
Showing
4 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/Reveal.Sdk.Dom/Core/Serialization/Converters/DateTimeConverter.cs
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,49 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
|
||
namespace Reveal.Sdk.Dom.Core.Serialization.Converters | ||
{ | ||
internal class DateTimeConverter : JsonConverter | ||
{ | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
if (value is DateTime dateTimeValue) | ||
{ | ||
JObject jObject = new JObject | ||
{ | ||
["_type"] = "date", | ||
["value"] = dateTimeValue | ||
}; | ||
jObject.WriteTo(writer); | ||
} | ||
else | ||
{ | ||
throw new JsonSerializationException("Expected DateTime object."); | ||
} | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
JObject jObject = JObject.Load(reader); | ||
var type = jObject["_type"].Value<string>(); | ||
if (type == "date") | ||
{ | ||
var value = jObject["value"]; | ||
if (value != null) | ||
{ | ||
return value.Value<DateTime>(); | ||
} | ||
//todo: need to handle the option of XML date time which is a string | ||
//this code logic can be found on line 248 of JsonUtility.cs in DataLayer.WPF | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return typeof(DateTime).IsAssignableFrom(objectType); | ||
} | ||
} | ||
} |
9 changes: 7 additions & 2 deletions
9
src/Reveal.Sdk.Dom/Filters/Bindings/DashboardDateFilterBindingTarget.cs
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
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Reveal.Sdk.Dom.Core.Serialization.Converters; | ||
using System; | ||
|
||
namespace Reveal.Sdk.Dom | ||
{ | ||
public sealed class DateRange | ||
{ | ||
[JsonConverter(typeof(DateTimeConverter))] | ||
public DateTime? From { get; set; } | ||
|
||
[JsonConverter(typeof(DateTimeConverter))] | ||
public DateTime? To { get; set; } | ||
} | ||
} |