diff options
5 files changed, 14 insertions, 14 deletions
diff --git a/projecttemplates/RelyingPartyLogic/Model.AuthenticationToken.cs b/projecttemplates/RelyingPartyLogic/Model.AuthenticationToken.cs index f629bf6..d6564da 100644 --- a/projecttemplates/RelyingPartyLogic/Model.AuthenticationToken.cs +++ b/projecttemplates/RelyingPartyLogic/Model.AuthenticationToken.cs @@ -28,15 +28,11 @@ } partial void OnLastUsedUtcChanging(DateTime value) { - if (value.Kind != DateTimeKind.Utc) { - throw new ArgumentException("DateTime must be given in UTC time."); - } + Utilities.VerifyThrowNotLocalTime(value); } partial void OnCreatedOnUtcChanging(DateTime value) { - if (value.Kind != DateTimeKind.Utc) { - throw new ArgumentException("DateTime must be given in UTC time."); - } + Utilities.VerifyThrowNotLocalTime(value); } } } diff --git a/projecttemplates/RelyingPartyLogic/Model.IssuedAccessToken.cs b/projecttemplates/RelyingPartyLogic/Model.IssuedAccessToken.cs index d966baf..25d983b 100644 --- a/projecttemplates/RelyingPartyLogic/Model.IssuedAccessToken.cs +++ b/projecttemplates/RelyingPartyLogic/Model.IssuedAccessToken.cs @@ -66,8 +66,8 @@ namespace RelyingPartyLogic { } partial void OnExpirationDateUtcChanging(DateTime? value) { - if (value.HasValue && value.Value.Kind != DateTimeKind.Utc) { - throw new ArgumentException("DateTime must be given in UTC time."); + if (value.HasValue) { + Utilities.VerifyThrowNotLocalTime(value.Value); } } } diff --git a/projecttemplates/RelyingPartyLogic/Model.IssuedToken.cs b/projecttemplates/RelyingPartyLogic/Model.IssuedToken.cs index aab1fc1..5e10178 100644 --- a/projecttemplates/RelyingPartyLogic/Model.IssuedToken.cs +++ b/projecttemplates/RelyingPartyLogic/Model.IssuedToken.cs @@ -20,9 +20,7 @@ namespace RelyingPartyLogic { } partial void OnCreatedOnUtcChanging(DateTime value) { - if (value.Kind != DateTimeKind.Utc) { - throw new ArgumentException("DateTime must be given in UTC time."); - } + Utilities.VerifyThrowNotLocalTime(value); } } } diff --git a/projecttemplates/RelyingPartyLogic/Model.User.cs b/projecttemplates/RelyingPartyLogic/Model.User.cs index 51fd38b..b47cd2f 100644 --- a/projecttemplates/RelyingPartyLogic/Model.User.cs +++ b/projecttemplates/RelyingPartyLogic/Model.User.cs @@ -19,9 +19,7 @@ namespace RelyingPartyLogic { } partial void OnCreatedOnUtcChanging(DateTime value) { - if (value.Kind != DateTimeKind.Utc) { - throw new ArgumentException("DateTime must be given in UTC time."); - } + Utilities.VerifyThrowNotLocalTime(value); } partial void OnEmailAddressChanged() { diff --git a/projecttemplates/RelyingPartyLogic/Utilities.cs b/projecttemplates/RelyingPartyLogic/Utilities.cs index 02eb273..affbe26 100644 --- a/projecttemplates/RelyingPartyLogic/Utilities.cs +++ b/projecttemplates/RelyingPartyLogic/Utilities.cs @@ -60,5 +60,13 @@ GO serverConnection.Disconnect(); } } + + internal static void VerifyThrowNotLocalTime(DateTime value) { + // When we want UTC time, we have to accept Unspecified kind + // because that's how it is set to us in the database. + if (value.Kind == DateTimeKind.Local) { + throw new ArgumentException("DateTime must be given in UTC time but was " + value.Kind.ToString()); + } + } } } |