Bug: time attribute is always a string, yet is type casted to string | Date
See original GitHub issueIt appears that time
constructor attribute value, which can be Date
is always converted to a string:
The setter also converts to a string:
Yet, the value of the getter is type casted to string | Date
. This is actually confusing and leads to buggy behavior.
This led me to a wrong conclusion, that if I pass a Date
it will remain a Date
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Conversion failed when converting date and/or time from ...
Conversion failed when converting date and/or time from character string. The reason for this error is simply there is no such date (Feb-29)...
Read more >Data Conversion - Error when trying to convert string to date
The Data Conversion component will work fine - but it only works when the string data is formatted properly, which is almost never...
Read more >How to Handle the Incompatible Types Error in Java - Rollbar
The main method in Fig. 2(a) declares the variable date which holds the current date as a String in the yyyy-MM-dd format ...
Read more >How to Convert a String to a Date In Swift - Cocoacasts
The DateFormatter is powerful, but it isn't magical. It cannot infer the date format of the string. That is something we need to...
Read more >Java 8 - How to convert String to LocalDate - Mkyong.com
If the String is in ISO_LOCAL_DATE format, we can parse the String directly, no need conversion. JavaDateExample1.java. package com.mkyong.date; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@moltar - good catch. All of this conversion with the
time
attribute is done because the spec for JSON representation of an event specifically requires a string. But I think this is highlighting a deeper issue related to the JSON representation.When we refactored this repository into TypeScript, there was an effort to create the
CloudEvent
class in such a way that simply doingconsole.log(event)
would result in a JSON representation adhering to the spec. This breaks down in a few places and is why you see some attribute transformation as in this case.I think we need to consider the fact that the
CloudEvent
class has to be explicitly transformed viatoString()
andJSON.stringify()
in order to have a valid JSON representation of an event. We are working on some big API changes for the 4.0.0 version, and I think that this question should be addressed in 4.0. Resolving this, would result in a fix for what you highlight here, as well.@cloudevents/sdk-javascript-maintainers any thoughts on this?
Thanks! 😃