Groonga
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Brazil
3 Copyright (C) 2022-2026 Sutou Kouhei <kou@clear-code.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#pragma once
21
22#include <time.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define GRN_TIMEVAL_TO_MSEC(timeval) \
29 (((timeval)->tv_sec * GRN_TIME_MSEC_PER_SEC) + \
30 ((timeval)->tv_nsec / GRN_TIME_NSEC_PER_MSEC))
31
32#define GRN_TIMEVAL_TO_NSEC(timeval) \
33 (((timeval)->tv_sec * GRN_TIME_NSEC_PER_SEC) + (timeval)->tv_nsec)
34
35#define GRN_TIME_NSEC_PER_SEC 1000000000
36#define GRN_TIME_NSEC_PER_SEC_F 1000000000.0
37#define GRN_TIME_NSEC_PER_MSEC 1000000
38#define GRN_TIME_NSEC_PER_USEC 1000
39#define GRN_TIME_NSEC_TO_USEC(nsec) ((nsec) / GRN_TIME_NSEC_PER_USEC)
40#define GRN_TIME_USEC_TO_NSEC(usec) ((usec) * GRN_TIME_NSEC_PER_USEC)
41
42#define GRN_TIME_MSEC_PER_SEC 1000
43
44#define GRN_TIME_USEC_PER_SEC 1000000
45#define GRN_TIME_USEC_PER_SEC_F 1000000.0
46#define GRN_TIME_USEC_PER_MSEC 1000
47#define GRN_TIME_USEC_TO_SEC(usec) ((usec) / GRN_TIME_USEC_PER_SEC)
48
49#define GRN_TIME_MSEC_TO_USEC(msec) ((msec) * GRN_TIME_USEC_PER_MSEC)
50
51#define GRN_TIME_PACK(sec, usec) ((int64_t)(sec) * GRN_TIME_USEC_PER_SEC + (usec))
52#define GRN_TIME_UNPACK(time_value, sec, usec) do {\
53 sec = (time_value) / GRN_TIME_USEC_PER_SEC;\
54 usec = (int32_t)((time_value) % GRN_TIME_USEC_PER_SEC);\
55} while (0)
56
59
61
62#define GRN_TIME_NOW(ctx,obj) (grn_time_now((ctx), (obj)))
63
65 int64_t time,
66 struct tm *tm);
68 int64_t *time,
69 struct tm *tm);
70
71/* Return the offset of the local time from UTC in seconds at the given
72 * UNIX time. */
73typedef int32_t (*grn_time_utc_offset_func)(int64_t unix_time,
74 void *user_data);
75/* Use the given function instead of localtime() and mktime() to
76 * convert between UNIX time and local time. This is for an environment
77 * that doesn't have time zone information such as WASI. */
79 void *user_data);
80
81#ifdef __cplusplus
82}
83#endif
grn_rc
Definition groonga.h:61
struct _grn_ctx grn_ctx
grn_ctx is the most important object.
Definition groonga.h:332
#define GRN_API
Definition groonga.h:39
struct _grn_obj grn_obj
The generic Groonga object type.
Definition groonga.h:310
Definition groonga.h:3446
GRN_API void grn_time_now(grn_ctx *ctx, grn_obj *obj)
GRN_API bool grn_time_from_tm(grn_ctx *ctx, int64_t *time, struct tm *tm)
GRN_API void grn_time_set_utc_offset_func(grn_time_utc_offset_func func, void *user_data)
GRN_API bool grn_time_to_tm(grn_ctx *ctx, int64_t time, struct tm *tm)
GRN_API grn_rc grn_timeval_now(grn_ctx *ctx, grn_timeval *tv)
int32_t(* grn_time_utc_offset_func)(int64_t unix_time, void *user_data)
Definition time.h:73
GRN_API grn_timeval grn_timeval_from_double(grn_ctx *ctx, double value)