blob: 989e5656a88a03aa8144883f1ee3c003bdd5da67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#pragma once
#include "http_response.hpp"
#include <chrono>
#include <cstdint>
#include <ctime>
#include <optional>
#include <ratio>
#include <string>
#include <string_view>
#include <utility>
namespace redfish
{
namespace time_utils
{
/**
* @brief Convert string that represents value in Duration Format to its numeric
* equivalent.
*/
std::optional<std::chrono::milliseconds> fromDurationString(std::string_view v);
/**
* @brief Convert time value into duration format that is based on ISO 8601.
* Example output: "P12DT1M5.5S"
* Ref: Redfish Specification, Section 9.4.4. Duration values
*/
std::string toDurationString(std::chrono::milliseconds ms);
std::optional<std::string> toDurationStringFromUint(uint64_t timeMs);
// Returns the formatted date time string.
// Note that the maximum supported date is 9999-12-31T23:59:59+00:00, if
// the given |secondsSinceEpoch| is too large, we return the maximum supported
// date.
std::string getDateTimeUint(uint64_t secondsSinceEpoch);
// Returns the formatted date time string with millisecond precision
// Note that the maximum supported date is 9999-12-31T23:59:59+00:00, if
// the given |secondsSinceEpoch| is too large, we return the maximum supported
// date.
std::string getDateTimeUintMs(uint64_t milliSecondsSinceEpoch);
// Returns the formatted date time string with microsecond precision
std::string getDateTimeUintUs(uint64_t microSecondsSinceEpoch);
std::string getDateTimeStdtime(std::time_t secondsSinceEpoch);
/**
* Returns the current Date, Time & the local Time Offset
* information in a pair
*
* @param[in] None
*
* @return std::pair<std::string, std::string>, which consist
* of current DateTime & the TimeOffset strings respectively.
*/
std::pair<std::string, std::string> getDateTimeOffsetNow();
using usSinceEpoch = std::chrono::duration<int64_t, std::micro>;
std::optional<usSinceEpoch> dateStringToEpoch(std::string_view datetime);
/**
* @brief Returns the datetime in ISO 8601 format
*
* @param[in] std::string_view the date of item manufacture in ISO 8601 format,
* either as YYYYMMDD or YYYYMMDDThhmmssZ
* Ref: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/
* xyz/openbmc_project/Inventory/Decorator/Asset.interface.yaml#L16
*
* @return std::string which consist the datetime
*/
std::optional<std::string> getDateTimeIso8601(std::string_view datetime);
/**
* @brief ProductionDate report
*/
void productionDateReport(crow::Response& res, const std::string& buildDate);
} // namespace time_utils
} // namespace redfish
|