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

Change timestamp format #106

Open
benfrancis opened this issue Jan 20, 2022 · 3 comments
Open

Change timestamp format #106

benfrancis opened this issue Jan 20, 2022 · 3 comments

Comments

@benfrancis
Copy link
Member

Utils.timestamp() currently generates timestamps in the following format:

2022-01-20T17:21:12+00:00

For some reason the default output of Date().toISOString() is modified so that it ends in "+00:00" rather than "Z". This is probably because that's the format used by the examples do in the Web Thing API specification.

The latest draft of the W3C WoT Profile specification constrains the date format so that it must end in "Z".

I therefore propose changing the timestamp method to return the raw output of Date().toISOString() rather than modify it, so that datestamps look like:

2011-10-05T14:48:00.000Z

Before doing this we should check if it breaks anything.

Also, double check that the milliseconds portion of the datestamp is expected by WoT Profile.

Note: These timestamps are used in action resources in the gateway's API to show the requested and completed times of an action, and also for the timestamps of events. I'm not really sure why the gateway uses this utility function from the add-on library and they can probably call Date().toISOString() directly instead. If this utility function isn't used anywhere else then it could probably just be removed.

@adioanca
Copy link

The absence of .123 miliseconds poses a problem when one has multiple events generated in 1 second.
I am tracking multiple events in a custom UI and their (sorted) order is incorrect.

looking at https://w3c.github.io/wot-profile/#date-format I can see the following:

All date and time values MUST use the canonical dateTime representation format defined in section 3.2.7 of [xmlschema-2].

As described by this section the following constraints must be observed: All dateTime values SHOULD use UTC as the time zone and use the 'Z' identifier. 

and https://www.w3.org/TR/xmlschema-2/#dateTime under 3.2.7.1 says:

The [·lexical space·](https://www.w3.org/TR/xmlschema-2/#dt-lexical-space) of dateTime consists of finite-length sequences of characters of the form: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?, where
[...]

I think the current Utils.timestamp() should be upgraded asap, and just use Date.toISOString()

@benfrancis
Copy link
Member Author

Thanks for this valuable feedback, I agree that one second resolution is not enough.

Regarding the WoT Profile specification, I'm afraid the situation is still in flux because there are still inconsistent and broken references which need fixing. I have an open pull request which suggests consolidating on RFC 3339.

I need to check whether Date.toISOString() conforms with that specification, which is a kind of a profile of ISO 8601, but I think that it probably does.

@benfrancis
Copy link
Member Author

The latest draft of WoT Profile only requires that timestamps conform to RFC3339, which does allow both numerical timezone offsets and "Z". As I understand it that means the timestamps used by the gateway do now comply with the specification.

However, I think we should still change the gateway to use Date().toISOString() directly to allow millisecond precision timestamps.

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

2 participants