microsoft / api-guidelines

Microsoft REST API Guidelines
Other
22.78k stars 2.71k forks source link

Feedback on Dates and Times in Section 11 #22

Open mattjohnsonpint opened 8 years ago

mattjohnsonpint commented 8 years ago

Please review the following constructive criticism with regard to the date and time guidelines in section 11.

Iso8601Literal is poorly defined

To address all of these, the guidance should recommend using the date-time and full-date formats defined in RFC 3339 § 5.6.

StructuredDateLiteral is not good advice

Thanks.

garethj-msft commented 8 years ago

Matt, thank you very much for the detailed feedback.

maggiepint commented 8 years ago

I'll generally just agree with Matt here, but would add the following:

Informally, a DateValue is either an ISO 8601-formatted string or a JSON object containing two properties named kind and value that together define a point in time.

This text assumes that all date values exchanged by a REST API are defined by a point in time. This assumption is incorrect and does not hold water in the real world.

For instance, one might want to express this information in an API:

All Microsoft store locations open at 05:00 in the morning on Black Friday in 2016.

This is a datetime value, that would be expressed by the ISO8601 standard as 2016-11-25T05:00:00.00, where this is interpreted as local time to the store. It is not any single point on the global timeline.

You may also encounter time-only situations like

All Microsoft store locations open at 11:00 on Saturdays

Again, there is no reference to a point in time, and this should be interpreted as time local to the store. RFC 3339 would specify this as partial-time in the format 11:00:00.

This documentation should explicitly state that absent an offset values shall be interpreted as local time (which may vary based on the context of the problem domain). While ISO8601 and ECMAScript already say this, most people won't go look it up, so if this is best practice documentation, best to put it in. It should also be noted that these formats should only be used if you mean local time. If you mean time that represents a point on the global timeline, ISO8601 with offset should almost universally be used.

On that note, I will echo that StructuredDateLiteral is not good advice. If these formats had to be handled, I guess it would be a way to do it. That said, this appears to be best practice documentation. The best practice would be to keep formats like that inside your own ecosystem, and convert to ISO8601 for data transfer purposes. Anything else would be in conflict with established internet norms.

Happy to think harder about the local time documentation and make a pull if you would like one.

mattjohnsonpint commented 8 years ago

Yes, I'll agree with Maggie's statements (thank you). The partial-time format is indeed worth adding.

On the Black Friday example, I suppose that is indeed a valid value - and one might get it by using a .NET DateTime having DateTimeKind.Unspecified. However - in the vast majority of use cases I've encountered - the value is usually intended to describing a specific moment in time, rather than a floating value. I'll suggest then that the guidance say something like the following:

A date+time value MUST include a time zone offset in the form +/-HH:MM (or Z for UTC) if it is intended to represent a specific instant in time. A date+time value without an offset specified is assumed to be in some local time, or could be interpreted as a floating time value, not belonging to any specific time zone.

Does that make sense?

mattjohnsonpint commented 8 years ago

@garethj-msft - No problem, glad to help. I'm going to ask some of the other @mspnp guys to take a look at the other parts of the guidelines also. Date/time just happens to be my thing. :smile: