question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add DateTime to transformValue in forms

See original GitHub issue

When working with forms it is quite a nuisance when dealing with Dates. Currently, Prisma only accepts dates as ISO strings. If you use the <DatetimeLocalField /> from the form package you will receive an error by default.

Expected type "DateTime". DateTime cannot represent an invalid date-time-string 2020-11-19T14:50.

You eventually have to transform it yourself before submitting that data to be stored. new Date(data.date).toISOString())

I believe the solution is simply to add DateTime to the COERCION_FUNCTIONS in the forms package https://github.com/redwoodjs/redwood/blob/6aa9a28f5f3db8d69aced7cab4eb3880734ae6b7/packages/forms/src/coercion.tsx#L24-L29

Also maybe the DateTimeField could automatically convert the incoming ISO string to a format that the input can accept

const date = "2020-11-12T22:08:00.000Z"

// using date-fn-timezone here to help convert since it is store as iso in prisma
const convertToDateTimeLocale = (date) => {
 return formatToTimeZone(date, 'YYYY-M-DTHH:mm:ss.SSS', {
    timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
  })
}
convertToDateTimeLocale(date)
// expected output  = 2020-11-12T22:08:00

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
cannikincommented, Feb 23, 2021

Hmm, I could have sworn that using the <DatetimeLocalField> would output the proper format for GraphQL/Prisma and that it serialized it back to a string properly to pre-fill the form later. It’s possible that sometime between whenever this was written and 2.16 of Prisma that something changed somewhere?

If someone could PR a fix and show it working we’d happily accept it!

1reaction
KrisCoulsoncommented, Mar 3, 2021

@thedavidprice @cannikin I can circle back on this one. I posted this I think back in November. I’ll look to get a PR up here soon. I didn’t see my mentions on this until today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to append datetime value to formdata and receive it in ...
DateTime fromDate = Convert.ToDateTime(Request.Form["start"]).Date;. Depending on your machine's culture settings you may need to use DateTime.
Read more >
<input type="datetime-local"> - HTML - MDN Web Docs
A string representing the value of the date entered into the input. The format of the date and time value used by this...
Read more >
Inserting the value from Datetime field form - Drupal Answers
Any suggestions or how should I process the value from the form so I can insert it into the db? Alternatively, any way...
Read more >
DateValue, TimeValue, and DateTimeValue functions in ...
DateTimeValue function converts a date and time string (for example, "January 10, 2013 12:13 AM") to a date/time value. DateValue function ...
Read more >
SAS Date, Time, and Datetime Values
SAS datetime value: is a value representing the number of seconds between ... figure shows some dates written in calendar form and as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found