docs: Add supported versions and fix-backport policy
[lttng-tools.git] / src / common / time.hpp
CommitLineData
395d6b02 1/*
ab5be9fa 2 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
395d6b02 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-or-later
395d6b02 5 *
395d6b02
JG
6 */
7
8#ifndef LTTNG_TIME_H
9#define LTTNG_TIME_H
10
28f23191
JG
11#include <common/compat/time.hpp>
12#include <common/macros.hpp>
13
332a2147 14#include <ctime>
2a1135fa 15#include <stdbool.h>
332a2147 16#include <string>
28f23191 17#include <time.h>
332a2147 18
28f23191
JG
19#define MSEC_PER_SEC 1000ULL
20#define NSEC_PER_SEC 1000000000ULL
21#define NSEC_PER_MSEC 1000000ULL
22#define NSEC_PER_USEC 1000ULL
23#define USEC_PER_SEC 1000000ULL
24#define USEC_PER_MSEC 1000ULL
81684730 25
28f23191 26#define SEC_PER_MINUTE 60ULL
81684730
JR
27#define MINUTE_PER_HOUR 60ULL
28
29#define USEC_PER_MINUTE (USEC_PER_SEC * SEC_PER_MINUTE)
28f23191 30#define USEC_PER_HOURS (USEC_PER_MINUTE * MINUTE_PER_HOUR)
395d6b02 31
28f23191 32#define ISO8601_STR_LEN sizeof("YYYYmmddTHHMMSS+HHMM")
a8b66566 33#define DATETIME_STR_LEN sizeof("YYYYmmdd-HHMMSS")
274ca939 34
cd9adb8b 35bool locale_supports_utf8();
2a1135fa 36
28f23191
JG
37#define NSEC_UNIT "ns"
38#define USEC_UNIT (locale_supports_utf8() ? "µs" : "us")
39#define MSEC_UNIT "ms"
40#define SEC_UNIT "s"
41#define MIN_UNIT "m"
42#define HR_UNIT "h"
2a1135fa 43
2daf6502
MD
44/*
45 * timespec_to_ms: Convert timespec to milliseconds.
46 *
47 * Returns 0 on success, else -1 on error. errno is set to EOVERFLOW if
48 * input would overflow the output in milliseconds.
49 */
50int timespec_to_ms(struct timespec ts, unsigned long *ms);
51
52/*
53 * timespec_abs_diff: Absolute difference between timespec.
54 */
55struct timespec timespec_abs_diff(struct timespec ts_a, struct timespec ts_b);
56
274ca939
JG
57/*
58 * Format a Unix timestamp to an ISO 8601 compatible timestamp of
59 * the form "YYYYmmddTHHMMSS+HHMM" in local time. `len` must >= to
60 * ISO8601_STR_LEN.
61 *
62 * Returns 0 on success, else -1 on error.
63 */
274ca939 64int time_to_iso8601_str(time_t time, char *str, size_t len);
332a2147
JG
65namespace lttng {
66namespace utils {
67
68std::string time_to_iso8601_str(time_t time);
69
70} /* namespace utils */
71} /* namespace lttng */
274ca939 72
a8b66566
JR
73int time_to_datetime_str(time_t time, char *str, size_t len);
74
395d6b02 75#endif /* LTTNG_TIME_H */
This page took 0.070774 seconds and 4 git commands to generate.