]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/iso_8601.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / iso_8601.h
CommitLineData
31f18b77
FG
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
11fdf7f2 7#include <boost/optional.hpp>
31f18b77
FG
8#include <boost/utility/string_ref.hpp>
9
10#include "common/ceph_time.h"
11
12namespace ceph {
13
14// Here, we support the W3C profile of ISO 8601 with the following
15// restrictions:
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.
29//
30// If a date is invalid, boost::none is returned.
31
32boost::optional<ceph::real_time> from_iso_8601(
33 boost::string_ref s, const bool ws_terminates = true) noexcept;
34
35enum class iso_8601_format {
36 Y, YM, YMD, YMDh, YMDhm, YMDhms, YMDhmsn
37};
38
39std::string to_iso_8601(const ceph::real_time t,
40 const iso_8601_format f = iso_8601_format::YMDhmsn)
41 noexcept;
42}
43
44#endif