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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// Copyright (c) 2024 Anton Zhiyanov, MIT License
// https://github.com/nalgeon/sqlean
// Based on Go's time package, BSD 3-Clause License
// https://github.com/golang/go
// Package timex provides functionality for working with time.
// The calendrical calculations always assume a Gregorian calendar, with no leap seconds.
// Month is a month of the year.
;
// Weekday is a day of the week (Sunday = 0, ...).
;
// Time represents an instant in time with nanosecond precision.
// The zero value is January 1, year 1, 00:00:00.000000000 UTC.
typedef struct Time;
// Duration represents the elapsed time between two instants
// as an int64 nanosecond count. The representation limits the
// largest representable duration to approximately 290 years.
typedef int64_t Duration;
// --- Time ---
// Constructors.
// time_now returns the current time in UTC.
Time ;
// time_date returns the Time corresponding to
// yyyy-mm-dd hh:mm:ss + nsec nanoseconds
// with the given timezone offset in seconds.
Time ;
// Time parts.
// time_get_date returns the year, month, and day in which t occurs.
void ;
// time_get_year returns the year in which t occurs.
int ;
// time_get_month returns the month of the year specified by t.
enum Month ;
// time_get_day returns the day of the month specified by t.
int ;
// time_get_clock returns the hour, minute, and second within the day specified by t.
void ;
// time_get_hour returns the hour within the day specified by t.
int ;
// time_get_minute returns the minute offset within the hour specified by t.
int ;
// time_get_second returns the second offset within the minute specified by t.
int ;
// time_get_nano returns the nanosecond offset within the second specified by t.
int ;
// time_get_weekday returns the day of the week specified by t.
enum Weekday ;
// time_get_yearday returns the day of the year specified by t.
int ;
// time_get_isoweek returns the ISO 8601 year and week number in which t occurs.
void ;
// Unix time.
// time_unix returns the Time corresponding to the given Unix time,
// sec seconds and nsec nanoseconds since January 1, 1970 UTC.
Time ;
// time_milli returns the Time corresponding to the given Unix time,
// msec milliseconds since January 1, 1970 UTC.
Time ;
// time_micro returns the local Time corresponding to the given Unix time,
// usec microseconds since January 1, 1970 UTC.
Time ;
// time_nano returns the Time corresponding to the given Unix time,
// nsec nanoseconds since January 1, 1970 UTC.
Time ;
// time_to_unix returns t as a Unix time, the number of seconds elapsed
// since January 1, 1970 UTC.
int64_t ;
// time_to_milli returns t as a Unix time, the number of milliseconds elapsed since
// January 1, 1970 UTC.
int64_t ;
// time_to_micro returns t as a Unix time, the number of microseconds elapsed since
// January 1, 1970 UTC.
int64_t ;
// time_to_nano returns t as a Unix time, the number of nanoseconds elapsed
// since January 1, 1970 UTC.
int64_t ;
// Calendar time.
// time_tm returns the Time corresponding to the given calendar time at the given timezone offset.
Time ;
// time_to_tm returns t in the given timezone offset as a calendar time.
struct tm ;
// Comparison.
// time_after reports whether the time instant t is after u.
bool ;
// time_before reports whether the time instant t is before u.
bool ;
// time_compare compares the time instant t with u.
int ;
// time_equal reports whether t and u represent the same time instant.
bool ;
// time_is_zero reports whether t represents the zero time instant,
// January 1, year 1, 00:00:00 UTC.
bool ;
// Arithmetic.
// time_add returns the time t+d.
Time ;
// time_sub returns the duration t-u.
Duration ;
// time_since returns the time elapsed since t.
Duration ;
// time_until returns the duration until t.
Duration ;
// time_add_date returns the time corresponding to adding the
// given number of years, months, and days to t.
Time ;
// Rounding.
// time_truncate returns the result of rounding t down to a multiple of d.
Time ;
// time_round returns the result of rounding t to the nearest multiple of d.
Time ;
// Formatting.
// time_fmt_iso returns an ISO 8601 time string for the given time value.
size_t ;
// time_fmt_datetime returns a datetime string for the given time value.
size_t ;
// time_fmt_date returns a date string for the given time value.
size_t ;
// time_fmt_time returns a time string for the given time value.
size_t ;
// time_parse parses a formatted string and returns the time value it represents.
Time ;
// Marshaling.
// time_blob returns the time instant represented by the binary data.
Time ;
// time_to_blob returns the binary representation of the time instant t.
void ;
// --- Duration ---
// Min/Max durations.
// Common durations. There is no definition for units of Day or larger
// to avoid confusion across daylight savings time zone transitions.
extern const Duration Nanosecond;
extern const Duration Microsecond;
extern const Duration Millisecond;
extern const Duration Second;
extern const Duration Minute;
extern const Duration Hour;
// Conversion.
// dur_to_micro returns the duration as an integer microsecond count.
int64_t ;
// dur_to_milli returns the duration as an integer millisecond count.
int64_t ;
// dur_to_seconds returns the duration as a floating point number of seconds.
double ;
// dur_to_minutes returns the duration as a floating point number of minutes.
double ;
// dur_to_hours returns the duration as a floating point number of hours.
double ;
// Rounding.
// dur_truncate returns the result of rounding d toward zero to a multiple of m.
Duration ;
// dur_round returns the result of rounding d to the nearest multiple of m.
Duration ;
// dur_abs returns the absolute value of d.
Duration ;
/* TIMEX_H */