1 /* 2 Copyright(C) 2016 Brazil 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 module groonga_d.time; 19 20 21 private static import groonga_d.groonga; 22 private static import core.stdc.time; 23 24 extern(C): 25 nothrow @nogc: 26 27 /+ 28 #include <time.h> 29 30 #define GRN_TIMEVAL_TO_MSEC(timeval) (((timeval)->tv_sec * GRN_TIME_MSEC_PER_SEC) + ((timeval)->tv_nsec / GRN_TIME_NSEC_PER_MSEC)) 31 +/ 32 33 enum GRN_TIME_NSEC_PER_SEC = 1000000000; 34 enum GRN_TIME_NSEC_PER_SEC_F = 1000000000.0; 35 enum GRN_TIME_NSEC_PER_MSEC = 1000000; 36 /+ 37 #define GRN_TIME_NSEC_PER_USEC (GRN_TIME_NSEC_PER_SEC / GRN_TIME_USEC_PER_SEC) 38 +/ 39 enum GRN_TIME_MSEC_PER_SEC = 1000; 40 /+ 41 #define GRN_TIME_NSEC_TO_USEC(nsec) ((nsec) / GRN_TIME_NSEC_PER_USEC) 42 #define GRN_TIME_USEC_TO_NSEC(usec) ((usec) * GRN_TIME_NSEC_PER_USEC) 43 +/ 44 45 enum GRN_TIME_USEC_PER_SEC = 1000000; 46 enum GRN_TIME_USEC_PER_SEC_F = 1000000.0; 47 /+ 48 #define GRN_TIME_PACK(sec, usec) ((long)(sec) * GRN_TIME_USEC_PER_SEC + (usec)) 49 #define GRN_TIME_UNPACK(time_value, sec, usec) sec = cast(time_value)(/ GRN_TIME_USEC_PER_SEC); usec = cast(time_value)( % GRN_TIME_USEC_PER_SEC); 50 +/ 51 52 //GRN_API 53 groonga_d.groonga.grn_rc grn_timeval_now(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_timeval* tv); 54 55 //GRN_API 56 void grn_time_now(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* obj); 57 58 /+ 59 #define GRN_TIME_NOW(ctx, obj) (grn_time_now((ctx), (obj))) 60 +/ 61 62 //GRN_API 63 ubyte grn_time_to_tm(groonga_d.groonga.grn_ctx* ctx, long time, core.stdc.time.tm* tm); 64 65 //GRN_API 66 ubyte grn_time_from_tm(groonga_d.groonga.grn_ctx* ctx, long* time, core.stdc.time.tm* tm);