]>
Commit | Line | Data |
---|---|---|
2659a49e SK |
1 | /*** |
2 | First set of functions in this file are part of systemd, and were | |
3 | copied to util-linux at August 2013. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
700031ad | 6 | Copyright (C) 2014 Karel Zak <kzak@redhat.com> |
2659a49e SK |
7 | |
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | #ifndef UTIL_LINUX_TIME_UTIL_H | |
22 | #define UTIL_LINUX_TIME_UTIL_H | |
23 | ||
24 | #include <stdio.h> | |
25 | #include <inttypes.h> | |
3c201431 | 26 | #include <sys/time.h> |
2659a49e SK |
27 | |
28 | typedef uint64_t usec_t; | |
29 | typedef uint64_t nsec_t; | |
30 | ||
31 | #define MSEC_PER_SEC 1000ULL | |
32 | #define USEC_PER_SEC 1000000ULL | |
33 | #define USEC_PER_MSEC 1000ULL | |
34 | #define NSEC_PER_SEC 1000000000ULL | |
35 | #define NSEC_PER_MSEC 1000000ULL | |
36 | #define NSEC_PER_USEC 1000ULL | |
37 | ||
38 | #define USEC_PER_MINUTE (60ULL*USEC_PER_SEC) | |
39 | #define NSEC_PER_MINUTE (60ULL*NSEC_PER_SEC) | |
40 | #define USEC_PER_HOUR (60ULL*USEC_PER_MINUTE) | |
41 | #define NSEC_PER_HOUR (60ULL*NSEC_PER_MINUTE) | |
42 | #define USEC_PER_DAY (24ULL*USEC_PER_HOUR) | |
43 | #define NSEC_PER_DAY (24ULL*NSEC_PER_HOUR) | |
44 | #define USEC_PER_WEEK (7ULL*USEC_PER_DAY) | |
45 | #define NSEC_PER_WEEK (7ULL*NSEC_PER_DAY) | |
46 | #define USEC_PER_MONTH (2629800ULL*USEC_PER_SEC) | |
47 | #define NSEC_PER_MONTH (2629800ULL*NSEC_PER_SEC) | |
48 | #define USEC_PER_YEAR (31557600ULL*USEC_PER_SEC) | |
49 | #define NSEC_PER_YEAR (31557600ULL*NSEC_PER_SEC) | |
50 | ||
51 | #define FORMAT_TIMESTAMP_MAX ((4*4+1)+11+9+4+1) /* weekdays can be unicode */ | |
52 | #define FORMAT_TIMESTAMP_RELATIVE_MAX 256 | |
53 | #define FORMAT_TIMESPAN_MAX 64 | |
54 | ||
55 | int parse_timestamp(const char *t, usec_t *usec); | |
9fd0a7a9 | 56 | int get_gmtoff(const struct tm *tp); |
2659a49e | 57 | |
4111bb3a | 58 | /* flags and masks for strxxx_iso() functions */ |
3c201431 | 59 | enum { |
4111bb3a WP |
60 | ISO_DATE = (1 << 0), |
61 | ISO_TIME = (1 << 1), | |
62 | ISO_TIMEZONE = (1 << 2), | |
63 | ISO_DOTUSEC = (1 << 3), | |
64 | ISO_COMMAUSEC = (1 << 4), | |
65 | ISO_T = (1 << 5), | |
66 | ISO_GMTIME = (1 << 6), | |
67 | ISO_TIMESTAMP = ISO_DATE | ISO_TIME | ISO_TIMEZONE, | |
68 | ISO_TIMESTAMP_T = ISO_TIMESTAMP | ISO_T, | |
69 | ISO_TIMESTAMP_DOT = ISO_TIMESTAMP | ISO_DOTUSEC, | |
70 | ISO_TIMESTAMP_DOT_T = ISO_TIMESTAMP_DOT | ISO_T, | |
71 | ISO_TIMESTAMP_COMMA = ISO_TIMESTAMP | ISO_COMMAUSEC, | |
72 | ISO_TIMESTAMP_COMMA_T = ISO_TIMESTAMP_COMMA | ISO_T, | |
73 | ISO_TIMESTAMP_COMMA_G = ISO_TIMESTAMP_COMMA | ISO_GMTIME, | |
74 | ISO_TIMESTAMP_COMMA_GT = ISO_TIMESTAMP_COMMA_G | ISO_T | |
3c201431 | 75 | }; |
33c7ffa3 | 76 | |
4111bb3a | 77 | #define ISO_BUFSIZ 42 |
33c7ffa3 KZ |
78 | |
79 | int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz); | |
80 | int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz); | |
81 | int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz); | |
3c201431 | 82 | |
eee665bb KZ |
83 | #define UL_SHORTTIME_THISYEAR_HHMM (1 << 1) |
84 | ||
eee665bb KZ |
85 | int strtime_short(const time_t *t, struct timeval *now, int flags, char *buf, size_t bufsz); |
86 | ||
b72a75e9 SK |
87 | #ifndef HAVE_TIMEGM |
88 | extern time_t timegm(struct tm *tm); | |
89 | #endif | |
90 | ||
7088bd88 WP |
91 | int parse_date(struct timespec *, char const *, struct timespec const *); |
92 | ||
2659a49e | 93 | #endif /* UTIL_LINUX_TIME_UTIL_H */ |