From 6668b10a0fe65810c812586154dd5b3b51f7d880 Mon Sep 17 00:00:00 2001
From: Alexander van Delft <56023674+lxatrhea@users.noreply.github.com>
Date: Thu, 11 Apr 2024 14:22:47 +0200
Subject: [PATCH] TimeOfDayParameterType conversion doesn't work as expected;
fixes #328
TimeOfDayParameterType conversion doesn't work as expected
---
.../DtoValueValidatorTestFixture.cs | 20 ++++++---
.../DtoValueValidatorTestFixture.cs | 21 +++++++---
CDP4Common/CDP4Common.csproj | 4 +-
CDP4Common/Validation/ObjectValueValidator.cs | 42 +++++++++++++++++--
CDP4Dal/CDP4Dal.csproj | 4 +-
CDP4DalCommon/CDP4DalCommon.csproj | 4 +-
CDP4JsonFileDal/CDP4JsonFileDal.csproj | 4 +-
CDP4JsonSerializer/CDP4JsonSerializer.csproj | 4 +-
.../CDP4MessagePackSerializer.csproj | 4 +-
CDP4Reporting/CDP4Reporting.csproj | 4 +-
.../CDP4RequirementsVerification.csproj | 4 +-
CDP4Rules/CDP4Rules.csproj | 4 +-
CDP4ServicesDal/CDP4ServicesDal.csproj | 4 +-
.../CDP4ServicesMessaging.csproj | 4 +-
CDP4Web/CDP4Web.csproj | 4 +-
CDP4WspDal/CDP4WspDal.csproj | 4 +-
16 files changed, 96 insertions(+), 39 deletions(-)
diff --git a/CDP4Common.NetCore.Tests/Validation/DtoValueValidatorTestFixture.cs b/CDP4Common.NetCore.Tests/Validation/DtoValueValidatorTestFixture.cs
index cb147f5c..f3851c94 100644
--- a/CDP4Common.NetCore.Tests/Validation/DtoValueValidatorTestFixture.cs
+++ b/CDP4Common.NetCore.Tests/Validation/DtoValueValidatorTestFixture.cs
@@ -422,16 +422,26 @@ public void VerifyTimeOfDayParameterTypeValidationAndCleanup()
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
this.valueSet.Manual[0] = "14:00:12";
- this.valueSet.Computed[0] = "0001-01-01T14:00:12.0000000";
+ this.valueSet.Computed[0] = "0001-01-01T14:00:12.0000000Z";
this.valueSet.Reference[0] = "17:49:30.453Z";
+
+ result = this.timeOfDayParameterType.ValidateAndCleanup(this.valueSet, null);
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
+ Assert.That(this.valueSet.Manual[0], Is.EqualTo("14:00:12"));
+ Assert.That(this.valueSet.Computed[0], Is.EqualTo("14:00:12Z"));
+ Assert.That(this.valueSet.Reference[0], Is.EqualTo("17:49:30.453Z"));
+ });
+
+ this.valueSet.Computed[0] = "0001-01-01T14:00:12.0000000";
result = this.timeOfDayParameterType.ValidateAndCleanup(this.valueSet, null);
Assert.Multiple(() =>
{
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
- Assert.That(this.valueSet.Manual[0], Is.EqualTo("0001-01-01T14:00:12.0000000Z"));
- Assert.That(this.valueSet.Computed[0], Is.EqualTo("0001-01-01T14:00:12.0000000Z"));
- Assert.That(this.valueSet.Reference[0], Is.EqualTo("0001-01-01T17:49:30.4530000Z"));
+ Assert.That(this.valueSet.Computed[0], Is.EqualTo("14:00:12"));
});
this.valueSet.Manual[0] = "0001-01-02T14:00:12.0000000";
@@ -443,7 +453,7 @@ public void VerifyTimeOfDayParameterTypeValidationAndCleanup()
Assert.Multiple(() =>
{
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
- Assert.That(cleanedValue, Is.EqualTo("0001-01-01T12:45:35.0000000Z"));
+ Assert.That(cleanedValue, Is.EqualTo("12:45:35Z"));
});
result = this.timeOfDayParameterType.Validate(new DateTime(2001, 1, 1, 12, 45, 35, DateTimeKind.Utc), out _);
diff --git a/CDP4Common.Tests/Validation/DtoValueValidatorTestFixture.cs b/CDP4Common.Tests/Validation/DtoValueValidatorTestFixture.cs
index 335a7f50..6658c6a6 100644
--- a/CDP4Common.Tests/Validation/DtoValueValidatorTestFixture.cs
+++ b/CDP4Common.Tests/Validation/DtoValueValidatorTestFixture.cs
@@ -414,6 +414,7 @@ public void VerifyTextParameterTypeValidationAndCleanup()
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Invalid));
}
+
[Test]
public void VerifyTimeOfDayParameterTypeValidationAndCleanup()
{
@@ -422,16 +423,26 @@ public void VerifyTimeOfDayParameterTypeValidationAndCleanup()
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
this.valueSet.Manual[0] = "14:00:12";
- this.valueSet.Computed[0] = "0001-01-01T14:00:12.0000000";
+ this.valueSet.Computed[0] = "0001-01-01T14:00:12.0000000Z";
this.valueSet.Reference[0] = "17:49:30.453Z";
+
+ result = this.timeOfDayParameterType.ValidateAndCleanup(this.valueSet, null);
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
+ Assert.That(this.valueSet.Manual[0], Is.EqualTo("14:00:12"));
+ Assert.That(this.valueSet.Computed[0], Is.EqualTo("14:00:12Z"));
+ Assert.That(this.valueSet.Reference[0], Is.EqualTo("17:49:30.453Z"));
+ });
+
+ this.valueSet.Computed[0] = "0001-01-01T14:00:12.0000000";
result = this.timeOfDayParameterType.ValidateAndCleanup(this.valueSet, null);
Assert.Multiple(() =>
{
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
- Assert.That(this.valueSet.Manual[0], Is.EqualTo("0001-01-01T14:00:12.0000000Z"));
- Assert.That(this.valueSet.Computed[0], Is.EqualTo("0001-01-01T14:00:12.0000000Z"));
- Assert.That(this.valueSet.Reference[0], Is.EqualTo("0001-01-01T17:49:30.4530000Z"));
+ Assert.That(this.valueSet.Computed[0], Is.EqualTo("14:00:12"));
});
this.valueSet.Manual[0] = "0001-01-02T14:00:12.0000000";
@@ -443,7 +454,7 @@ public void VerifyTimeOfDayParameterTypeValidationAndCleanup()
Assert.Multiple(() =>
{
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Valid));
- Assert.That(cleanedValue, Is.EqualTo("0001-01-01T12:45:35.0000000Z"));
+ Assert.That(cleanedValue, Is.EqualTo("12:45:35Z"));
});
result = this.timeOfDayParameterType.Validate(new DateTime(2001, 1, 1, 12, 45, 35, DateTimeKind.Utc), out _);
diff --git a/CDP4Common/CDP4Common.csproj b/CDP4Common/CDP4Common.csproj
index e955a54a..9db05169 100644
--- a/CDP4Common/CDP4Common.csproj
+++ b/CDP4Common/CDP4Common.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4Common Community Edition
- 26.6.1
+ 26.6.2
CDP4 Common Class Library that contains DTOs, POCOs
Copyright © RHEA System S.A.
Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [FIX] Support of space before/after '|' for multivalues enumeration
+ [FIX] Supported values for TimeOfDay ParameterType
README.md
diff --git a/CDP4Common/Validation/ObjectValueValidator.cs b/CDP4Common/Validation/ObjectValueValidator.cs
index 400d0f7f..02423149 100644
--- a/CDP4Common/Validation/ObjectValueValidator.cs
+++ b/CDP4Common/Validation/ObjectValueValidator.cs
@@ -476,11 +476,11 @@ public static ValidationResult ValidateTimeOfDay(this object value, out string c
// date of the dateTime variable is not 1-1-1 the user provided an invalid date. The loophole here is that when a user provides a
// value that includes 1-1-1, it will be validated as being valid.
- var isDateTime = DateTime.TryParse(parsedString, CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.AssumeUniversal, out var dateTime);
+ var isDateTime = DateTime.TryParse(parsedString, CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.RoundtripKind, out var dateTime);
if (isDateTime && dateTime.IsDefaultDateTime())
{
- cleanedValue = dateTime.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture);
+ cleanedValue = ToTimeOfDay(dateTime);
Logger.Debug("TimeOfDay {0} validated", parsedString);
return ValidationResult.ValidResult();
}
@@ -492,7 +492,8 @@ public static ValidationResult ValidateTimeOfDay(this object value, out string c
if (timeOfDayValue.IsDefaultDateTime())
{
- cleanedValue = timeOfDayValue.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture);
+ cleanedValue = ToTimeOfDay(timeOfDayValue);
+
Logger.Debug("TimeOfDay {0} validated", value);
return ValidationResult.ValidResult();
}
@@ -510,5 +511,40 @@ public static ValidationResult ValidateTimeOfDay(this object value, out string c
Message = $"'{value}' is not a valid Time of Day, for valid Time Of Day formats see http://www.w3.org/TR/xmlschema-2/#time."
};
}
+
+ ///
+ /// Converts a object to a CDP compliant TimeOfDay string representation
+ ///
+ /// The
+ /// The correct string format
+ private static string ToTimeOfDay(DateTime dateTime)
+ {
+ string cleanedValue;
+
+ if (dateTime.Kind == DateTimeKind.Utc)
+ {
+ if (dateTime.Millisecond > 0)
+ {
+ cleanedValue = dateTime.ToString("HH:mm:ss.fffZ");
+ }
+ else
+ {
+ cleanedValue = dateTime.ToString("HH:mm:ssZ");
+ }
+ }
+ else
+ {
+ if (dateTime.Millisecond > 0)
+ {
+ cleanedValue = dateTime.ToString("HH:mm:ss.fff");
+ }
+ else
+ {
+ cleanedValue = dateTime.ToString("HH:mm:ss");
+ }
+ }
+
+ return cleanedValue;
+ }
}
}
diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj
index 2f8c9b5d..553348dc 100644
--- a/CDP4Dal/CDP4Dal.csproj
+++ b/CDP4Dal/CDP4Dal.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4Dal Community Edition
- 26.6.1
+ 26.6.2
CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API
Copyright © RHEA System S.A.
Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4DalCommon/CDP4DalCommon.csproj b/CDP4DalCommon/CDP4DalCommon.csproj
index 092a753e..da1da3f6 100644
--- a/CDP4DalCommon/CDP4DalCommon.csproj
+++ b/CDP4DalCommon/CDP4DalCommon.csproj
@@ -5,7 +5,7 @@
RHEA System S.A.
latest
CDP4DalCommon Community Edition
- 26.6.1
+ 26.6.2
CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal
Copyright © RHEA System S.A.
Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime
@@ -21,7 +21,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
true
diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj
index 37d27bf3..2d5354b9 100644
--- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj
+++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4JsonFileDal Community Edition
- 26.6.1
+ 26.6.2
CDP4 Json File Dal Plugin
Copyright © RHEA System S.A.
Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj
index 96777fe0..2db5514f 100644
--- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj
+++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4JsonSerializer Community Edition
- 26.6.1
+ 26.6.2
CDP4 JSON Serialization Library
Copyright © RHEA System S.A.
Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25 JSON
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj
index 0c2f081a..50148fa2 100644
--- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj
+++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4MessagePackSerializer Community Edition
- 26.6.1
+ 26.6.2
CDP4 MessagePack Serialization Library
Copyright © RHEA System S.A.
Sam, Alex, Alexander, Nathanael, Antoine, Omar
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25 MessagePack
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4Reporting/CDP4Reporting.csproj b/CDP4Reporting/CDP4Reporting.csproj
index d93e2b7d..63693bcc 100644
--- a/CDP4Reporting/CDP4Reporting.csproj
+++ b/CDP4Reporting/CDP4Reporting.csproj
@@ -4,7 +4,7 @@
netstandard2.0
RHEA System S.A.
CDP4Reporting Community Edition
- 26.6.1
+ 26.6.2
CDP4 Reporting
Copyright © RHEA System S.A.
Sam, Alex, Alexander
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
latest
README.md
diff --git a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj
index 20c08744..5cbc4283 100644
--- a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj
+++ b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4RequirementsVerification Community Edition
- 26.6.1
+ 26.6.2
CDP4 Class Library that provides requirement verification
Copyright © RHEA System S.A.
Sam, Alex, Alexander, Yevhen, Nathanael
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4Rules/CDP4Rules.csproj b/CDP4Rules/CDP4Rules.csproj
index 45c05818..bf7f816e 100644
--- a/CDP4Rules/CDP4Rules.csproj
+++ b/CDP4Rules/CDP4Rules.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4Rules Community Edition
- 26.6.1
+ 26.6.2
CDP4 Class Library that provides Model Analysis and Rule Checking
Copyright © RHEA System S.A.
Sam, Alex, Alexander, Yevhen, Nathanael
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj
index 7700f95b..0957969b 100644
--- a/CDP4ServicesDal/CDP4ServicesDal.csproj
+++ b/CDP4ServicesDal/CDP4ServicesDal.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4ServicesDal Community Edition
- 26.6.1
+ 26.6.2
CDP4ServicesDal Dal Plugin
Copyright © RHEA System S.A.
Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj
index 89ba7581..cf0fc28c 100644
--- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj
+++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj
@@ -4,7 +4,7 @@
netstandard2.0
RHEA System S.A.
CDP4Common Community Edition
- 26.6.1
+ 26.6.2
CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication
Copyright © RHEA System S.A.
Sam, Alex, Alexander, Nathanael, Antoine
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
latest
diff --git a/CDP4Web/CDP4Web.csproj b/CDP4Web/CDP4Web.csproj
index 8dd8d232..ab670835 100644
--- a/CDP4Web/CDP4Web.csproj
+++ b/CDP4Web/CDP4Web.csproj
@@ -5,7 +5,7 @@
latest
RHEA System S.A.
CDP4Web Community Edition
- 26.6.1
+ 26.6.2
CDP4Web Dedicated Sdk for CDPServicesDal
Copyright © RHEA System S.A.
Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime
@@ -21,7 +21,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md
diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj
index fa75703d..562de0d0 100644
--- a/CDP4WspDal/CDP4WspDal.csproj
+++ b/CDP4WspDal/CDP4WspDal.csproj
@@ -4,7 +4,7 @@
net47;net471;net472;net48;netstandard2.0;netstandard2.1
RHEA System S.A.
CDP4WspDal Community Edition
- 26.6.1
+ 26.6.2
CDP4 WSP Dal Plugin
Copyright © RHEA System S.A.
Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael
@@ -20,7 +20,7 @@
CDP COMET ECSS-E-TM-10-25
LGPL-3.0-only
- [BUMP] To CDP4Common 26.6.1
+ [BUMP] To CDP4Common 26.6.2
README.md