Skip to content

Commit

Permalink
TimeOfDayParameterType conversion doesn't work as expected; fixes #328
Browse files Browse the repository at this point in the history
TimeOfDayParameterType conversion doesn't work as expected
  • Loading branch information
lxatstariongroup authored Apr 11, 2024
1 parent 91eae73 commit 6668b10
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 _);
Expand Down
21 changes: 16 additions & 5 deletions CDP4Common.Tests/Validation/DtoValueValidatorTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public void VerifyTextParameterTypeValidationAndCleanup()
Assert.That(result.ResultKind, Is.EqualTo(ValidationResultKind.Invalid));
}


[Test]
public void VerifyTimeOfDayParameterTypeValidationAndCleanup()
{
Expand All @@ -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";
Expand All @@ -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 _);
Expand Down
4 changes: 2 additions & 2 deletions CDP4Common/CDP4Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[FIX] Support of space before/after '|' for multivalues enumeration
[FIX] Supported values for TimeOfDay ParameterType
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
42 changes: 39 additions & 3 deletions CDP4Common/Validation/ObjectValueValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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."
};
}

/// <summary>
/// Converts a <see cref="DateTime"/> object to a CDP compliant TimeOfDay string representation
/// </summary>
/// <param name="dateTime">The <see cref="DateTime"/></param>
/// <returns>The correct string format</returns>
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;
}
}
}
4 changes: 2 additions & 2 deletions CDP4Dal/CDP4Dal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Dal Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4DalCommon/CDP4DalCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>RHEA System S.A.</Company>
<Language>latest</Language>
<Title>CDP4DalCommon Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime</Authors>
Expand All @@ -21,7 +21,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
4 changes: 2 additions & 2 deletions CDP4JsonFileDal/CDP4JsonFileDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4JsonFileDal Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Json File Dal Plugin</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4JsonSerializer/CDP4JsonSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4JsonSerializer Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 JSON Serialization Library</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25 JSON</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4MessagePackSerializer Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 MessagePack Serialization Library</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25 MessagePack</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Reporting/CDP4Reporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Reporting Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Reporting</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<LangVersion>latest</LangVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4RequirementsVerification Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Class Library that provides requirement verification</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Rules/CDP4Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Rules Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Class Library that provides Model Analysis and Rule Checking</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4ServicesDal/CDP4ServicesDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4ServicesDal Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4ServicesDal Dal Plugin</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4ServicesMessaging/CDP4ServicesMessaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Web/CDP4Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<Company>RHEA System S.A.</Company>
<Title>CDP4Web Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4Web Dedicated Sdk for CDPServicesDal</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime</Authors>
Expand All @@ -21,7 +21,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions CDP4WspDal/CDP4WspDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4WspDal Community Edition</Title>
<VersionPrefix>26.6.1</VersionPrefix>
<VersionPrefix>26.6.2</VersionPrefix>
<Description>CDP4 WSP Dal Plugin</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.1
[BUMP] To CDP4Common 26.6.2
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down

0 comments on commit 6668b10

Please sign in to comment.