-
Notifications
You must be signed in to change notification settings - Fork 53
Date without time component #339
Unanswered
chrisstuart-cl
asked this question in
Q&A
-
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();
}
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
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))
}
}
}
});
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment