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
7 #include <boost/utility/string_ref.hpp>
9 #include "common/ceph_time.h"
13 // Here, we support the W3C profile of ISO 8601 with the following
15 // - Subsecond resolution is supported to nanosecond
16 // granularity. Any number of digits between 1 and 9 may be
17 // specified after the decimal point.
18 // - All times must be UTC.
19 // - All times must be representable as a sixty-four bit count of
20 // nanoseconds since the epoch.
21 // - Partial times are handled thus:
22 // * If there are no subseconds, they are assumed to be zero.
23 // * If there are no seconds, they are assumed to be zero.
24 // * If there are no minutes, they are assumed to be zero.
25 // * If there is no time, it is assumed to midnight.
26 // * If there is no day, it is assumed to be the first.
27 // * If there is no month, it is assumed to be January.
29 // If a date is invalid, boost::none is returned.
31 boost::optional<ceph::real_time> from_iso_8601(
32 boost::string_ref s, const bool ws_terminates = true) noexcept;
34 enum class iso_8601_format {
35 Y, YM, YMD, YMDh, YMDhm, YMDhms, YMDhmsn
38 std::string to_iso_8601(const ceph::real_time t,
39 const iso_8601_format f = iso_8601_format::YMDhmsn)