1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_COMMON_ISO_8601_H
5 #define CEPH_COMMON_ISO_8601_H
8 #include <boost/optional.hpp>
10 #include "common/ceph_time.h"
14 // Here, we support the W3C profile of ISO 8601 with the following
16 // - Subsecond resolution is supported to nanosecond
17 // granularity. Any number of digits between 1 and 9 may be
18 // specified after the decimal point.
19 // - All times must be UTC.
20 // - All times must be representable as a sixty-four bit count of
21 // nanoseconds since the epoch.
22 // - Partial times are handled thus:
23 // * If there are no subseconds, they are assumed to be zero.
24 // * If there are no seconds, they are assumed to be zero.
25 // * If there are no minutes, they are assumed to be zero.
26 // * If there is no time, it is assumed to midnight.
27 // * If there is no day, it is assumed to be the first.
28 // * If there is no month, it is assumed to be January.
30 // If a date is invalid, boost::none is returned.
32 boost::optional
<ceph::real_time
> from_iso_8601(
33 std::string_view s
, const bool ws_terminates
= true) noexcept
;
35 enum class iso_8601_format
{
36 Y
, YM
, YMD
, YMDh
, YMDhm
, YMDhms
, YMDhmsn
39 std::string
to_iso_8601(const ceph::real_time t
,
40 const iso_8601_format f
= iso_8601_format::YMDhmsn
,
41 std::string_view date_separator
= "-",
42 std::string_view time_separator
= ":")
45 static inline std::string
to_iso_8601_no_separators(const ceph::real_time t
,
46 const iso_8601_format f
= iso_8601_format::YMDhmsn
)
48 return to_iso_8601(t
, f
, "", "");