[time.duration.io]

# 30 Time library [[time]](./#time)

## 30.5 Class template duration [[time.duration]](time.duration#io)

### 30.5.11 I/O [time.duration.io]

[ð](#lib:operator%3c%3c,duration)

`template<class charT, class traits, class Rep, class Period>
  basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, const duration<Rep, Period>& d);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2063)

*Effects*: Inserts the duration d onto the stream os as if it were implemented as follows:basic_ostringstream<charT, traits> s;
s.flags(os.flags());
s.imbue(os.getloc());
s.precision(os.precision());
s << d.count() << *units-suffix*;return os << s.str(); where *units-suffix* depends on the type Period​::​type as follows:

- [(1.1)](#1.1)

  If Period​::​type is atto,*units-suffix* is "as"[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  Otherwise, if Period​::​type is femto,*units-suffix* is "fs"[.](#1.2.sentence-1)

- [(1.3)](#1.3)

  Otherwise, if Period​::​type is pico,*units-suffix* is "ps"[.](#1.3.sentence-1)

- [(1.4)](#1.4)

  Otherwise, if Period​::​type is nano,*units-suffix* is "ns"[.](#1.4.sentence-1)

- [(1.5)](#1.5)

  Otherwise, if Period​::​type is micro,
it isimplementation-defined
whether *units-suffix* is"Î¼s" ("\u00b5\u0073") or"us"[.](#1.5.sentence-1)

- [(1.6)](#1.6)

  Otherwise, if Period​::​type is milli,*units-suffix* is "ms"[.](#1.6.sentence-1)

- [(1.7)](#1.7)

  Otherwise, if Period​::​type is centi,*units-suffix* is "cs"[.](#1.7.sentence-1)

- [(1.8)](#1.8)

  Otherwise, if Period​::​type is deci,*units-suffix* is "ds"[.](#1.8.sentence-1)

- [(1.9)](#1.9)

  Otherwise, if Period​::​type is ratio<1>,*units-suffix* is "s"[.](#1.9.sentence-1)

- [(1.10)](#1.10)

  Otherwise, if Period​::​type is deca,*units-suffix* is "das"[.](#1.10.sentence-1)

- [(1.11)](#1.11)

  Otherwise, if Period​::​type is hecto,*units-suffix* is "hs"[.](#1.11.sentence-1)

- [(1.12)](#1.12)

  Otherwise, if Period​::​type is kilo,*units-suffix* is "ks"[.](#1.12.sentence-1)

- [(1.13)](#1.13)

  Otherwise, if Period​::​type is mega,*units-suffix* is "Ms"[.](#1.13.sentence-1)

- [(1.14)](#1.14)

  Otherwise, if Period​::​type is giga,*units-suffix* is "Gs"[.](#1.14.sentence-1)

- [(1.15)](#1.15)

  Otherwise, if Period​::​type is tera,*units-suffix* is "Ts"[.](#1.15.sentence-1)

- [(1.16)](#1.16)

  Otherwise, if Period​::​type is peta,*units-suffix* is "Ps"[.](#1.16.sentence-1)

- [(1.17)](#1.17)

  Otherwise, if Period​::​type is exa,*units-suffix* is "Es"[.](#1.17.sentence-1)

- [(1.18)](#1.18)

  Otherwise, if Period​::​type is ratio<60>,*units-suffix* is "min"[.](#1.18.sentence-1)

- [(1.19)](#1.19)

  Otherwise, if Period​::​type is ratio<3600>,*units-suffix* is "h"[.](#1.19.sentence-1)

- [(1.20)](#1.20)

  Otherwise, if Period​::​type is ratio<86400>,*units-suffix* is "d"[.](#1.20.sentence-1)

- [(1.21)](#1.21)

  Otherwise, if Period​::​type​::​den == 1,*units-suffix* is "[*num*]s"[.](#1.21.sentence-1)

- [(1.22)](#1.22)

  Otherwise, *units-suffix* is"[*num*/*den*]s"[.](#1.22.sentence-1)

In the list above,
the use of *num* and *den* refers to the static data members of Period​::​type,
which are converted to arrays of charT using a decimal conversion with no leading zeroes[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2176)

*Returns*: os[.](#2.sentence-1)

[ð](#lib:from_stream,duration)

`template<class charT, class traits, class Rep, class Period, class Alloc = allocator<charT>>
  basic_istream<charT, traits>&
    from_stream(basic_istream<charT, traits>& is, const charT* fmt,
                duration<Rep, Period>& d,
                basic_string<charT, traits, Alloc>* abbrev = nullptr,
                minutes* offset = nullptr);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2192)

*Effects*: Attempts to parse the input stream is into the duration d using the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13 Parsing")[.](#3.sentence-1)

If the parse fails to decode a valid duration,is.setstate(ios_base​::​failbit) is called and d is not modified[.](#3.sentence-2)

If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#3.sentence-3)

If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#3.sentence-4)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2205)

*Returns*: is[.](#4.sentence-1)
