-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DateOnly as our base type for Date Input (#249)
Up until now we've had our own Date type for use with the Date Input component. Now that we have access to a built-in one - DateOnly - our's is going away. For now it's [Obsolete]d with a view to removing it in the final 1.0 release.
- Loading branch information
Showing
17 changed files
with
173 additions
and
86 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
16 changes: 12 additions & 4 deletions
16
src/GovUk.Frontend.AspNetCore/DateDateInputModelConverter.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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
using System; | ||
|
||
namespace GovUk.Frontend.AspNetCore | ||
{ | ||
internal class DateDateInputModelConverter : DateInputModelConverter | ||
{ | ||
public override bool CanConvertModelType(Type modelType) => | ||
modelType == typeof(Date) || modelType == typeof(Date?); | ||
public override bool CanConvertModelType(Type modelType) => modelType == typeof(Date); | ||
|
||
public override object CreateModelFromDate(Type modelType, Date date) => date; | ||
public override object CreateModelFromDate(Type modelType, DateOnly date) => new Date(date.Year, date.Month, date.Day); | ||
|
||
public override Date? GetDateFromModel(Type modelType, object model) => (Date?)model; | ||
public override DateOnly? GetDateFromModel(Type modelType, object model) | ||
{ | ||
if (model is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return (Date)model; | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/GovUk.Frontend.AspNetCore/DateOnlyDateInputModelConverter.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,14 @@ | ||
#nullable enable | ||
using System; | ||
|
||
namespace GovUk.Frontend.AspNetCore | ||
{ | ||
internal class DateOnlyDateInputModelConverter : DateInputModelConverter | ||
{ | ||
public override bool CanConvertModelType(Type modelType) => modelType == typeof(DateOnly); | ||
|
||
public override object CreateModelFromDate(Type modelType, DateOnly date) => date; | ||
|
||
public override DateOnly? GetDateFromModel(Type modelType, object model) => (DateOnly?)model; | ||
} | ||
} |
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
Oops, something went wrong.