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

Add fractional second support to timestamps #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

O1O1O1O
Copy link

@O1O1O1O O1O1O1O commented Feb 28, 2017

RFC-3339 supports fractional seconds as does the ISO-8601 but the regexp being used for validation of timestamp strings did not allow them for a TJSON timestamp value.

Technically the RFC-3339 specification allows use of a comma , as well as decimal point . for the whole and fractional seconds separator:

time-fraction = ("," / ".") 1*DIGIT

Although use of , is common in European countries, in the interests of eliminating equivalent but lexically different encodings which would have a different cryptographic hash, this change only allows the decimal point as the separator. Thus 2016-10-02T07:31:51.42Z is a valid timestamp, but 2016-10-02T07:31:51,42Z is not.

RFC-3339 supports fractional seconds as does the ISO-8601 but the regexp being used for validation of timestamp strings did not support it.

Technically the [RFC-3339 specification](https://www.ietf.org/rfc/rfc3339.txt) allows use of a comma `,` as well as decimal point `.` for the whole and fractional seconds separator:

>  time-fraction     = ("," / ".") 1*DIGIT

Although use of `,` is common in European countries, in the interests of eliminating equivalent but lexically different encodings which would have a different cryptographic hash, this change only allows the decimal point as separator.  Thus `2016-10-02T07:31:51.42Z` is a valid timestamp, but `2016-10-02T07:31:51,42Z` is not.
@O1O1O1O
Copy link
Author

O1O1O1O commented Feb 28, 2017

I see that this could cause an inconsistency with your pretty generate since the standard iso8601 output does not include fractional seconds so accuracy would be lost in parsing and generating TJSON again. A workaround might be a precision digit for the t tag so t<n> to force output of digits of precision - available in Ruby with a parameter to the iso8601 method i.e. iso8601(n).

Another alternative would be to say you always output however many significant non-zero digits it takes to convey the fractional seconds part if it is non-zero. So if you're given timestamps without a fraction you don't output them with a decimal point for seconds. If has a fractional part you output as many digits as is necessary (I believe the accuracy is generally milli, micro or nanoseconds) but no more.

A combination would be to do the default, but allow override with a precision digit. So if it is 3.75 seconds and you specify timestamp-field:t6 for microsecond precision then you output 3.750000

Despite all these potential issues I still think fractional second support is important for timestamps. There are so many uses where a second resolution just doesn't cut it.

@tarcieri
Copy link
Contributor

tarcieri commented Mar 1, 2017

Note that the spec presently mandates Z-normalized RFC 3339 timestamps:

https://www.tjson.org/spec/#rfc.section.3.4

Subsecond precision is not addressed in the spec, but should probably be allowed. If it is allowed it should be called out in the spec and added to the test cases.

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

Successfully merging this pull request may close these issues.

2 participants