camaraproject / Commonalities

Repository to describe, develop, document and test the common guidelines and assets for CAMARA APIs
Apache License 2.0
12 stars 25 forks source link

Proposal to add a standard for defining durations for API Design guidelines #137

Open mhfoo opened 8 months ago

mhfoo commented 8 months ago

Problem description Proposal to add a standard for defining durations for CAMARA APIs.

Possible evolution

Use ISO 8601 Durations as the definition for duration. Under API Design Guidelines: 11.5 Data Definitions, add a bullet point to define duration, with reference to ISO 8601 Durations, with the following type and format.

If the format of a string is duration, the following sentence must be present in the description: 'It must follow ISO 8601 Durations'

Alternative solution N.A

Additional context Have a common definition for duration when designing CAMARA APIs. Example: Searching or querying records for the previous stated time duration:

PS. Referring to wikipedia

mhfoo commented 8 months ago

@jpengar FYI above

rartych commented 8 months ago

The duration format proposed by OpenAPI Initiative refers to - RFC3339,

Durations:
   dur-second        = 1*DIGIT "S"
   dur-minute        = 1*DIGIT "M" [dur-second]
   dur-hour          = 1*DIGIT "H" [dur-minute]
   dur-time          = "T" (dur-hour / dur-minute / dur-second)
   dur-day           = 1*DIGIT "D"
   dur-week          = 1*DIGIT "W"
   dur-month         = 1*DIGIT "M" [dur-day]
   dur-year          = 1*DIGIT "Y" [dur-month]
   dur-date          = (dur-day / dur-month / dur-year) [dur-time]
   duration          = "P" (dur-date / dur-time / dur-week)

It is more related to OAS 3.1 as indicated here: https://github.com/camaraproject/Commonalities/issues/93#issuecomment-1841531161

mhfoo commented 7 months ago

@rartych

Thanks for pointing it out in your comment: Formats Registry.

What is your recommendation for duration format to refer to?

hdamker commented 7 months ago

Without presenting an own opinion I would like to mention two use cases of "duration" which we are currently using in QualityOnDemand (and the sub project is aware that this need to consolidated, see https://github.com/camaraproject/QualityOnDemand/issues/249):

hdamker commented 7 months ago

The duration format proposed by OpenAPI Initiative refers to - RFC3339,

It is maybe worth to note that RFC3339 explicitly does not cover time periods but only timestamps:

Description of time periods, or intervals, is not covered here.

The grammar given in Annex A is informal. In addition is the duration format on its own ambiguous regarding the total number of days in a calendar year and calendar month if not used within a "period" (with defined start or end timestamp).

A way forward could be to use duration format with the restrictions defined within the Java Class Duration, but without the minus signs:

Obtains a Duration from a text string such as PnDTnHnMn.nS.

This will parse a textual representation of a duration, including the string produced by toString(). The formats accepted are based on the ISO-8601 duration format PnDTnHnMn.nS with days considered to be exactly 24 hours.

The string starts with an optional sign, denoted by the ASCII negative or positive symbol. If negative, the whole period is negated. The ASCII letter "P" is next in upper or lower case. There are then four sections, each consisting of a number and a suffix. The sections have suffixes in ASCII of "D", "H", "M" and "S" for days, hours, minutes and seconds, accepted in upper or lower case. The suffixes must occur in order. The ASCII letter "T" must occur before the first occurrence, if any, of an hour, minute or second section. At least one of the four sections must be present, and if "T" is present there must be at least one section after the "T". The number part of each section must consist of one or more ASCII digits. The number may be prefixed by the ASCII negative or positive symbol. The number of days, hours and minutes must parse to an long. The number of seconds must parse to an long with optional fraction. The decimal point may be either a dot or a comma. The fractional part may have from zero to 9 digits.

The leading plus/minus sign, and negative values for other units are not part of the ISO-8601 standard.

mhfoo commented 7 months ago

Discussion #144

rartych commented 7 months ago

@Kevsy Definitions of duration similar to QoD QoSProfiles are also present in Connectivity Insights subproject. Is string duration format suitable for this use case?