aboutsummaryrefslogtreecommitdiff
path: root/arch/all/core/include/time.h
blob: 0e15a9bba461fb7dc4baf7d0dfa4906048b6d82e (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
87
88
89
90
91
92
/* ****************************************************************************
 * time.h -- Time utilities.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of the 'all/core' module,
 * in libcarrot, an experimental modular libc project.
 *
 * This file is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Lesser Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#include <cdefs.h>
#include <stddef.h>
#include_bits <time.h>

#define CLOCKS_PER_SEC __CLOCKS_PER_SEC

/* ************************************************************************* */
/*  Time types                                                               */
/* ************************************************************************* */
/* This type contains the processor time, i.e. the number of ticks (where
 * `CLOCK_PER_SEC` represents the number of ticks that form a second). */

typedef __uint32_t clock_t;

/* This type contains UNIX timestamps, i.e. the number of seconds since the
 * Epoch.
 *
 * FIXME: Y2038 problem, should find a way to use 64-bit integer in
 * pre-C99. */

typedef __uint32_t time_t;

/* This structure holds the broken-down time (components of a
 * calendar time). */

struct tm {
	int tm_sec;   /* seconds after the minute [0, 60] */
	int tm_min;   /* minutes after the hour [0, 59] */
	int tm_hour;  /* hours since midnight [0, 23] */
	int tm_mday;  /* day of the month [0, 31] */
	int tm_mon;   /* months since january [0, 11] */
	int tm_year;  /* years since 1900 */
	int tm_wday;  /* days since sunday [0, 6] */
	int tm_yday;  /* days since january 1 [0, 365] */
	int tm_isdst; /* daylight saving time flag */
};
/* ************************************************************************* */
/*  Main functions                                                           */
/* ************************************************************************* */
/* This function to get the processor time.
 * Divide the return value by `CLOCKS_PER_SEC` to get the number of seconds. */

extern __wur clock_t clock _OF((void)) __THROW;

/* Compute the difference between two calendar times.
 * The returned value is the difference expressed in seconds. */

extern __pure double difftime _OF((time_t __time1, time_t __time0)) __THROW;

/* Correct a broken-down time, and calculate the timestamp out of it. */

extern __wur time_t mktime _OF((struct tm *__timep)) __THROW;

/* Get the current timestamp. */

extern time_t time _OF((time_t *__timep)) __THROW;

/* Get static strings out of broken-down time or timestamps. */

extern __wur char *asctime _OF((const struct tm *__timep)) __THROW;
extern __wur char *ctime   _OF((const time_t *__timer)) __THROW;

/* Get the broken-down time out of a timestamp, using the GMT or local time. */

extern __wur struct tm *gmtime    _OF((const time_t *__timer)) __THROW;
extern __wur struct tm *localtime _OF((const time_t *__timer)) __THROW;

/* Get a custom-format date string. */

extern size_t strftime _OF((char *__restrict __s,
	size_t __maxsize, const char *__restrict __format,
	const struct tm *__restrict __timep)) __THROW;