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

Issue with format of type EntryFields.Date #2347

Open
venerated opened this issue Oct 4, 2024 · 0 comments
Open

Issue with format of type EntryFields.Date #2347

venerated opened this issue Oct 4, 2024 · 0 comments

Comments

@venerated
Copy link

venerated commented Oct 4, 2024

I don't think this is necessarily a bug, but I have hit a dead-end trying to work around it, and searching has come up empty.

From node_modules/contentful/dist/types/types/entry.d.ts:

type Date = `${number}-${number}-${number}T${number}:${number}:${number}Z`

so when trying to make a content API call with parameters like...

{
        content_type: 'event',
        include: 10,
        locale: locale.value,
        limit: 500,
        'fields.startDatetime[gte]': new Date()
  }

there is a TypeScript error, since the date is formatted incorrectly. This is of course a simplified version, the date is set by the user.

Where I am running into an issue is that there is no good way to format a date to work with this format.

Even if I create a helper function that returns the individual values formatted in the string Contentful expects, the individual numbers become an issue if they're less than 10, because I can't prepend a 0, since it's a number. So for example, if the day or month are less than 10, I end up with a string that looks like this 1-1-2024T11:59:59 which does not work when sending the request to Contentful, the date needs to be formatted like 01-01-2024T11:59:59.

Thank you in advanced for any insight or help.

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

No branches or pull requests

1 participant