Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISO 8601 Duration with milliseconds?

How should a duration of 500 milliseconds be expressed using ISO 8601? To me, the documentation is not 100% clear. Is it just "PT0.5S" ?

like image 714
Werner Avatar asked Nov 21 '14 09:11

Werner


1 Answers

Yes.

I could only find an old draft for 8601 but it is explicit on the fractional representation:

5.5 Periods of time

5.5.1 Means of specifying periods of time

A period of time shall be expressed in one of the following ways:

a) As a duration delimited by a specific start and a specific end;

b) As a duration expressed in one or more specific components but not associated with any specific start or end;

c) As a duration associated with a specific start;

d) As a duration associated with a specific end.

5.5.2 Separators and designators

A solidus [/] shall be used to separate the two components in each of 5.5.1 a), c) and d).

For 5.5.1 b), c) and d) the designator [P] shall precede, without spaces, the representation of the duration.

Other designators (and the hyphen when used to indicate omitted components) shall be used as shown in 5.5.4 and 5.5.5 below.

and later

5.5.3.1 Format with time-unit designators

In expressions of period of time or recurring time-interval duration can be represented by a data element of variable length. The number of years shall be followed by the designator [Y], the number of months by [M], the number of weeks by [W], and the number of days by [D]. The part including time components shall be preceded by the designator [T]; the number of hours shall be followed by [H], the number of minutes by [M] and the number of seconds by [S]. In the examples [n] represents one or more digits, constituting a positive integer or zero.

In complete representations the format shall be nYnMnDTnHnMnS or nW.

For reduced precision, decimal or truncated representations of this format of duration the following rules apply:

a) If necessary for a particular application the lowest order components may be omitted to represent duration with reduced precision;

b) If necessary for a particular application the lowest order component may have a decimal fraction. The decimal fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0: i.e. the comma [,] or full stop [.]. Of these, the comma is the preferred sign. If the magnitude of the number is less than unity, the decimal sign shall be preceded by a zero (see ISO 31-0);

c) If the number of years, months, days, hours, minutes or seconds in any of these expressions equals zero, the number and the corresponding designator may be absent; however, at least one number and its designator shall be present. Note that the removal of leading non-zero components is not allowed;

d) The designator T shall be absent if all of the time components are absent.

All this is coherent with the wikipedia article, so the ISO-8601 of a duration of 500 ms should be PT0,5S or PT0.5S

like image 130
Serge Ballesta Avatar answered Oct 22 '22 00:10

Serge Ballesta