Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / iso_8601.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_COMMON_ISO_8601_H
5 #define CEPH_COMMON_ISO_8601_H
6
7 #include <boost/utility/string_ref.hpp>
8
9 #include "common/ceph_time.h"
10
11 namespace ceph {
12
13 // Here, we support the W3C profile of ISO 8601 with the following
14 // restrictions:
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.
28 //
29 // If a date is invalid, boost::none is returned.
30
31 boost::optional<ceph::real_time> from_iso_8601(
32   boost::string_ref s, const bool ws_terminates = true) noexcept;
33
34 enum class iso_8601_format {
35   Y, YM, YMD, YMDh, YMDhm, YMDhms, YMDhmsn
36 };
37
38 std::string to_iso_8601(const ceph::real_time t,
39                         const iso_8601_format f = iso_8601_format::YMDhmsn)
40   noexcept;
41 }
42
43 #endif