8000 Use DateTimeOffset instead of DateTime for DatePropertyValue by KoditkarVedant · Pull Request #422 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Use DateTimeOffset instead of DateTime for DatePropertyValue #422

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Notion.Client
{
Expand All @@ -26,13 +27,15 @@ public class Date
/// Start date with optional time.
/// </summary>
[JsonProperty("start")]
public DateTime? Start { get; set; }
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset? Start { get; set; }

/// <summary>
/// End date with optional time.
/// </summary>
[JsonProperty("end")]
public DateTime? End { get; set; }
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTimeOffset? End { get; set; }

/// <summary>
/// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are
Expand Down
61 changes: 58 additions & 3 deletions Test/Notion.IntegrationTests/PageClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
{
Expand Down Expand Up @@ -384,4 +385,58 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin
updatedPage.Properties["Colors1"].As<SelectPropertyValue>().Select.Name.Should().Be("Blue");
updatedPage.Properties["Colors2"].As<SelectPropertyValue>().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<RichTextBase>
{
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<DatabaseParent>().Which
.DatabaseId.Should().Be(_database.Id);

page.Properties.Should().ContainKey("Name");
var pageProperty = page.Properties["Name"].Should().BeOfType<TitlePropertyValue>().Subject;

var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync(
new RetrievePropertyItemParameters
{
PageId = page.Id,
PropertyId = pageProperty.Id
});

titleProperty.Results.First()
.As<TitlePropertyItem>()
.Title.As<RichTextMention>()
.Mention.Date.Date.Should().NotBeNull();
}
}
Loading
0