]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/timeutils.h
libfdisk: (dos) accept start for log.partitions on template
[thirdparty/util-linux.git] / include / timeutils.h
CommitLineData
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
28typedef uint64_t usec_t;
29typedef 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
55int parse_timestamp(const char *t, usec_t *usec);
56
3c201431
KZ
57/* flags for strxxx_iso() functions */
58enum {
59 ISO_8601_DATE = (1 << 1),
60 ISO_8601_TIME = (1 << 2),
33c7ffa3
KZ
61 ISO_8601_DOTUSEC = (1 << 3),
62 ISO_8601_COMMAUSEC = (1 << 4),
63 ISO_8601_TIMEZONE = (1 << 5),
c1616946
SK
64 ISO_8601_SPACE = (1 << 6),
65 ISO_8601_GMTIME = (1 << 7)
3c201431 66};
33c7ffa3
KZ
67
68#define ISO_8601_BUFSIZ 32
69
70int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz);
71int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz);
72int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz);
3c201431 73
eee665bb
KZ
74#define UL_SHORTTIME_THISYEAR_HHMM (1 << 1)
75
76int time_is_today(const time_t *t, struct timeval *now);
77int time_is_thisyear(const time_t *t, struct timeval *now);
78
79int strtime_short(const time_t *t, struct timeval *now, int flags, char *buf, size_t bufsz);
80
b72a75e9
SK
81#ifndef HAVE_TIMEGM
82extern time_t timegm(struct tm *tm);
83#endif
84
7088bd88
WP
85int parse_date(struct timespec *, char const *, struct timespec const *);
86
2659a49e 87#endif /* UTIL_LINUX_TIME_UTIL_H */