[2] [[XML Schema]] の [DFN[[CODE(XML)@en[[[xs:duration]]]]]]
は、 [[ISO 8601]] をベースに定義された[[時間]]を表す[[データ型]]です。

* 仕様書

[REFS[
- [3] [CITE@EN[W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes]] ([TIME[2012-04-04 21:34:51 +09:00]] 版) <http://www.w3.org/TR/xmlschema11-2/#duration>
]REFS]

* 値空間

[4] 値は、[DFN[[RUBYB[月数]@en[months]]]]と[DFN[[RUBYB[秒数]@en[seconds]]]]で構成されます。
それぞれ[[整数]]と[[十進数]]で、両者の[[符号]]は一致していなければ[['''なりません''']]。 [SRC[>>3]]

* 字句空間

[5] [[字句空間]]は、次の[[正規表現]]に[[一致]]する[[文字列]]です [SRC[>>3]]。

>
[PRE(regexp code)[
-?P( ( ( [0-9]+Y([0-9]+M)?([0-9]+D)?
       | ([0-9]+M)([0-9]+D)?
       | ([0-9]+D)
       )
       (T ( ([0-9]+H)([0-9]+M)?([0-9]+(\.[0-9]+)?S)?
          | ([0-9]+M)([0-9]+(\.[0-9]+)?S)?
          | ([0-9]+(\.[0-9]+)?S)
          )
       )?
    )
  | (T ( ([0-9]+H)([0-9]+M)?([0-9]+(\.[0-9]+)?S)?
       | ([0-9]+M)([0-9]+(\.[0-9]+)?S)?
       | ([0-9]+(\.[0-9]+)?S)
       )
    )
  )
]PRE]

* 関連

[SEE[ [[XML Schema暦]] ]]

[6] [[HTMLの時間形式]]と同じく [[ISO 8601の時間形式]]をベースにしていますが、
[[HTML]] とは違って、
- 全体を負にできます
- Y や M による指定ができます

[7] [[妥当なvEvent時間文字列]]もやはり [[ISO 8601の時間形式]]ですが、
[[vEvent]] とは違って
- 全体を負にできます
- Y や M による指定ができます
- H と S だけで M なしの指定ができます
- W による指定ができません
- 小数以下の秒を指定できます

[8] [[派生型]]として [CODE[[[xs:dayTimeDuration]]]] と [CODE[[[xs:yearMonthDuration]]]] があります。

* 歴史

[REFS[
- [1] [CITE@EN[W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes]]
( ([TIME[2012-04-05 06:34:51 +09:00]] 版))
<http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#duration>
]REFS]

[9] [CITE@EN[W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes]]
( ([TIME[2012-04-04 21:34:51 +09:00]] 版))
<http://www.w3.org/TR/xmlschema11-2/#partial-implementation>

[10] [CITE@EN[W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes]]
( ([TIME[2012-04-04 21:34:51 +09:00]] 版))
<http://www.w3.org/TR/xmlschema11-2/#sec-dt-arith>

[11] [CITE@en[README.md | master | Chris Lord / gaia-navigator | GitLab]]
([TIME[2015-06-10 21:26:19 +09:00]] 版)
<https://gitlab.com/Cwiiis/gaia-navigator/blob/master/README.md>

[12] [CITE@EN[XPath and XQuery Functions and Operators 3.1]]
([TIME[2017-03-21 16:02:06 +09:00]])
<https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#duration-subtypes>

[FIG(quote)[
[FIGCAPTION[
[13] [CITE@en[Activity Vocabulary]]
([TIME[2017-05-21 23:50:36 +09:00]])
<https://w3c.github.io/activitystreams/vocabulary/#dfn-duration>
]FIGCAPTION]

> The value must be expressed as an xsd:duration as defined by '''[''' xmlschema11-2''']''', section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").

]FIG]


[FIG(quote)[
[FIGCAPTION[
[14] [CITE@ja[データ コントラクト スキーマの参照]]
([TIME[2017-06-01 22:06:11 +09:00]])
<https://msdn.microsoft.com/ja-jp/library/ms733112(v=vs.110).aspx>
]FIGCAPTION]

>  <!-- xs:duration is restricted to an ordered value space, 
>     to map to System.TimeSpan -->
>  <xs:element name="duration" nillable="true" type="tns:duration"/>
>  <xs:simpleType name="duration">
>   <xs:restriction base="xs:duration">
>    <xs:pattern 
>      value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
>    <xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
>    <xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
>   </xs:restriction>
>  </xs:simpleType>
> 

]FIG]


[FIG(quote)[
[FIGCAPTION[
[15] [CITE@en[Compose file version 3 reference | Docker Documentation]]
( ([TIME[2017-06-10 02:19:31 +09:00]]))
<https://docs.docker.com/compose/compose-file/#specifying-durations>
]FIGCAPTION]

> Some configuration options, such as the interval and timeout sub-options for healthcheck, accept a duration as a string in a format that looks like this:
> 2.5s
> 10s
> 1m30s
> 2h32m
> 5h34m56s
> The supported units are us, ms, s, m and h.

]FIG]
