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