Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DateOnly / TimeOnly in DynamoDBContext #3677

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test that saved DateOnly is successully read as DateTime
  • Loading branch information
Dreamescaper committed Feb 27, 2025
commit c992d2fea127d015477aafdcfe21d19dc026eefc
Original file line number Diff line number Diff line change
@@ -249,8 +249,8 @@ public void V2_ConvertToEntry_HashSet()
[DynamicData((nameof(DynamoDBEntryConversions)))]
public void ConvertToEntry_DateOnly(DynamoDBEntryConversion conversion)
{
var dateTime = new DateOnly(2024, 07, 03);
var entry = conversion.ConvertToEntry(dateTime);
var dateOnly = new DateOnly(2024, 07, 03);
var entry = conversion.ConvertToEntry(dateOnly);
Assert.AreEqual(new Primitive("2024-07-03", false), entry);
}

@@ -259,17 +259,17 @@ public void ConvertToEntry_DateOnly(DynamoDBEntryConversion conversion)
public void ConvertFromEntry_DateOnly(DynamoDBEntryConversion conversion)
{
var entry = new Primitive("2024-07-03", false);
var actualDateTime = conversion.ConvertFromEntry<DateOnly>(entry);
var expectedDateTime = new DateOnly(2024, 07, 03);
Assert.AreEqual(expectedDateTime, actualDateTime);
var actualDateOnly = conversion.ConvertFromEntry<DateOnly>(entry);
var expectedDateOnly = new DateOnly(2024, 07, 03);
Assert.AreEqual(expectedDateOnly, actualDateOnly);
}

[DataTestMethod]
[DynamicData((nameof(DynamoDBEntryConversions)))]
public void ConvertToEntry_TimeOnly(DynamoDBEntryConversion conversion)
{
var dateTime = new TimeOnly(18, 31, 56, 123);
var entry = conversion.ConvertToEntry(dateTime);
var timeOnly = new TimeOnly(18, 31, 56, 123);
var entry = conversion.ConvertToEntry(timeOnly);
Assert.AreEqual(new Primitive("18:31:56.123", false), entry);
}

@@ -278,8 +278,21 @@ public void ConvertToEntry_TimeOnly(DynamoDBEntryConversion conversion)
public void ConvertFromEntry_TimeOnly(DynamoDBEntryConversion conversion)
{
var entry = new Primitive("18:31:56.123", false);
var actualDateTime = conversion.ConvertFromEntry<TimeOnly>(entry);
var expectedDateTime = new TimeOnly(18, 31, 56, 123);
var actualTimeOnly = conversion.ConvertFromEntry<TimeOnly>(entry);
var expectedTimeOnly = new TimeOnly(18, 31, 56, 123);
Assert.AreEqual(expectedTimeOnly, actualTimeOnly);
}

[DataTestMethod]
[DynamicData((nameof(DynamoDBEntryConversions)))]
public void ConvertFromEntry_ShouldBeAbleToReadDateOnlyAsDateTime(DynamoDBEntryConversion conversion)
{
var dateOnly = new DateOnly(2024, 07, 03);
var entry = conversion.ConvertToEntry(dateOnly);

var actualDateTime = conversion.ConvertFromEntry<DateTime>(entry);
var expectedDateTime = new DateTime(2024, 07, 03, 0, 0, 0, DateTimeKind.Utc);

Assert.AreEqual(expectedDateTime, actualDateTime);
}
#endif