Closed mcastrup closed 4 months ago
Hi Michael,
thanks for digging into to the code to find the culprit. I had confirmed with the runtime team beforehand that in almost all cases, cds Date
is in fact supposed to be a string
, hence my comment in the code. Could you please show the intended use in your code? Could be that you are just one .toString()
away from the solution.
Best, Daniel
Hi Michael,
I confirmed with the runtime team again that dates in your entities will in fact be strings during runtime. As they are stored as such in the database, converting them to JS Date
objects every time would impose a performance hit on the runtime and the most common case for dates is to funnel them from the DB to the frontend anyway. If you need them as dates to do calculations on them, you can convert them to Date
objects in your handler code:
this.on('READ', Receivables, ({data}) => {
const d = new Date(data.documentDate)
d.setDate(d.getDate() + 7) // one week later
})
I will remove the misleading comment from the the Builtins
.
Best, Daniel
Question
I noticed that an element of a CDS entity with the type 'Date' has the type 'string' in the generated types. E.g. see the element
documentDate
:leads to
There is a comment in your
Builtins
object, in which you already stated that 'Date' may be needed:We get now errors in our code like
Type 'Date' is not assignable to type 'string'
, because the generated type of the element is 'string' instead of 'Date'.Can you change this behavior or can it be configured somehow?
Thanks and best regards, Michael