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 #define GRN_TIMEVAL_TO_NSEC(timeval) (((timeval)->tv_sec * GRN_TIME_NSEC_PER_SEC) + (timeval)->tv_nsec) 33 +/ 34 35 enum GRN_TIME_NSEC_PER_SEC = 1000000000; 36 enum GRN_TIME_NSEC_PER_SEC_F = 1000000000.0; 37 enum GRN_TIME_NSEC_PER_MSEC = 1000000; 38 enum GRN_TIME_NSEC_PER_USEC = 1000; 39 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_MSEC_PER_SEC = 1000; 46 47 enum GRN_TIME_USEC_PER_SEC = 1000000; 48 enum GRN_TIME_USEC_PER_SEC_F = 1000000.0; 49 enum GRN_TIME_USEC_PER_MSEC = 1000; 50 /+ 51 #define GRN_TIME_USEC_TO_SEC(usec) ((usec) / GRN_TIME_USEC_PER_SEC) 52 53 #define GRN_TIME_MSEC_TO_USEC(msec) ((msec) * GRN_TIME_USEC_PER_MSEC) 54 55 #define GRN_TIME_PACK(sec, usec) ((long)(sec) * GRN_TIME_USEC_PER_SEC + (usec)) 56 #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); 57 +/ 58 59 //GRN_API 60 groonga_d.groonga.grn_rc grn_timeval_now(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_timeval* tv); 61 62 //GRN_API 63 void grn_time_now(groonga_d.groonga.grn_ctx* ctx, groonga_d.groonga.grn_obj* obj); 64 65 //GRN_API 66 groonga_d.groonga.grn_timeval grn_timeval_from_double(groonga_d.groonga.grn_ctx* ctx, double value); 67 68 /+ 69 #define GRN_TIME_NOW(ctx, obj) (grn_time_now((ctx), (obj))) 70 +/ 71 72 //GRN_API 73 groonga_d.groonga.grn_bool grn_time_to_tm(groonga_d.groonga.grn_ctx* ctx, long time, core.stdc.time.tm* tm); 74 75 //GRN_API 76 groonga_d.groonga.grn_bool grn_time_from_tm(groonga_d.groonga.grn_ctx* ctx, long* time, core.stdc.time.tm* tm);