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

Option for choosing the Date format #177

Open
katyatitkova opened this issue Jun 3, 2024 · 1 comment · May be fixed by #188
Open

Option for choosing the Date format #177

katyatitkova opened this issue Jun 3, 2024 · 1 comment · May be fixed by #188

Comments

@katyatitkova
Copy link
Contributor

The Date type currently includes the time as part of the date:

type Date time.Time

func (d *Date) String() string {
	return time.Time(*d).Format(time.RFC3339)
}

func (d Date) MarshalText() ([]byte, error) {
	return []byte(d.String()), nil
}

As a result, all Date properties filled using notionapi will have the time part visible in the Notion UI (until the user manually turns off the "Include time" option for that property on a particular page).

When I change time.RFC3339 to "2006-01-02" locally, only the date part is sent, and only the date part is visible in the Notion UI.

Would it be possible to add an option to choose the date format that is sent to Notion? This would allow users to select whether they want to include the time or not. I don't have much experience with Go, so I'm wondering if it's possible to make this change in a backward-compatible manner. If it's not, then I can continue to use my forked version.

@julien040
Copy link

Hello,
I have the same issue with one of my projects.

To avoid breaking existing code and to fix the issue, I thought about adding a dateOnly field to DateObject

type DateObject struct {
	Start *Date `json:"start"`
	End   *Date `json:"end"`
	DateOnly bool
}

Then, implement a custom MarshalJSON() for the struct to switch between "2006-01-02" and time.RFC3339, depending on whether the DateOnly field is set.

I can create a pull request if you'd like.

aydinomer00 added a commit to aydinomer00/notionapi that referenced this issue Dec 30, 2024
- Add Date struct with DateOnly flag
- Implement custom date formatting for Notion API
- Add comprehensive test coverage
- Fix timezone formatting in FormatForNotion
- Handle null values in UnmarshalJSON
- Closes jomei#177
@aydinomer00 aydinomer00 linked a pull request Dec 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants