From 54f5fd32330b903afff7cc65eeecd51832e060e6 Mon Sep 17 00:00:00 2001
From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com>
Date: Wed, 30 Oct 2024 12:28:05 +0530
Subject: [PATCH] Use DateTimeOffset instead of DateTime for DatePropertyValue
---
.../Models/PropertyValue/DatePropertyValue.cs | 7 ++-
.../PageClientTests.cs | 61 ++++++++++++++++++-
2 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs
index 22715b2e..7467936b 100644
--- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs
+++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
namespace Notion.Client
{
@@ -26,13 +27,15 @@ public class Date
/// Start date with optional time.
///
[JsonProperty("start")]
- public DateTime? Start { get; set; }
+ [JsonConverter(typeof(IsoDateTimeConverter))]
+ public DateTimeOffset? Start { get; set; }
///
/// End date with optional time.
///
[JsonProperty("end")]
- public DateTime? End { get; set; }
+ [JsonConverter(typeof(IsoDateTimeConverter))]
+ public DateTimeOffset? End { get; set; }
///
/// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are
diff --git a/Test/Notion.IntegrationTests/PageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs
index 21adbd5b..31678d73 100644
--- a/Test/Notion.IntegrationTests/PageClientTests.cs
+++ b/Test/Notion.IntegrationTests/PageClientTests.cs
@@ -216,8 +216,8 @@ public async Task Test_UpdatePageProperty_with_date_as_null()
{
Date = new Date
{
- Start = Convert.ToDateTime("2020-12-08T12:00:00Z"),
- End = Convert.ToDateTime("2025-12-08T12:00:00Z")
+ Start = DateTimeOffset.Parse("2024-06-26T00:00:00.000+01:00"),
+ End = DateTimeOffset.Parse("2025-12-08").Date
}
})
.Build();
@@ -236,7 +236,8 @@ public async Task Test_UpdatePageProperty_with_date_as_null()
);
// Assert
- setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z"));
+ setDate?.Date?.Start.Should().Be(DateTimeOffset.Parse("2024-06-26T00:00:00.000+01:00"));
+ setDate?.Date?.End.Should().Be(DateTimeOffset.Parse("2025-12-08T00:00:00.000+01:00"));
var pageUpdateParameters = new PagesUpdateParameters
{
@@ -384,4 +385,58 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin
updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue");
updatedPage.Properties["Colors2"].As().Select.Should().BeNull();
}
+
+ [Fact]
+ public async Task Verify_date_property_is_parsed_correctly_in_mention_object()
+ {
+ var pageRequest = PagesCreateParametersBuilder
+ .Create(new DatabaseParentInput { DatabaseId = _database.Id })
+ .AddProperty("Name",
+ new TitlePropertyValue
+ {
+ Title = new List
+ {
+ new RichTextMention()
+ {
+ Mention = new Mention()
+ {
+ Page = new ObjectId()
+ {
+ Id = _page.Id,
+ },
+ Date = new DatePropertyValue()
+ {
+ Date = new Date()
+ {
+ Start = DateTime.UtcNow
+ }
+ }
+ }
+ }
+ }
+ })
+ .Build();
+
+ var page = await Client.Pages.CreateAsync(pageRequest);
+
+ page.Should().NotBeNull();
+
+ page.Parent.Should().BeOfType().Which
+ .DatabaseId.Should().Be(_database.Id);
+
+ page.Properties.Should().ContainKey("Name");
+ var pageProperty = page.Properties["Name"].Should().BeOfType().Subject;
+
+ var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync(
+ new RetrievePropertyItemParameters
+ {
+ PageId = page.Id,
+ PropertyId = pageProperty.Id
+ });
+
+ titleProperty.Results.First()
+ .As()
+ .Title.As()
+ .Mention.Date.Date.Should().NotBeNull();
+ }
}