-
Notifications
You must be signed in to change notification settings - Fork 226
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
[docs] Clarify that DateTimeKnownEncoding.unixTimestamp is seconds (not milliseconds) #2887
Comments
Unix time as far as I understand it is properly understood to be seconds since epoch and stored in a 32 bit integer. |
And yeah, the docs should be updated. We called the scalar type |
@bterlson: For the spec in question: Azure/autorest.csharp#4189 (comment) The service does use milliseconds since epoch. How should this be represented in TypeSpec? |
I think we have to add a known encoding for that? @timotheeguerin may know more. Also note that you would probably encode it as a safeint instead of an int64 (53 bits is good enough for 285 ka with ms granularity). |
yeah we'd have to define a new encoding as just saying the same encoding on an If we want to have a type that allows second we should have a And yeah lets update the docs to be clear that this encoding means encoded as an integer of seconds |
This website seems to be showing a good set of examples how unixtimestamp with millisseconds is represented in different language Usually seems to either have no way to do it or just suffixed with milliseconds |
I am not sure I like changing the semantics of the encoded value based on the data type you store the ecoded value in? Do we have other cases of that? Also I would prefer to see safeint in virtually all instances of this (int64 has interoperability issues in JSON), and it's less clear that safeint implies ms granularity. |
I mean @encode("unixTimestamp", int32)
scalar unixTimestamp32 extends utcDateTime;
@encode("unixTimestamp", int64)
scalar unixTimestamp64 extends utcDateTime; // This is seconds it is consitent we are just saying that the data type used is int64 not int32
// Now here we define a different encoding
@encode("unixTimestampMilliseconds", int64)
scalar unixTimestampMilliseconds64 extends utcDateTime; |
ah ok sorry I misread your comment. Yes, I think that's the general shape of things, though we could bikeshed name some (and also probably want to add a scalar for the safeint variant). |
est: 1 |
…g of unixTimestamp (#2893) fix #2892 Clarify `numeric`, `integer`, `decimal`, `float` fix #2887 Clarify unixTimestamp encoding --------- Co-authored-by: Brian Terlson <[email protected]>
@timotheeguerin: Can you please update https://github.com/microsoft/typespec/blob/main/docs/libraries/http/encoding.md#utcdatetime-and-offsetdatetime as well? As stated in the OP, the example is very misleading (shows a value of milliseconds since epoch). |
I think the documentation for
DateTimeKnownEncoding.unixTimestamp
at https://github.com/microsoft/typespec/blob/main/docs/libraries/http/encoding.md#utcdatetime-and-offsetdatetime can be improved:Specify that the timestamp is the number of seconds since the epoch (not milliseconds like JavaScript
Date
).Update the example payload to use timestamp in seconds rather than milliseconds:
Related:
The text was updated successfully, but these errors were encountered: