Creating new dates with timestamp from content studio fails

Enonic version: 7.4.0
OS: os x

Hi

When I use a date from content studio as a parameter in the new Date() constructor, it fails when the timestamp has more than three milliseconds integers.

This timestamp will create a new date object: 2020-10-14T08:15:24.307Z
This timestamp will fail to create a new date object: 2020-10-14T08:15:24.3072Z.

The (new?) standard format for published.from are now 6 integers long, which will also fail when used as argument in new Date().

I am not sure what I can do or should do. Is there a way to configure content studio to only use 3 integers, or do I need to update anything, or do I need to write code to remove the integers, or is it a bug?

I guess the main problem might be the Nashorn version doesn’t support those timestamps.

Sincerely
Øyvind

1 Like

It’s not Content Studio that does that, this is how dates are stored on the server.
Why don’t you conversion client-side? It works fine regardless of the milliseconds format:

image

Aha.

I use it to compare dates and want to do that server-side. In this case i think the logic should be in the controller, and not sent to the client.

When was this changed? I see that “old” published content still have 3 digits, but all new published content have 6.

It changed in XP7 and was caused by increased time precision in Java 9. XP6 was on Java 8 while XP 7 is on Java 11.

Thanks!

I ended up using a regexp to find and remove the numbers I didn’t want back-end.