-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Signum.Utilities.Date
- Loading branch information
1 parent
ed42d8a
commit 5602eff
Showing
12 changed files
with
96 additions
and
36 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
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
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,26 @@ | ||
using Newtonsoft.Json; | ||
using Signum.Utilities; | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Signum.React.Json | ||
{ | ||
public class DateConverter : JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return typeof(Date).IsAssignableFrom(objectType.UnNullify()); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(((DateTime?)(Date?)value)?.ToString("o")); | ||
} | ||
|
||
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) | ||
{ | ||
var date = reader.Value as DateTime?; | ||
return (Date?)date; | ||
} | ||
} | ||
} |
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
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
5602eff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New
Date
type inSignum.Utilities
.Both PostgreSQL and Microsoft SQL Server have a type for
DateTime
without Time for a long time, but it's not implemented in .Net, so was never usable from Signum Framework.The new
Date
type is very intuitive and is based in the implementation from https://github.com/supersonicclay/csharp-date/blob/master/CSharpDate/Date.cs.MonthStart
,WeekStart
,QuarterStart
).yyyy-MM-dd 00:00:00
) you you just need to domoment().format()
like always.When to use it?
If you have a date time that needs no time part (often using
DateTimePrecisionValidator(DateTimePrecision.Days)
) it's a good idea to use Date type. Less space in the database and less space where bugs can hide, specially for applications with multiple time zones where the conversions from / to UTC make no sense for properties likeDateOfBirth
.Check how Southwind was updated: signumsoftware/southwind@31a5f7f
Enjoy!
5602eff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Actually we need this.
5602eff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Great feature!