Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Date without time component#339

Unanswered
chrisstuart-cl asked this question inQ&A
Discussion options

I add a task to a list using this code. The due date always appears with a time component. Is there a way to switch off the Notion time component in the API?

AddTaskToDatabase(client, "<database id>", "<task name>", DateTime.Now.Date);public void AddTaskToDatabase(NotionClient client, string databaseId, string taskName, DateTime dueDate){    var pagesCreateParameters = new PagesCreateParameters();    var databaseParent = new DatabaseParentInput()    {        DatabaseId = databaseId    };    pagesCreateParameters.Parent = databaseParent;    var titleProperty = new TitlePropertyValue    {        Title = new List<RichTextBase>                {                     new RichTextText                     {                         Text = new Text                         {                             Content = taskName                         }                     }                }    };    pagesCreateParameters.Properties = new Dictionary<string, PropertyValue>();    pagesCreateParameters.Properties.Add("Name", titleProperty);    var selectOption = new SelectOption() { Name = "ToDo", Id = "1" };    pagesCreateParameters.Properties.Add("Status", new SelectPropertyValue() { Select = selectOption });    pagesCreateParameters.Properties.Add("Due Date", new DatePropertyValue() { Date = new Notion.Client.Date() { Start = dueDate}});    var page = client.Pages.CreateAsync(pagesCreateParameters);    page.Wait();}
You must be logged in to vote

Replies: 1 comment

Comment options

Work-around for now:

DateWithoutTimePropertyValue.cs - using Newtonsoft.Json;namespace Notion.Client;/// <summary>/// Date without time property value object./// </summary>public class DateWithoutTimePropertyValue : PropertyValue{    public override PropertyValueType Type => PropertyValueType.Date;    /// <summary>    /// Date    /// </summary>    [JsonProperty("date", NullValueHandling = NullValueHandling.Include)]    public DateWithoutTime Date { get; set; }}/// <summary>/// Date without time value object./// </summary>public class DateWithoutTime{    [JsonProperty("start")]    private string? StartValue    {        get => Start?.ToString("yyyy-MM-dd");        set => Start = value is null ? null : DateOnly.Parse(value);    }    /// <summary>    /// Start date with optional time.    /// </summary>    [JsonIgnore]    public DateOnly? Start { get; set; }    [JsonProperty("end")]    private string? EndValue    {        get => End?.ToString("yyyy-MM-dd");        set => End = value is null ? null : DateOnly.Parse(value);    }    /// <summary>    /// End date with optional time.    /// </summary>    [JsonIgnore]    public DateOnly? End { get; set; }}

Usage:

await client.Pages.UpdatePropertiesAsync("00000000000000000000000000000000", new Dictionary<string, PropertyValue>(){    {        "aaa", new DatePropertyValue        {            Id = "aaa",            Date = new()            {                Start = DateOnly.FromDateTime(DateTime.UtcNow)            }        }    },    {        "bbb", new DatePropertyValue        {            Id = "bbb",            Date = new()            {                Start = DateOnly.FromDateTime(DateTime.UtcNow),                End = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(1))            }        }    }});
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@chrisstuart-cl@olegfridman

[8]ページ先頭

©2009-2025 Movatter.jp