LCOV - code coverage report
Current view: top level - monetdb5/modules/atoms - mtime.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 171 244 70.1 %
Date: 2021-10-13 02:24:04 Functions: 111 199 55.8 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /* In this file we implement three new types with supporting code.
      10             :  * The types are:
      11             :  *
      12             :  * - daytime - representing a time-of-day between 00:00:00 (included)
      13             :  *   and 24:00:00 (not included);
      14             :  * - date - representing a date between the year -4712 and 170050;
      15             :  * - timestamp - a combination of date and daytime, representing an
      16             :  *   exact point in time.
      17             :  *
      18             :  * Dates, both in the date and the timestamp types, are represented in
      19             :  * the so-called proleptic Gregorian calendar, that is to say, the
      20             :  * Gregorian calendar (which is in common use today) is extended
      21             :  * backwards.  See e.g.
      22             :  * <https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar>.
      23             :  *
      24             :  * Times, both in the daytime and the timestamp types, are recorded
      25             :  * with microsecond precision.
      26             :  *
      27             :  * Times and timestamps are all in UTC.  Conversion from the system
      28             :  * time zone where appropriate is done automatically.
      29             :  */
      30             : 
      31             : #include "monetdb_config.h"
      32             : #include "gdk.h"
      33             : #include "gdk_time.h"
      34             : #include "mal_client.h"
      35             : #include "mal_interpreter.h"
      36             : #include "mal_exception.h"
      37             : 
      38             : #ifndef HAVE_STRPTIME
      39             : extern char *strptime(const char *, const char *, struct tm *);
      40             : #endif
      41             : 
      42             : /* interfaces callable from MAL, not used from any C code */
      43             : 
      44             : static str
      45          13 : MTIMEcurrent_date(date *ret)
      46             : {
      47          13 :         *ret = timestamp_date(timestamp_current());
      48          13 :         return MAL_SUCCEED;
      49             : }
      50             : 
      51             : static str
      52           2 : MTIMEcurrent_time(daytime *ret)
      53             : {
      54           2 :         *ret = timestamp_daytime(timestamp_current());
      55           2 :         return MAL_SUCCEED;
      56             : }
      57             : 
      58             : static str
      59          50 : MTIMEcurrent_timestamp(timestamp *ret)
      60             : {
      61          50 :         *ret = timestamp_current();
      62          50 :         return MAL_SUCCEED;
      63             : }
      64             : 
      65             : #define is_str_nil strNil
      66             : 
      67             : #define MTIME_STR_BUFFER_LENGTH MAX(strlen(str_nil) + 1, 512)
      68             : 
      69             : 
      70             : #define DEC_VAR_R(TYPE, ARG) TYPE *restrict ptr##ARG
      71             : 
      72             : #define DEC_VAR(TYPE, ARG) TYPE *ptr##ARG
      73             : 
      74             : #define DEC_ITER(TYPE, ARG)
      75             : 
      76             : #define DEC_BUFFER(OUTTYPE, RES, MALFUNC) \
      77             :         OUTTYPE RES = GDKmalloc(MTIME_STR_BUFFER_LENGTH); \
      78             :         if (!res) {     \
      79             :                 msg = createException(MAL, "batmtime." MALFUNC, SQLSTATE(HY013) MAL_MALLOC_FAIL); \
      80             :                 goto bailout; \
      81             :         }
      82             : 
      83             : #define DEC_INT(OUTTYPE, RES, MALFUNC) OUTTYPE RES = (OUTTYPE){0}
      84             : 
      85             : #define INIT_VAROUT(ARG) ptr##ARG = Tloc(b##ARG, 0)
      86             : #define INIT_VARIN(ARG) ptr##ARG = b##ARG##i.base
      87             : #define INIT_ITERIN(ARG)
      88             : 
      89             : #define APPEND_VAR(MALFUNC) ptrn[i] = res
      90             : 
      91             : #define GET_NEXT_VAR(ARG, OFF) ptr##ARG[OFF]
      92             : 
      93             : #define APPEND_STR(MALFUNC) \
      94             :         if (tfastins_nocheckVAR(bn, i, res) != GDK_SUCCEED) { \
      95             :                 msg = createException(SQL, "batmtime." MALFUNC, SQLSTATE(HY013) MAL_MALLOC_FAIL); \
      96             :                 break; \
      97             :         }
      98             : 
      99             : #define GET_NEXT_ITER(ARG, OFF) BUNtvar(b##ARG##i, OFF)
     100             : 
     101             : #define DEC_NOTHING(TYPE, ARG)
     102             : #define INIT_NOTHING(ARG)
     103             : 
     104             : #define FINISH_BUFFER_SINGLE(MALFUNC) \
     105             : bailout: \
     106             :         *ret = NULL; \
     107             :         if (!msg && res && !(*ret = GDKstrdup(res))) \
     108             :                 msg = createException(MAL, "batmtime." MALFUNC, SQLSTATE(HY013) MAL_MALLOC_FAIL); \
     109             :         GDKfree(res)
     110             : 
     111             : #define FINISH_INT_SINGLE(MALFUNC) *ret = res
     112             : 
     113             : #define FINISH_BUFFER_MULTI(RES) GDKfree(RES)
     114             : 
     115             : #define CLEAR_NOTHING(RES)
     116             : 
     117             : 
     118             : #define COPYFLAGS       do { bn->tsorted = b1->tsorted; bn->trevsorted = b1->trevsorted; } while (0)
     119             : #define SETFLAGS        do { bn->tsorted = bn->trevsorted = n < 2; } while (0)
     120             : #define func1(NAME, MALFUNC, INTYPE, OUTTYPE,                                                   \
     121             :                           FUNC, SETFLAGS, FUNC_CALL,                                                            \
     122             :                           DEC_SRC, DEC_OUTPUT,                                                                          \
     123             :                           INIT_SRC, INIT_OUTPUT, GET_NEXT_SRC)                                          \
     124             : static str                                                                                                                              \
     125             : NAME(OUTTYPE *ret, const INTYPE *src)                                                                   \
     126             : {                                                                                                                                               \
     127             :         str msg = MAL_SUCCEED;                                                                                          \
     128             :         do {                                                                                                                            \
     129             :                 FUNC_CALL(FUNC, (*ret), *src);                                                                  \
     130             :         } while (0);                                                                                                            \
     131             :         return msg;                                                                                                                     \
     132             : }                                                                                                                                               \
     133             : static str                                                                                                                              \
     134             : NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)    \
     135             : {                                                                                                                                               \
     136             :         str msg = MAL_SUCCEED;                                                                                          \
     137             :         BAT *b1 = NULL, *s = NULL, *bn = NULL;                                                          \
     138             :         BUN n;                                                                                                                          \
     139             :         struct canditer ci = {0};                                                                                       \
     140             :         oid off;                                                                                                                        \
     141             :         bool nils = false;                                                                                                      \
     142             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     143             :                 *bid = getArgReference_bat(stk, pci, 1),                                                \
     144             :                 *sid = pci->argc == 3 ? getArgReference_bat(stk, pci, 2) : NULL;\
     145             :         BATiter b1i;                                                                                                            \
     146             :         DEC_SRC(INTYPE, 1);                                                                                             \
     147             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     148             :                                                                                                                                                 \
     149             :         (void) cntxt;                                                                                                           \
     150             :         (void) mb;                                                                                                                      \
     151             :         if ((b1 = BATdescriptor(*bid)) == NULL) {                                                       \
     152             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     153             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     154             :                 goto bailout;                                                                                                   \
     155             :         }                                                                                                                                       \
     156             :         b1i = bat_iterator(b1);                                                                                         \
     157             :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {\
     158             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     159             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     160             :                 goto bailout;                                                                                                   \
     161             :         }                                                                                                                                       \
     162             :         off = b1->hseqbase;                                                                                                  \
     163             :         n = canditer_init(&ci, b1, s);                                                                              \
     164             :         if ((bn = COLnew(ci.hseq, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \
     165             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     166             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                             \
     167             :                 goto bailout;                                                                                                   \
     168             :         }                                                                                                                                       \
     169             :         INIT_SRC(1);                                                                                                            \
     170             :         INIT_OUTPUT(n);                                                                                                         \
     171             :         if (ci.tpe == cand_dense) {                                                                                     \
     172             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     173             :                         oid p = (canditer_next_dense(&ci) - off);                                   \
     174             :                         FUNC_CALL(FUNC, ptrn[i], GET_NEXT_SRC(1, p));                           \
     175             :                         nils |= is_##OUTTYPE##_nil(ptrn[i]);                                            \
     176             :                 }                                                                                                                               \
     177             :         } else {                                                                                                                        \
     178             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     179             :                         oid p = (canditer_next(&ci) - off);                                                 \
     180             :                         FUNC_CALL(FUNC, ptrn[i], GET_NEXT_SRC(1, p));                           \
     181             :                         nils |= is_##OUTTYPE##_nil(ptrn[i]);                                            \
     182             :                 }                                                                                                                               \
     183             :         }                                                                                                                                       \
     184             :         bn->tnonil = !nils;                                                                                                  \
     185             :         bn->tnil = nils;                                                                                                     \
     186             :         BATsetcount(bn, n);                                                                                                     \
     187             :         SETFLAGS;                                                                                                                       \
     188             :         bn->tkey = false;                                                                                                    \
     189             : bailout:                                                                                                                                \
     190             :         if (b1) {                                                                                                                       \
     191             :                 bat_iterator_end(&b1i);                                                                                     \
     192             :                 BBPunfix(b1->batCacheid);                                                                            \
     193             :         }                                                                                                                                       \
     194             :         if (s)                                                                                                                          \
     195             :                 BBPunfix(s->batCacheid);                                                                             \
     196             :         if (bn) {                                                                                                                       \
     197             :                 if (msg)                                                                                                                \
     198             :                         BBPreclaim(bn);                                                                                         \
     199             :                 else                                                                                                                    \
     200             :                         BBPkeepref(*ret = bn->batCacheid);                                                   \
     201             :         }                                                                                                                                       \
     202             :         return msg;                                                                                                                     \
     203             : }
     204             : 
     205             : #define func1_noexcept(FUNC, RET, PARAM) RET = FUNC(PARAM)
     206             : #define func1_except(FUNC, RET, PARAM) msg = FUNC(&RET, PARAM); if (msg) break
     207             : 
     208             : #define func2(NAME, MALFUNC,                                                                                    \
     209             :                           INTYPE1, INTYPE2, OUTTYPE, FUNC, FUNC_CALL,                           \
     210             :                           DEC_SRC1, DEC_SRC2, DEC_OUTPUT, DEC_EXTRA,                            \
     211             :                           INIT_SRC1, INIT_SRC2, INIT_OUTPUT,                                            \
     212             :                           GET_NEXT_SRC1, GET_NEXT_SRC2,                                                         \
     213             :                           APPEND_NEXT, CLEAR_EXTRA_SINGLE, CLEAR_EXTRA_MULTI)           \
     214             : static str                                                                                                                              \
     215             : NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2)                                \
     216             : {                                                                                                                                               \
     217             :         str msg = MAL_SUCCEED;                                                                                          \
     218             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     219             :                                                                                                                                                 \
     220             :         do {                                                                                                                            \
     221             :                 FUNC_CALL(FUNC, res, *v1, *v2);                                                                 \
     222             :         } while (0);                                                                                                            \
     223             :         CLEAR_EXTRA_SINGLE(MALFUNC);                                                                            \
     224             :         return msg;                                                                                                                     \
     225             : }                                                                                                                                               \
     226             : static str                                                                                                                              \
     227             : NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)    \
     228             : {                                                                                                                                               \
     229             :         str msg = MAL_SUCCEED;                                                                                          \
     230             :         BAT *b1 = NULL, *b2 = NULL, *s1 = NULL, *s2 = NULL, *bn = NULL;         \
     231             :         BUN n;                                                                                                                          \
     232             :         oid off1, off2;                                                                                                         \
     233             :         struct canditer ci1 = {0}, ci2 = {0};                                                           \
     234             :         bool nils = false;                                                                                                      \
     235             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     236             :                 *bid1 = getArgReference_bat(stk, pci, 1),                                               \
     237             :                 *bid2 = getArgReference_bat(stk, pci, 2),                                               \
     238             :                 *sid1 = pci->argc == 5 ? getArgReference_bat(stk, pci, 3) : NULL, \
     239             :                 *sid2 = pci->argc == 5 ? getArgReference_bat(stk, pci, 4) : NULL; \
     240             :         BATiter b1i, b2i = (BATiter){ .vh = NULL };                                                     \
     241             :         DEC_SRC1(INTYPE1, 1);                                                                                           \
     242             :         DEC_SRC2(INTYPE2, 2);                                                                                           \
     243             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     244             :                                                                                                                                                 \
     245             :         (void) cntxt;                                                                                                           \
     246             :         (void) mb;                                                                                                                      \
     247             :         b1 = BATdescriptor(*bid1);                                                                                      \
     248             :         b2 = BATdescriptor(*bid2);                                                                                      \
     249             :         b1i = bat_iterator(b1);                                                                                         \
     250             :         b2i = bat_iterator(b2);                                                                                         \
     251             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     252             :         if (b1 == NULL || b2 == NULL) {                                                                         \
     253             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     254             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     255             :                 goto bailout;                                                                                                   \
     256             :         }                                                                                                                                       \
     257             :         if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) { \
     258             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     259             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     260             :                 goto bailout;                                                                                                   \
     261             :         }                                                                                                                                       \
     262             :         if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) { \
     263             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     264             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     265             :                 goto bailout;                                                                                                   \
     266             :         }                                                                                                                                       \
     267             :         n = canditer_init(&ci1, b1, s1);                                                                    \
     268             :         if (canditer_init(&ci2, b2, s2) != n || ci1.hseq != ci2.hseq) {             \
     269             :                 msg = createException(MAL, "batmtime." MALFUNC,                               \
     270             :                           "inputs not the same size");                                                                \
     271             :                 goto bailout;                                                                                                   \
     272             :         }                                                                                                                                       \
     273             :         if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \
     274             :                 msg = createException(MAL, "batmtime." MALFUNC,                               \
     275             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                             \
     276             :                 goto bailout;                                                                                                   \
     277             :         }                                                                                                                                       \
     278             :         off1 = b1->hseqbase;                                                                                         \
     279             :         off2 = b2->hseqbase;                                                                                         \
     280             :         INIT_SRC1(1);                                                                                                           \
     281             :         INIT_SRC2(2);                                                                                                           \
     282             :         INIT_OUTPUT(n);                                                                                                         \
     283             :         if (ci1.tpe == cand_dense && ci2.tpe == cand_dense) {                           \
     284             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     285             :                         oid p1 = (canditer_next_dense(&ci1) - off1);                                \
     286             :                         oid p2 = (canditer_next_dense(&ci2) - off2);                                \
     287             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), GET_NEXT_SRC2(2, p2)); \
     288             :                         APPEND_NEXT(MALFUNC);                                                                           \
     289             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     290             :                 }                                                                                                                               \
     291             :         } else {                                                                                                                        \
     292             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     293             :                         oid p1 = (canditer_next(&ci1) - off1);                                              \
     294             :                         oid p2 = (canditer_next(&ci2) - off2);                                              \
     295             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), GET_NEXT_SRC2(2, p2)); \
     296             :                         APPEND_NEXT(MALFUNC);                                                                           \
     297             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     298             :                 }                                                                                                                               \
     299             :         }                                                                                                                                       \
     300             :         bn->tnonil = !nils;                                                                                                  \
     301             :         bn->tnil = nils;                                                                                                     \
     302             :         BATsetcount(bn, n);                                                                                                     \
     303             :         bn->tsorted = n < 2;                                                                                              \
     304             :         bn->trevsorted = n < 2;                                                                                           \
     305             :         bn->tkey = false;                                                                                                    \
     306             : bailout:                                                                                                                                \
     307             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     308             :         bat_iterator_end(&b1i);                                                                                             \
     309             :         bat_iterator_end(&b2i);                                                                                             \
     310             :         if (b1)                                                                                                                         \
     311             :                 BBPunfix(b1->batCacheid);                                                                            \
     312             :         if (b2)                                                                                                                         \
     313             :                 BBPunfix(b2->batCacheid);                                                                            \
     314             :         if (s1)                                                                                                                         \
     315             :                 BBPunfix(s1->batCacheid);                                                                            \
     316             :         if (s2)                                                                                                                         \
     317             :                 BBPunfix(s2->batCacheid);                                                                            \
     318             :         if (bn) {                                                                                                                       \
     319             :                 if (msg)                                                                                                                \
     320             :                         BBPreclaim(bn);                                                                                         \
     321             :                 else                                                                                                                    \
     322             :                         BBPkeepref(*ret = bn->batCacheid);                                                   \
     323             :         }                                                                                                                                       \
     324             :         return msg;                                                                                                                     \
     325             : }                                                                                                                                               \
     326             : static str                                                                                                                              \
     327             : NAME##_bulk_p1(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) \
     328             : {                                                                                                                                               \
     329             :         str msg = MAL_SUCCEED;                                                                                          \
     330             :         BAT *b2 = NULL, *s2 = NULL, *bn = NULL;                                                         \
     331             :         BUN n;                                                                                                                          \
     332             :         oid off2;                                                                                                                       \
     333             :         struct canditer ci2 = {0};                                                                                      \
     334             :         bool nils = false;                                                                                                      \
     335             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     336             :                 *bid2 = getArgReference_bat(stk, pci, 2),                                               \
     337             :                 *sid2 = pci->argc == 4 ? getArgReference_bat(stk, pci, 3) : NULL; \
     338             :         const INTYPE1 src1 = *(INTYPE1*)getArgReference(stk, pci, 1);           \
     339             :         BATiter b2i;                                                                                                            \
     340             :         DEC_SRC2(INTYPE2, 2);                                                                                           \
     341             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     342             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     343             :                                                                                                                                                 \
     344             :         (void) cntxt;                                                                                                           \
     345             :         (void) mb;                                                                                                                      \
     346             :         if ((b2 = BATdescriptor(*bid2)) == NULL) {                                                      \
     347             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     348             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     349             :                 goto bailout;                                                                                                   \
     350             :         }                                                                                                                                       \
     351             :         b2i = bat_iterator(b2);                                                                                         \
     352             :         if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) {\
     353             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     354             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     355             :                 goto bailout;                                                                                                   \
     356             :         }                                                                                                                                       \
     357             :         n = canditer_init(&ci2, b2, s2);                                                                    \
     358             :         if ((bn = COLnew(ci2.hseq, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \
     359             :                 msg = createException(MAL, "batmtime." MALFUNC,                               \
     360             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                             \
     361             :                 goto bailout;                                                                                                   \
     362             :         }                                                                                                                                       \
     363             :         off2 = b2->hseqbase;                                                                                         \
     364             :         INIT_SRC2(2);                                                                                                           \
     365             :         INIT_OUTPUT(n);                                                                                                         \
     366             :         if (ci2.tpe == cand_dense) {                                                                            \
     367             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     368             :                         oid p2 = (canditer_next_dense(&ci2) - off2);                                \
     369             :                         FUNC_CALL(FUNC, res, src1, GET_NEXT_SRC2(2, p2));                       \
     370             :                         APPEND_NEXT(MALFUNC);                                                                           \
     371             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     372             :                 }                                                                                                                               \
     373             :         } else {                                                                                                                        \
     374             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     375             :                         oid p2 = (canditer_next(&ci2) - off2);                                              \
     376             :                         FUNC_CALL(FUNC, res, src1, GET_NEXT_SRC2(2, p2));                       \
     377             :                         APPEND_NEXT(MALFUNC);                                                                           \
     378             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     379             :                 }                                                                                                                               \
     380             :         }                                                                                                                                       \
     381             :         bn->tnonil = !nils;                                                                                                  \
     382             :         bn->tnil = nils;                                                                                                     \
     383             :         BATsetcount(bn, n);                                                                                                     \
     384             :         bn->tsorted = n < 2;                                                                                              \
     385             :         bn->trevsorted = n < 2;                                                                                           \
     386             :         bn->tkey = false;                                                                                                    \
     387             : bailout:                                                                                                                                \
     388             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     389             :         if (b2) {                                                                                                                       \
     390             :                 bat_iterator_end(&b2i);                                                                                     \
     391             :                 BBPunfix(b2->batCacheid);                                                                            \
     392             :         }                                                                                                                                       \
     393             :         if (s2)                                                                                                                         \
     394             :                 BBPunfix(s2->batCacheid);                                                                            \
     395             :         if (bn) {                                                                                                                       \
     396             :                 if (msg)                                                                                                                \
     397             :                         BBPreclaim(bn);                                                                                         \
     398             :                 else                                                                                                                    \
     399             :                         BBPkeepref(*ret = bn->batCacheid);                                                   \
     400             :         }                                                                                                                                       \
     401             :         return msg;                                                                                                                     \
     402             : }                                                                                                                                               \
     403             : static str                                                                                                                              \
     404             : NAME##_bulk_p2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) \
     405             : {                                                                                                                                               \
     406             :         str msg = MAL_SUCCEED;                                                                                          \
     407             :         BAT *b1 = NULL, *s1 = NULL, *bn = NULL;                                                         \
     408             :         BUN n;                                                                                                                          \
     409             :         oid off1;                                                                                                                       \
     410             :         struct canditer ci1 = {0};                                                                                      \
     411             :         bool nils = false;                                                                                                      \
     412             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     413             :                 *bid1 = getArgReference_bat(stk, pci, 1),                                               \
     414             :                 *sid1 = pci->argc == 4 ? getArgReference_bat(stk, pci, 3) : NULL; \
     415             :         BATiter b1i;                                                                                                            \
     416             :         DEC_SRC1(INTYPE1, 1);                                                                                           \
     417             :         const INTYPE2 src2 = *(INTYPE2*)getArgReference(stk, pci, 2);           \
     418             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     419             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     420             :                                                                                                                                                 \
     421             :         (void) cntxt;                                                                                                           \
     422             :         (void) mb;                                                                                                                      \
     423             :         if ((b1 = BATdescriptor(*bid1)) == NULL) {                                                      \
     424             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     425             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     426             :                 goto bailout;                                                                                                   \
     427             :         }                                                                                                                                       \
     428             :         b1i = bat_iterator(b1);                                                                                         \
     429             :         if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) { \
     430             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     431             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     432             :                 goto bailout;                                                                                                   \
     433             :         }                                                                                                                                       \
     434             :         n = canditer_init(&ci1, b1, s1);                                                                    \
     435             :         if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, n, TRANSIENT)) == NULL) { \
     436             :                 msg = createException(MAL, "batmtime." MALFUNC,                               \
     437             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                             \
     438             :                 goto bailout;                                                                                                   \
     439             :         }                                                                                                                                       \
     440             :         off1 = b1->hseqbase;                                                                                         \
     441             :         INIT_SRC1(1);                                                                                                           \
     442             :         INIT_OUTPUT(n);                                                                                                         \
     443             :         if (ci1.tpe == cand_dense) {                                                                            \
     444             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     445             :                         oid p1 = (canditer_next_dense(&ci1) - off1);                                \
     446             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), src2);                       \
     447             :                         APPEND_NEXT(MALFUNC);                                                                           \
     448             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     449             :                 }                                                                                                                               \
     450             :         } else {                                                                                                                        \
     451             :                 for (BUN i = 0; i < n; i++) {                                                                        \
     452             :                         oid p1 = (canditer_next(&ci1) - off1);                                              \
     453             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), src2);                       \
     454             :                         APPEND_NEXT(MALFUNC);                                                                           \
     455             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     456             :                 }                                                                                                                               \
     457             :         }                                                                                                                                       \
     458             :         bn->tnonil = !nils;                                                                                                  \
     459             :         bn->tnil = nils;                                                                                                     \
     460             :         BATsetcount(bn, n);                                                                                                     \
     461             :         bn->tsorted = n < 2;                                                                                              \
     462             :         bn->trevsorted = n < 2;                                                                                           \
     463             :         bn->tkey = false;                                                                                                    \
     464             : bailout:                                                                                                                                \
     465             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     466             :         if (b1) {                                                                                                                       \
     467             :                 bat_iterator_end(&b1i);                                                                                     \
     468             :                 BBPunfix(b1->batCacheid);                                                                            \
     469             :         }                                                                                                                                       \
     470             :         if (s1)                                                                                                                         \
     471             :                 BBPunfix(s1->batCacheid);                                                                            \
     472             :         if (bn) {                                                                                                                       \
     473             :                 if (msg)                                                                                                                \
     474             :                         BBPreclaim(bn);                                                                                         \
     475             :                 else                                                                                                                    \
     476             :                         BBPkeepref(*ret = bn->batCacheid);                                                   \
     477             :         }                                                                                                                                       \
     478             :         return msg;                                                                                                                     \
     479             : }                                                                                                                                               \
     480             : 
     481             : #define func2_noexcept(FUNC, RET, PARAM1, PARAM2) RET = FUNC(PARAM1, PARAM2)
     482             : #define func2_except(FUNC, RET, PARAM1, PARAM2) msg = FUNC(&RET, PARAM1, PARAM2); if (msg) break
     483             : 
     484             : /* TODO change dayint again into an int instead of lng */
     485             : static inline lng
     486          59 : date_diff_imp(const date d1, const date d2)
     487             : {
     488          59 :         int diff = date_diff(d1, d2);
     489          59 :         return is_int_nil(diff) ? lng_nil : (lng) diff * (lng) (24*60*60*1000);
     490             : }
     491          64 : func2(MTIMEdate_diff, "diff",
     492             :           date, date, lng, date_diff_imp, func2_noexcept,
     493             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
     494             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     495             :           GET_NEXT_VAR, GET_NEXT_VAR,
     496             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     497          24 : func2(MTIMEdaytime_diff_msec, "diff",
     498             :           daytime, daytime, lng, daytime_diff, func2_noexcept,
     499             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
     500             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     501             :           GET_NEXT_VAR, GET_NEXT_VAR,
     502             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     503             : 
     504             : static inline str
     505          19 : date_sub_msec_interval(date *ret, date d, lng ms)
     506             : {
     507          19 :         if (is_date_nil(d) || is_lng_nil(ms)) {
     508           0 :                 *ret = date_nil;
     509           0 :                 return MAL_SUCCEED;
     510             :         }
     511          19 :         if (is_date_nil((*ret = date_add_day(d, (int) (-ms / (24*60*60*1000))))))
     512           0 :                 throw(MAL, "mtime.date_sub_msec_interval", SQLSTATE(22003) "overflow in calculation");
     513             :         return MAL_SUCCEED;
     514             : }
     515             : static inline str
     516         426 : date_add_msec_interval(date *ret, date d, lng ms)
     517             : {
     518         426 :         if (is_date_nil(d) || is_lng_nil(ms)) {
     519           0 :                 *ret = date_nil;
     520           0 :                 return MAL_SUCCEED;
     521             :         }
     522         426 :         if (is_date_nil((*ret = date_add_day(d, (int) (ms / (24*60*60*1000))))))
     523           0 :                 throw(MAL, "mtime.date_add_msec_interval", SQLSTATE(22003) "overflow in calculation");
     524             :         return MAL_SUCCEED;
     525             : }
     526          23 : func2(MTIMEdate_sub_msec_interval, "date_sub_msec_interval",
     527             :           date, lng, date, date_sub_msec_interval, func2_except,
     528             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     529             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     530             :           GET_NEXT_VAR, GET_NEXT_VAR,
     531             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     532         433 : func2(MTIMEdate_add_msec_interval, "date_add_msec_interval",
     533             :           date, lng, date, date_add_msec_interval, func2_except,
     534             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     535             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     536             :           GET_NEXT_VAR, GET_NEXT_VAR,
     537             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     538             : 
     539             : static inline str
     540           4 : timestamp_sub_msec_interval(timestamp *ret, timestamp ts, lng ms)
     541             : {
     542           4 :         if (is_timestamp_nil(ts) || is_lng_nil(ms)) {
     543           0 :                 *ret = timestamp_nil;
     544           0 :                 return MAL_SUCCEED;
     545             :         }
     546           4 :         if (is_timestamp_nil((*ret = timestamp_add_usec(ts, -ms * 1000))))
     547           0 :                 throw(MAL, "mtime.timestamp_sub_msec_interval", SQLSTATE(22003) "overflow in calculation");
     548             :         return MAL_SUCCEED;
     549             : }
     550             : static inline str
     551         125 : timestamp_add_msec_interval(timestamp *ret, timestamp ts, lng ms)
     552             : {
     553         125 :         if (is_timestamp_nil(ts) || is_lng_nil(ms)) {
     554          14 :                 *ret = timestamp_nil;
     555          14 :                 return MAL_SUCCEED;
     556             :         }
     557         111 :         if (is_timestamp_nil((*ret = timestamp_add_usec(ts, ms * 1000))))
     558           0 :                 throw(MAL, "mtime.timestamp_add_msec_interval", SQLSTATE(22003) "overflow in calculation");
     559             :         return MAL_SUCCEED;
     560             : }
     561           5 : func2(MTIMEtimestamp_sub_msec_interval, "timestamp_sub_msec_interval",
     562             :           timestamp, lng, timestamp, timestamp_sub_msec_interval, func2_except,
     563             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     564             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     565             :           GET_NEXT_VAR, GET_NEXT_VAR,
     566             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     567         239 : func2(MTIMEtimestamp_add_msec_interval, "timestamp_add_msec_interval",
     568             :           timestamp, lng, timestamp, timestamp_add_msec_interval, func2_except,
     569             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     570             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     571             :           GET_NEXT_VAR, GET_NEXT_VAR,
     572             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     573             : 
     574             : static inline str
     575           0 : timestamp_sub_month_interval(timestamp *ret, timestamp ts, int m)
     576             : {
     577           0 :         if (is_timestamp_nil(ts) || is_int_nil(m)) {
     578           0 :                 *ret = timestamp_nil;
     579           0 :                 return MAL_SUCCEED;
     580             :         }
     581           0 :         if (is_timestamp_nil((*ret = timestamp_add_month(ts, -m))))
     582           0 :                 throw(MAL, "mtime.timestamp_sub_month_interval", SQLSTATE(22003) "overflow in calculation");
     583             :         return MAL_SUCCEED;
     584             : }
     585             : static inline str
     586           1 : timestamp_add_month_interval(timestamp *ret, timestamp ts, int m)
     587             : {
     588           1 :         if (is_timestamp_nil(ts) || is_int_nil(m)) {
     589           0 :                 *ret = timestamp_nil;
     590           0 :                 return MAL_SUCCEED;
     591             :         }
     592           1 :         if (is_timestamp_nil((*ret = timestamp_add_month(ts, m))))
     593           0 :                 throw(MAL, "mtime.timestamp_add_month_interval", SQLSTATE(22003) "overflow in calculation");
     594             :         return MAL_SUCCEED;
     595             : }
     596           0 : func2(MTIMEtimestamp_sub_month_interval, "timestamp_sub_month_interval",
     597             :           timestamp, int, timestamp, timestamp_sub_month_interval, func2_except,
     598             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     599             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     600             :           GET_NEXT_VAR, GET_NEXT_VAR,
     601             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     602           1 : func2(MTIMEtimestamp_add_month_interval, "timestamp_add_month_interval",
     603             :           timestamp, int, timestamp, timestamp_add_month_interval, func2_except,
     604             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     605             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     606             :           GET_NEXT_VAR, GET_NEXT_VAR,
     607             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     608             : 
     609             : static inline daytime
     610           2 : time_sub_msec_interval(const daytime t, const lng ms)
     611             : {
     612           2 :         if (is_lng_nil(ms))
     613           0 :                 return daytime_nil;
     614           2 :         return daytime_add_usec_modulo(t, -ms * 1000);
     615             : }
     616             : static inline daytime
     617           7 : time_add_msec_interval(const daytime t, const lng ms)
     618             : {
     619           7 :         if (is_lng_nil(ms))
     620           0 :                 return daytime_nil;
     621           7 :         return daytime_add_usec_modulo(t, ms * 1000);
     622             : }
     623           2 : func2(MTIMEtime_sub_msec_interval, "time_sub_msec_interval",
     624             :           daytime, lng, daytime, time_sub_msec_interval, func2_noexcept,
     625             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     626             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     627             :           GET_NEXT_VAR, GET_NEXT_VAR,
     628             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     629          14 : func2(MTIMEtime_add_msec_interval, "time_add_msec_interval",
     630             :           daytime, lng, daytime, time_add_msec_interval, func2_noexcept,
     631             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     632             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     633             :           GET_NEXT_VAR, GET_NEXT_VAR,
     634             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     635             : 
     636             : static inline str
     637           3 : date_submonths(date *ret, date d, int m)
     638             : {
     639           3 :         if (is_date_nil(d) || is_int_nil(m)) {
     640           0 :                 *ret = date_nil;
     641           0 :                 return MAL_SUCCEED;
     642             :         }
     643           3 :         if (is_date_nil((*ret = date_add_month(d, -m))))
     644           0 :                 throw(MAL, "mtime.date_submonths", SQLSTATE(22003) "overflow in calculation");
     645             :         return MAL_SUCCEED;
     646             : }
     647             : static inline str
     648          12 : date_addmonths(date *ret, date d, int m)
     649             : {
     650          12 :         if (is_date_nil(d) || is_int_nil(m)) {
     651           0 :                 *ret = date_nil;
     652           0 :                 return MAL_SUCCEED;
     653             :         }
     654          12 :         if (is_date_nil((*ret = date_add_month(d, m))))
     655           0 :                 throw(MAL, "mtime.date_addmonths", SQLSTATE(22003) "overflow in calculation");
     656             :         return MAL_SUCCEED;
     657             : }
     658           3 : func2(MTIMEdate_submonths, "date_submonths",
     659             :           date, int, date, date_submonths, func2_except,
     660             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     661             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     662             :           GET_NEXT_VAR, GET_NEXT_VAR,
     663             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     664          12 : func2(MTIMEdate_addmonths, "date_addmonths",
     665             :           date, int, date, date_addmonths, func2_except,
     666             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     667             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     668             :           GET_NEXT_VAR, GET_NEXT_VAR,
     669             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     670             : 
     671             : #define date_to_msec_since_epoch(t) is_date_nil(t) ? lng_nil : (timestamp_diff(timestamp_create(t, daytime_create(0, 0, 0, 0)), unixepoch) / 1000)
     672             : #define daytime_to_msec_since_epoch(t) daytime_diff(t, daytime_create(0, 0, 0, 0))
     673          26 : func1(MTIMEdate_extract_century, "date_century", date, int,
     674             :           date_century, COPYFLAGS, func1_noexcept,
     675             :           DEC_VAR_R, DEC_VAR_R,
     676             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     677           7 : func1(MTIMEdate_extract_decade, "date_decade", date, int,
     678             :           date_decade, COPYFLAGS, func1_noexcept,
     679             :           DEC_VAR_R, DEC_VAR_R,
     680             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     681     2003495 : func1(MTIMEdate_extract_year, "date_year", date, int,
     682             :           date_year, COPYFLAGS, func1_noexcept,
     683             :           DEC_VAR_R, DEC_VAR_R,
     684             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     685          33 : func1(MTIMEdate_extract_quarter, "date_quarter", date, int,
     686             :           date_quarter, SETFLAGS, func1_noexcept,
     687             :           DEC_VAR_R, DEC_VAR_R,
     688             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     689     2000703 : func1(MTIMEdate_extract_month, "date_month", date, int,
     690             :           date_month, SETFLAGS, func1_noexcept,
     691             :           DEC_VAR_R, DEC_VAR_R,
     692             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     693     2000119 : func1(MTIMEdate_extract_day, "date_day", date, int,
     694             :           date_day, SETFLAGS, func1_noexcept,
     695             :           DEC_VAR_R, DEC_VAR_R,
     696             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     697          36 : func1(MTIMEdate_extract_dayofyear, "date_dayofyear", date, int,
     698             :           date_dayofyear, SETFLAGS, func1_noexcept,
     699             :           DEC_VAR_R, DEC_VAR_R,
     700             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     701         141 : func1(MTIMEdate_extract_weekofyear, "date_weekofyear", date, int,
     702             :           date_weekofyear, SETFLAGS, func1_noexcept,
     703             :           DEC_VAR_R, DEC_VAR_R,
     704             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     705           0 : func1(MTIMEdate_extract_usweekofyear, "date_usweekofyear", date, int,
     706             :           date_usweekofyear, SETFLAGS, func1_noexcept,
     707             :           DEC_VAR_R, DEC_VAR_R,
     708             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     709          41 : func1(MTIMEdate_extract_dayofweek, "date_dayofweek", date, int,
     710             :           date_dayofweek, SETFLAGS, func1_noexcept,
     711             :           DEC_VAR_R, DEC_VAR_R,
     712             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     713          17 : func1(MTIMEdate_extract_epoch_ms, "epoch_ms", date, lng,
     714             :           date_to_msec_since_epoch, COPYFLAGS, func1_noexcept,
     715             :           DEC_VAR_R, DEC_VAR_R,
     716             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     717     2000057 : func1(MTIMEdaytime_extract_hours, "daytime_hour", daytime, int,
     718             :           daytime_hour, COPYFLAGS, func1_noexcept,
     719             :           DEC_VAR_R, DEC_VAR_R,
     720             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     721     2000061 : func1(MTIMEdaytime_extract_minutes, "daytime_minutes", daytime, int,
     722             :           daytime_min, SETFLAGS, func1_noexcept,
     723             :           DEC_VAR_R, DEC_VAR_R,
     724             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     725     2000055 : func1(MTIMEdaytime_extract_sql_seconds, "daytime_seconds", daytime, int,
     726             :           daytime_sec_usec, SETFLAGS, func1_noexcept,
     727             :           DEC_VAR_R, DEC_VAR_R,
     728             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     729          10 : func1(MTIMEdaytime_extract_epoch_ms, "epoch_ms", daytime, lng,
     730             :           daytime_to_msec_since_epoch, COPYFLAGS, func1_noexcept,
     731             :           DEC_VAR_R, DEC_VAR_R,
     732             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     733             : 
     734             : static inline lng
     735          87 : TSDIFF(timestamp t1, timestamp t2)
     736             : {
     737          87 :         lng diff = timestamp_diff(t1, t2);
     738          87 :         if (!is_lng_nil(diff)) {
     739             : #ifndef TRUNCATE_NUMBERS
     740          83 :                 if (diff < 0)
     741          18 :                         diff = -((-diff + 500) / 1000);
     742             :                 else
     743          65 :                         diff = (diff + 500) / 1000;
     744             : #else
     745             :                 diff /= 1000;
     746             : #endif
     747             :         }
     748          87 :         return diff;
     749             : }
     750         127 : func2(MTIMEtimestamp_diff_msec, "diff",
     751             :           timestamp, timestamp, lng, TSDIFF, func2_noexcept,
     752             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
     753             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     754             :           GET_NEXT_VAR, GET_NEXT_VAR,
     755             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     756             : 
     757             : static inline int
     758          17 : timestamp_century(const timestamp t)
     759             : {
     760          17 :         if (is_timestamp_nil(t))
     761           2 :                 return int_nil;
     762          15 :         int y = date_year(timestamp_date(t));
     763          15 :         if (y > 0)
     764          15 :                 return (y - 1) / 100 + 1;
     765             :         else
     766           0 :                 return -((-y - 1) / 100 + 1);
     767             : }
     768             : #define timestamp_decade(t) is_timestamp_nil(t) ? int_nil : date_year(timestamp_date(t)) / 10
     769             : #define timestamp_year(t) date_year(timestamp_date(t))
     770             : #define timestamp_quarter(t) is_timestamp_nil(t) ? int_nil : (date_month(timestamp_date(t)) - 1) / 3 + 1
     771             : #define timestamp_month(t) date_month(timestamp_date(t))
     772             : #define timestamp_day(t) date_day(timestamp_date(t))
     773             : #define timestamp_hours(t) daytime_hour(timestamp_daytime(t))
     774             : #define timestamp_minutes(t) daytime_min(timestamp_daytime(t))
     775             : #define timestamp_extract_usecond(ts)   daytime_sec_usec(timestamp_daytime(ts))
     776             : #define timestamp_to_msec_since_epoch(t) is_timestamp_nil(t) ? lng_nil : (timestamp_diff(t, unixepoch) / 1000)
     777          19 : func1(MTIMEtimestamp_century, "timestamp_century", timestamp, int,
     778             :           timestamp_century, COPYFLAGS, func1_noexcept,
     779             :           DEC_VAR_R, DEC_VAR_R,
     780             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     781           0 : func1(MTIMEtimestamp_decade, "timestamp_decade", timestamp, int,
     782             :           timestamp_decade, COPYFLAGS, func1_noexcept,
     783             :           DEC_VAR_R, DEC_VAR_R,
     784             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     785     2000090 : func1(MTIMEtimestamp_year, "timestamp_year", timestamp, int,
     786             :           timestamp_year, COPYFLAGS, func1_noexcept,
     787             :           DEC_VAR_R, DEC_VAR_R,
     788             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     789          38 : func1(MTIMEtimestamp_quarter,"timestamp_quarter", timestamp, int,
     790             :           timestamp_quarter, SETFLAGS, func1_noexcept,
     791             :           DEC_VAR_R, DEC_VAR_R,
     792             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     793     1875715 : func1(MTIMEtimestamp_month, "timestamp_month", timestamp, int,
     794             :           timestamp_month, SETFLAGS, func1_noexcept,
     795             :           DEC_VAR_R, DEC_VAR_R,
     796             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     797     2000069 : func1(MTIMEtimestamp_day, "timestamp_day", timestamp, int,
     798             :           timestamp_day, SETFLAGS, func1_noexcept,
     799             :           DEC_VAR_R, DEC_VAR_R,
     800             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     801     2000138 : func1(MTIMEtimestamp_hours, "timestamp_hours", timestamp, int,
     802             :           timestamp_hours, SETFLAGS, func1_noexcept,
     803             :           DEC_VAR_R, DEC_VAR_R,
     804             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     805     2000138 : func1(MTIMEtimestamp_minutes, "timestamp_minutes", timestamp, int,
     806             :           timestamp_minutes, SETFLAGS, func1_noexcept,
     807             :           DEC_VAR_R, DEC_VAR_R,
     808             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     809     2000152 : func1(MTIMEtimestamp_sql_seconds, "sql_seconds", timestamp, int,
     810             :           timestamp_extract_usecond, SETFLAGS, func1_noexcept,
     811             :           DEC_VAR_R, DEC_VAR_R,
     812             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     813          18 : func1(MTIMEtimestamp_extract_epoch_ms, "epoch_ms", timestamp, lng,
     814             :           timestamp_to_msec_since_epoch, COPYFLAGS, func1_noexcept,
     815             :           DEC_VAR_R, DEC_VAR_R,
     816             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     817             : 
     818             : #define sql_year(m) is_int_nil(m) ? int_nil : m / 12
     819             : #define sql_month(m) is_int_nil(m) ? int_nil : m % 12
     820             : #define sql_day(m) is_lng_nil(m) ? lng_nil : m / (24*60*60*1000)
     821             : #define sql_hours(m) is_lng_nil(m) ? int_nil : (int) ((m % (24*60*60*1000)) / (60*60*1000))
     822             : #define sql_minutes(m) is_lng_nil(m) ? int_nil : (int) ((m % (60*60*1000)) / (60*1000))
     823             : #define sql_seconds(m) is_lng_nil(m) ? int_nil : (int) ((m % (60*1000)) / 1000)
     824             : #define msec_since_epoch(ts)    ts
     825           1 : func1(MTIMEsql_year, "sql_year", int, int,
     826             :           sql_year, COPYFLAGS, func1_noexcept,
     827             :           DEC_VAR_R, DEC_VAR_R,
     828             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     829           0 : func1(MTIMEsql_month, "sql_month", int, int,
     830             :           sql_month, SETFLAGS, func1_noexcept,
     831             :           DEC_VAR_R, DEC_VAR_R,
     832             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     833           2 : func1(MTIMEsql_day, "sql_day", lng, lng,
     834             :           sql_day, COPYFLAGS, func1_noexcept,
     835             :           DEC_VAR_R, DEC_VAR_R,
     836             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     837           2 : func1(MTIMEsql_hours, "sql_hours", lng, int,
     838             :           sql_hours, SETFLAGS, func1_noexcept,
     839             :           DEC_VAR_R, DEC_VAR_R,
     840             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     841           5 : func1(MTIMEsql_minutes, "sql_minutes", lng, int,
     842             :           sql_minutes, SETFLAGS, func1_noexcept,
     843             :           DEC_VAR_R, DEC_VAR_R,
     844             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     845           2 : func1(MTIMEsql_seconds, "sql_seconds", lng, int,
     846             :           sql_seconds, SETFLAGS, func1_noexcept,
     847             :           DEC_VAR_R, DEC_VAR_R,
     848             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     849           2 : func1(MTIMEmsec_extract_epoch_ms, "msepoch", lng, lng,
     850             :           msec_since_epoch, COPYFLAGS, func1_noexcept,
     851             :           DEC_VAR_R, DEC_VAR_R,
     852             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     853             : 
     854             : static inline str
     855           0 : date_fromstr_func(date *ret, str s)
     856             : {
     857           0 :         if (date_fromstr(s, &(size_t){sizeof(date)}, &ret, false) < 0)
     858           0 :                 throw(MAL, "mtime.date_fromstr", GDK_EXCEPTION);
     859           0 :         return MAL_SUCCEED;
     860             : }
     861           0 : func1(MTIMEdate_fromstr, "date_fromstr", str, date,
     862             :           date_fromstr_func, SETFLAGS, func1_except,
     863             :           DEC_ITER, DEC_VAR_R,
     864             :           INIT_ITERIN, INIT_VAROUT, GET_NEXT_ITER)
     865             : 
     866             : #define date_date(m) m
     867           0 : func1(MTIMEdate_date, "date_date", date, date,
     868             :           date_date, COPYFLAGS, func1_noexcept,
     869             :           DEC_VAR_R, DEC_VAR_R,
     870             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     871             : 
     872         241 : func1(MTIMEtimestamp_extract_date, "date", timestamp, date,
     873             :           timestamp_date, COPYFLAGS, func1_noexcept,
     874             :           DEC_VAR_R, DEC_VAR_R,
     875             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     876             : 
     877             : static inline str
     878           0 : timestamp_fromstr_func(timestamp *ret, str s)
     879             : {
     880           0 :         if (timestamp_fromstr(s, &(size_t){sizeof(timestamp)}, &ret, false) < 0)
     881           0 :                 throw(MAL, "mtime.timestamp_fromstr", GDK_EXCEPTION);
     882           0 :         return MAL_SUCCEED;
     883             : }
     884           0 : func1(MTIMEtimestamp_fromstr, "timestamp_fromstr", str, timestamp,
     885             :           timestamp_fromstr_func, SETFLAGS, func1_except,
     886             :           DEC_ITER, DEC_VAR_R,
     887             :           INIT_ITERIN, INIT_VAROUT, GET_NEXT_ITER)
     888             : 
     889             : #define timestamp_timestamp(m) m
     890           0 : func1(MTIMEtimestamp_timestamp, "timestamp_timestamp", timestamp, timestamp,
     891             :           timestamp_timestamp, COPYFLAGS, func1_noexcept,
     892             :           DEC_VAR_R, DEC_VAR_R,
     893             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     894             : 
     895             : #define mkts(dt)        timestamp_create(dt, daytime_create(0, 0, 0, 0))
     896           0 : func1(MTIMEtimestamp_fromdate, "timestamp_fromdate", date, timestamp,
     897             :           mkts, COPYFLAGS, func1_noexcept,
     898             :           DEC_VAR_R, DEC_VAR_R,
     899             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     900             : 
     901             : #define seconds_since_epoch(t) is_timestamp_nil(t) ? int_nil : (int) (timestamp_diff(t, unixepoch) / 1000000);
     902          60 : func1(MTIMEseconds_since_epoch, "seconds_since_epoch", timestamp, int,
     903             :           seconds_since_epoch, COPYFLAGS, func1_noexcept,
     904             :           DEC_VAR_R, DEC_VAR_R,
     905             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     906             : 
     907             : #define mktsfromsec(sec)        (is_int_nil(sec) ?                                                      \
     908             :                                                          timestamp_nil :                                                        \
     909             :                                                          timestamp_add_usec(unixepoch,                          \
     910             :                                                                                                 (sec) * LL_CONSTANT(1000000)))
     911             : #define mktsfrommsec(msec)      (is_lng_nil(msec) ?                                                     \
     912             :                                                          timestamp_nil :                                                        \
     913             :                                                          timestamp_add_usec(unixepoch,                          \
     914             :                                                                                                 (msec) * LL_CONSTANT(1000)))
     915             : /* TODO later I have to remove this call */
     916           5 : func1(MTIMEtimestamp_fromsecond_epoch, "timestamp_fromsecond_epoch", int, timestamp,
     917             :           mktsfromsec, COPYFLAGS, func1_noexcept,
     918             :           DEC_VAR_R, DEC_VAR_R,
     919             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     920           0 : func1(MTIMEtimestamp_fromsecond, "timestamp_fromsecond", int, timestamp,
     921             :           mktsfromsec, COPYFLAGS, func1_noexcept,
     922             :           DEC_VAR_R, DEC_VAR_R,
     923             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     924             : /* TODO later I have to remove this call */
     925          55 : func1(MTIMEtimestamp_frommsec_epoch, "timestamp_frommsec_epoch", lng, timestamp,
     926             :           mktsfrommsec, COPYFLAGS, func1_noexcept,
     927             :           DEC_VAR_R, DEC_VAR_R,
     928             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     929           0 : func1(MTIMEtimestamp_frommsec, "timestamp_frommsec", lng, timestamp,
     930             :           mktsfrommsec, COPYFLAGS, func1_noexcept,
     931             :           DEC_VAR_R, DEC_VAR_R,
     932             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     933             : 
     934             : static inline str
     935           3 : daytime_fromstr_func(daytime *ret, str s)
     936             : {
     937           3 :         if (daytime_fromstr(s, &(size_t){sizeof(daytime)}, &ret, false) < 0)
     938           0 :                 throw(MAL, "mtime.daytime_fromstr", GDK_EXCEPTION);
     939           3 :         return MAL_SUCCEED;
     940             : }
     941           3 : func1(MTIMEdaytime_fromstr, "daytime_fromstr", str, daytime,
     942             :           daytime_fromstr_func, SETFLAGS, func1_except,
     943             :           DEC_ITER, DEC_VAR_R,
     944             :           INIT_ITERIN, INIT_VAROUT, GET_NEXT_ITER)
     945             : 
     946             : #define daytime_daytime(m) m
     947           0 : func1(MTIMEdaytime_daytime, "daytime_daytime", daytime, daytime,
     948             :           daytime_daytime, COPYFLAGS, func1_noexcept,
     949             :           DEC_VAR_R, DEC_VAR_R,
     950             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     951             : 
     952             : static inline str
     953           0 : daytime_fromseconds(daytime *ret, lng secs)
     954             : {
     955           0 :         if (is_lng_nil(secs))
     956           0 :                 *ret = daytime_nil;
     957           0 :         else if (secs < 0 || secs >= 24*60*60)
     958           0 :                 throw(MAL, "mtime.daytime_fromseconds", SQLSTATE(42000) ILLEGAL_ARGUMENT);
     959             :         else
     960           0 :                 *ret = (daytime) (secs * 1000000);
     961             :         return MAL_SUCCEED;
     962             : }
     963           0 : func1(MTIMEdaytime_fromseconds, "daytime_fromseconds", lng, daytime,
     964             :           daytime_fromseconds, COPYFLAGS, func1_except,
     965             :           DEC_VAR_R, DEC_VAR_R,
     966             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     967             : 
     968           0 : func1(MTIMEtimestamp_extract_daytime, "timestamp_extract_daytime", timestamp, daytime,
     969             :           timestamp_daytime, SETFLAGS, func1_noexcept,
     970             :           DEC_VAR_R, DEC_VAR_R,
     971             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     972             : 
     973             : /* return current system time zone offset in seconds East of Greenwich */
     974             : static int
     975           1 : local_timezone(int *isdstp)
     976             : {
     977             :         int tzone = 0;
     978             :         int isdst = -1;
     979             : 
     980             : #if defined(_MSC_VER)
     981             :         DYNAMIC_TIME_ZONE_INFORMATION tzinf;
     982             : 
     983             :         /* documentation says: UTC = localtime + Bias (in minutes),
     984             :          * but experimentation during DST period says, UTC = localtime
     985             :          * + Bias + DaylightBias, and presumably during non DST
     986             :          * period, UTC = localtime + Bias */
     987             :         switch (GetDynamicTimeZoneInformation(&tzinf)) {
     988             :         case TIME_ZONE_ID_STANDARD:     /* using standard time */
     989             :         case TIME_ZONE_ID_UNKNOWN:      /* no daylight saving time in this zone */
     990             :                 isdst = 0;
     991             :                 tzone = -(int) tzinf.Bias * 60;
     992             :                 break;
     993             :         case TIME_ZONE_ID_DAYLIGHT:     /* using daylight saving time */
     994             :                 isdst = 1;
     995             :                 tzone = -(int) (tzinf.Bias + tzinf.DaylightBias) * 60;
     996             :                 break;
     997             :         default:                        /* aka TIME_ZONE_ID_INVALID */
     998             :                 /* call failed, we don't know the time zone */
     999             :                 tzone = 0;
    1000             :                 break;
    1001             :         }
    1002             : #elif defined(HAVE_STRUCT_TM_TM_ZONE)
    1003             :         time_t t;
    1004             :         struct tm tm = (struct tm) {0};
    1005             : 
    1006             :         if ((t = time(NULL)) != (time_t) -1 && localtime_r(&t, &tm)) {
    1007             :                 tzone = (int) tm.tm_gmtoff;
    1008             :                 isdst = tm.tm_isdst;
    1009             :         }
    1010             : #else
    1011             :         time_t t;
    1012           1 :         struct tm tm = (struct tm) {0};
    1013             : 
    1014           1 :         if ((t = time(NULL)) != (time_t) -1 && gmtime_r(&t, &tm)) {
    1015             :                 timestamp lt, gt;
    1016           2 :                 gt = timestamp_create(date_create(tm.tm_year + 1900,
    1017           1 :                                                                                   tm.tm_mon + 1,
    1018             :                                                                                   tm.tm_mday),
    1019             :                                                           daytime_create(tm.tm_hour,
    1020             :                                                                                          tm.tm_min,
    1021           1 :                                                                                          tm.tm_sec == 60 ? 59 : tm.tm_sec,
    1022             :                                                                                          0));
    1023           1 :                 if (localtime_r(&t, &tm)) {
    1024           1 :                         isdst = tm.tm_isdst;
    1025           2 :                         lt = timestamp_create(date_create(tm.tm_year + 1900,
    1026           1 :                                                                                           tm.tm_mon + 1,
    1027             :                                                                                           tm.tm_mday),
    1028             :                                                                   daytime_create(tm.tm_hour,
    1029             :                                                                                                  tm.tm_min,
    1030           1 :                                                                                                  tm.tm_sec == 60 ? 59 : tm.tm_sec,
    1031             :                                                                                                  0));
    1032           1 :                         tzone = (int) (timestamp_diff(lt, gt) / 1000000);
    1033             :                 }
    1034             :         }
    1035             : #endif
    1036           1 :         if (isdstp)
    1037           1 :                 *isdstp = isdst;
    1038           1 :         return tzone;
    1039             : }
    1040             : 
    1041             : static str
    1042           0 : MTIMElocal_timezone_msec(lng *ret)
    1043             : {
    1044           0 :         int tzone = local_timezone(NULL);
    1045           0 :         *ret = (lng) tzone * 1000;
    1046           0 :         return MAL_SUCCEED;
    1047             : }
    1048             : 
    1049             : static str
    1050          10 : timestamp_to_str(str *buf, const timestamp *d, str *format, const char *type, const char *malfunc)
    1051             : {
    1052             :         date dt;
    1053             :         daytime t;
    1054             :         struct tm tm;
    1055             : 
    1056          20 :         if (is_timestamp_nil(*d) || strNil(*format)) {
    1057           0 :                 strcpy(*buf, str_nil);
    1058           0 :                 return MAL_SUCCEED;
    1059             :         }
    1060          10 :         dt = timestamp_date(*d);
    1061          10 :         t = timestamp_daytime(*d);
    1062          10 :         tm = (struct tm) {
    1063          10 :                 .tm_year = date_year(dt) - 1900,
    1064          10 :                 .tm_mon = date_month(dt) - 1,
    1065          10 :                 .tm_mday = date_day(dt),
    1066          10 :                 .tm_wday = date_dayofweek(dt) % 7,
    1067          10 :                 .tm_yday = date_dayofyear(dt) - 1,
    1068          10 :                 .tm_hour = daytime_hour(t),
    1069          10 :                 .tm_min = daytime_min(t),
    1070          10 :                 .tm_sec = daytime_sec(t),
    1071             :         };
    1072          10 :         if (strftime(*buf, MTIME_STR_BUFFER_LENGTH, *format, &tm) == 0)
    1073           0 :                 throw(MAL, malfunc, "cannot convert %s", type);
    1074             :         return MAL_SUCCEED;
    1075             : }
    1076             : 
    1077             : static str
    1078         205 : str_to_timestamp(timestamp *ret, str *s, str *format, const char *type, const char *malfunc)
    1079             : {
    1080         205 :         struct tm tm = (struct tm) {0};
    1081             :         time_t t;
    1082             : 
    1083         615 :         if (strNil(*s) || strNil(*format)) {
    1084           0 :                 *ret = timestamp_nil;
    1085           0 :                 return MAL_SUCCEED;
    1086             :         }
    1087         205 :         t = time(NULL);
    1088         205 :         localtime_r(&t, &tm);
    1089         205 :         tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
    1090         205 :         tm.tm_isdst = -1;
    1091         205 :         if (strptime(*s, *format, &tm) == NULL)
    1092           0 :                 throw(MAL, malfunc,
    1093             :                           "format '%s', doesn't match %s '%s'", *format, type, *s);
    1094         410 :         *ret = timestamp_create(date_create(tm.tm_year + 1900,
    1095         205 :                                                                                 tm.tm_mon + 1,
    1096             :                                                                                 tm.tm_mday),
    1097             :                                                         daytime_create(tm.tm_hour,
    1098             :                                                                                    tm.tm_min,
    1099         205 :                                                                                    tm.tm_sec == 60 ? 59 : tm.tm_sec,
    1100             :                                                                                    0));
    1101             :         /* if strptime filled in DST information (tm_isdst >= 0), then the
    1102             :          * time is in system local time and we convert to GMT by
    1103             :          * subtracting the time zone offset, else we don't touch the time
    1104             :          * returned because it is assumed to already be in GMT */
    1105         205 :         if (tm.tm_isdst >= 0) {
    1106           1 :                 int isdst = 0;
    1107           1 :                 int tz = local_timezone(&isdst);
    1108             :                 /* if strptime's information doesn't square with our own
    1109             :                  * information about having or not having DST, we compensate
    1110             :                  * an hour */
    1111           1 :                 if (tm.tm_isdst > 0 && isdst == 0) {
    1112           0 :                         tz += 3600;
    1113           1 :                 } else if (tm.tm_isdst == 0 && isdst > 0) {
    1114           1 :                         tz -= 3600;
    1115             :                 }
    1116             : 
    1117           1 :                 *ret = timestamp_add_usec(*ret, -tz * LL_CONSTANT(1000000));
    1118             :         }
    1119         205 :         if (is_timestamp_nil(*ret))
    1120           0 :                 throw(MAL, malfunc, "bad %s '%s'", type, *s);
    1121             :         return MAL_SUCCEED;
    1122             : }
    1123             : 
    1124             : static inline str
    1125         193 : str_to_date(date *ret, str s, str format)
    1126             : {
    1127             :         str msg = MAL_SUCCEED;
    1128             :         timestamp ts;
    1129         193 :         if ((msg = str_to_timestamp(&ts, &s, &format, "date", "mtime.str_to_date")) != MAL_SUCCEED)
    1130             :                 return msg;
    1131         193 :         *ret = timestamp_date(ts);
    1132         193 :         return MAL_SUCCEED;
    1133             : }
    1134         194 : func2(MTIMEstr_to_date, "str_to_date",
    1135             :           str, str, date, str_to_date, func2_except,
    1136             :           DEC_ITER, DEC_ITER, DEC_VAR_R, DEC_INT,
    1137             :           INIT_ITERIN, INIT_ITERIN, INIT_VAROUT,
    1138             :           GET_NEXT_ITER, GET_NEXT_ITER,
    1139             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1140             : 
    1141             : static inline str
    1142           1 : str_to_time(daytime *ret, str s, str format)
    1143             : {
    1144             :         str msg = MAL_SUCCEED;
    1145             :         timestamp ts;
    1146           1 :         if ((msg = str_to_timestamp(&ts, &s, &format, "time", "mtime.str_to_time")) != MAL_SUCCEED)
    1147             :                 return msg;
    1148           1 :         *ret = timestamp_daytime(ts);
    1149           1 :         return MAL_SUCCEED;
    1150             : }
    1151           1 : func2(MTIMEstr_to_time, "str_to_time",
    1152             :           str, str, daytime, str_to_time, func2_except,
    1153             :           DEC_ITER, DEC_ITER, DEC_VAR_R, DEC_INT,
    1154             :           INIT_ITERIN, INIT_ITERIN, INIT_VAROUT,
    1155             :           GET_NEXT_ITER, GET_NEXT_ITER,
    1156             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1157             : 
    1158             : static inline str
    1159             : str_to_timestamp_func(timestamp *ret, str s, str format)
    1160             : {
    1161          11 :         return str_to_timestamp(ret, &s, &format, "timestamp", "mtime.str_to_timestamp");
    1162             : }
    1163          11 : func2(MTIMEstr_to_timestamp, "str_to_timestamp",
    1164             :           str, str, timestamp, str_to_timestamp_func, func2_except,
    1165             :           DEC_ITER, DEC_ITER, DEC_VAR_R, DEC_INT,
    1166             :           INIT_ITERIN, INIT_ITERIN, INIT_VAROUT,
    1167             :           GET_NEXT_ITER, GET_NEXT_ITER,
    1168             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1169             : 
    1170             : static inline str
    1171           7 : date_to_str(str *ret, date d, str format)
    1172             : {
    1173           7 :         timestamp ts = timestamp_create(d, timestamp_daytime(timestamp_current()));
    1174           7 :         return timestamp_to_str(ret, &ts, &format, "date", "mtime.date_to_str");
    1175             : }
    1176           8 : func2(MTIMEdate_to_str, "date_to_str",
    1177             :           date, str, str, date_to_str, func2_except,
    1178             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1179             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1180             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1181             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1182             : 
    1183             : static inline str
    1184           0 : time_to_str(str *ret, daytime d, str format)
    1185             : {
    1186           0 :         timestamp ts = timestamp_create(timestamp_date(timestamp_current()), d);
    1187           0 :         return timestamp_to_str(ret, &ts, &format, "time", "mtime.time_to_str");
    1188             : }
    1189           0 : func2(MTIMEtime_to_str, "time_to_str",
    1190             :           daytime, str, str, time_to_str, func2_except,
    1191             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1192             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1193             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1194             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1195             : 
    1196             : static inline str
    1197             : timestamp_to_str_func(str *ret, timestamp d, str format)
    1198             : {
    1199           3 :         return timestamp_to_str(ret, &d, &format, "timestamp", "mtime.timestamp_to_str");
    1200             : }
    1201           5 : func2(MTIMEtimestamp_to_str, "timestamp_to_str",
    1202             :           timestamp, str, str, timestamp_to_str_func, func2_except,
    1203             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1204             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1205             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1206             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1207             : 
    1208             : #include "mel.h"
    1209             : static mel_func mtime_init_funcs[] = {
    1210             :  command("mtime", "epoch", MTIMEseconds_since_epoch, false, "unix-time (epoch) support: seconds since epoch", args(1,2, arg("",int),arg("t",timestamp))),
    1211             :  pattern("batmtime", "epoch", MTIMEseconds_since_epoch_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1212             :  pattern("batmtime", "epoch", MTIMEseconds_since_epoch_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1213             :  command("mtime", "epoch", MTIMEtimestamp_fromsecond_epoch, false, "convert seconds since epoch into a timestamp", args(1,2, arg("",timestamp),arg("t",int))),
    1214             :  pattern("batmtime", "epoch", MTIMEtimestamp_fromsecond_epoch_bulk, false, "", args(1,2, batarg("",timestamp),batarg("t",int))),
    1215             :  pattern("batmtime", "epoch", MTIMEtimestamp_fromsecond_epoch_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",int),batarg("s",oid))),
    1216             :  command("mtime", "epoch", MTIMEtimestamp_frommsec_epoch, false, "convert milli seconds since epoch into a timestamp", args(1,2, arg("",timestamp),arg("t",lng))),
    1217             :  pattern("batmtime", "epoch", MTIMEtimestamp_frommsec_epoch_bulk, false, "", args(1,2, batarg("",timestamp),batarg("t",lng))),
    1218             :  pattern("batmtime", "epoch", MTIMEtimestamp_frommsec_epoch_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",lng),batarg("s",oid))),
    1219             :  command("mtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval, false, "", args(1,3, arg("",date),arg("t",date),arg("ms",lng))),
    1220             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk, false, "", args(1,3, batarg("",date),batarg("t",date),batarg("ms",lng))),
    1221             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",date),batarg("ms",lng))),
    1222             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",date),arg("ms",lng))),
    1223             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk, false, "", args(1,5, batarg("",date),batarg("t",date),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1224             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",date),batarg("ms",lng),batarg("s",oid))),
    1225             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",date),arg("ms",lng),batarg("s",oid))),
    1226             :  command("mtime", "date_add_msec_interval", MTIMEdate_add_msec_interval, false, "", args(1,3, arg("",date),arg("t",date),arg("ms",lng))),
    1227             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk, false, "", args(1,3, batarg("",date),batarg("t",date),batarg("ms",lng))),
    1228             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",date),batarg("ms",lng))),
    1229             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",date),arg("ms",lng))),
    1230             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk, false, "", args(1,5, batarg("",date),batarg("t",date),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1231             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",date),batarg("ms",lng),batarg("s",oid))),
    1232             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",date),arg("ms",lng),batarg("s",oid))),
    1233             :  command("mtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval, false, "", args(1,3, arg("",timestamp),arg("t",timestamp),arg("ms",lng))),
    1234             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng))),
    1235             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng))),
    1236             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng))),
    1237             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1238             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng),batarg("s",oid))),
    1239             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng),batarg("s",oid))),
    1240             :  command("mtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval, false, "", args(1,3, arg("",timestamp),arg("t",timestamp),arg("ms",lng))),
    1241             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng))),
    1242             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng))),
    1243             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng))),
    1244             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1245             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng),batarg("s",oid))),
    1246             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng),batarg("s",oid))),
    1247             :  command("mtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval, false, "Subtract months from a timestamp", args(1,3, arg("",timestamp),arg("t",timestamp),arg("s",int))),
    1248             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("s",int))),
    1249             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("s",int))),
    1250             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("s",int))),
    1251             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("s",int),batarg("s1",oid),batarg("s2",oid))),
    1252             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("s",int),batarg("s",oid))),
    1253             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("s",int),batarg("s",oid))),
    1254             :  command("mtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval, false, "Add months to a timestamp", args(1,3, arg("",timestamp),arg("t",timestamp),arg("s",int))),
    1255             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("s",int))),
    1256             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("s",int))),
    1257             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("s",int))),
    1258             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("s",int),batarg("s1",oid),batarg("s2",oid))),
    1259             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("s",int),batarg("s",oid))),
    1260             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("s",int),batarg("s",oid))),
    1261             :  command("mtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval, false, "Subtract seconds from a time", args(1,3, arg("",daytime),arg("t",daytime),arg("ms",lng))),
    1262             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),batarg("ms",lng))),
    1263             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p1, false, "", args(1,3, batarg("",daytime),arg("t",daytime),batarg("ms",lng))),
    1264             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p2, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),arg("ms",lng))),
    1265             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk, false, "", args(1,5, batarg("",daytime),batarg("t",daytime),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1266             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p1, false, "", args(1,4, batarg("",daytime),arg("t",daytime),batarg("ms",lng),batarg("s",oid))),
    1267             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p2, false, "", args(1,4, batarg("",daytime),batarg("t",daytime),arg("ms",lng),batarg("s",oid))),
    1268             :  command("mtime", "time_add_msec_interval", MTIMEtime_add_msec_interval, false, "Add seconds to a time", args(1,3, arg("",daytime),arg("t",daytime),arg("ms",lng))),
    1269             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),batarg("ms",lng))),
    1270             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p1, false, "", args(1,3, batarg("",daytime),arg("t",daytime),batarg("ms",lng))),
    1271             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p2, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),arg("ms",lng))),
    1272             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk, false, "", args(1,5, batarg("",daytime),batarg("t",daytime),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1273             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p1, false, "", args(1,4, batarg("",daytime),arg("t",daytime),batarg("ms",lng),batarg("s",oid))),
    1274             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p2, false, "", args(1,4, batarg("",daytime),batarg("t",daytime),arg("ms",lng),batarg("s",oid))),
    1275             :  command("mtime", "diff", MTIMEdaytime_diff_msec, false, "returns the number of msec between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",daytime),arg("val2",daytime))),
    1276             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",daytime),batarg("val2",daytime))),
    1277             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",daytime),batarg("val2",daytime))),
    1278             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",daytime),arg("val2",daytime))),
    1279             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",daytime),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    1280             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",daytime),batarg("val2",daytime),batarg("s",oid))),
    1281             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",daytime),arg("val2",daytime),batarg("s",oid))),
    1282             :  command("mtime", "date_sub_month_interval", MTIMEdate_submonths, false, "Subtract months from a date", args(1,3, arg("",date),arg("t",date),arg("months",int))),
    1283             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk, false, "", args(1,3, batarg("",date),batarg("t",date),batarg("months",int))),
    1284             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",date),batarg("months",int))),
    1285             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",date),arg("months",int))),
    1286             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk, false, "", args(1,5, batarg("",date),batarg("t",date),batarg("months",int),batarg("s1",oid),batarg("s2",oid))),
    1287             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",date),batarg("months",int),batarg("s",oid))),
    1288             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",date),arg("months",int),batarg("s",oid))),
    1289             :  command("mtime", "local_timezone", MTIMElocal_timezone_msec, false, "get the local timezone in seconds", args(1,1, arg("",lng))),
    1290             :  command("mtime", "century", MTIMEdate_extract_century, false, "extracts century from date.", args(1,2, arg("",int),arg("d",date))),
    1291             :  pattern("batmtime", "century", MTIMEdate_extract_century_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1292             :  pattern("batmtime", "century", MTIMEdate_extract_century_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1293             :  command("mtime", "decade", MTIMEdate_extract_decade, false, "extracts decade from date.", args(1,2, arg("",int),arg("d",date))),
    1294             :  pattern("batmtime", "decade", MTIMEdate_extract_decade_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1295             :  pattern("batmtime", "decade", MTIMEdate_extract_decade_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1296             :  command("mtime", "year", MTIMEdate_extract_year, false, "extracts year from date.", args(1,2, arg("",int),arg("d",date))),
    1297             :  pattern("batmtime", "year", MTIMEdate_extract_year_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1298             :  pattern("batmtime", "year", MTIMEdate_extract_year_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1299             :  command("mtime", "quarter", MTIMEdate_extract_quarter, false, "extracts quarter from date", args(1,2, arg("",int),arg("d",date))),
    1300             :  pattern("batmtime", "quarter", MTIMEdate_extract_quarter_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1301             :  pattern("batmtime", "quarter", MTIMEdate_extract_quarter_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1302             :  command("mtime", "month", MTIMEdate_extract_month, false, "extracts month from date", args(1,2, arg("",int),arg("d",date))),
    1303             :  pattern("batmtime", "month", MTIMEdate_extract_month_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1304             :  pattern("batmtime", "month", MTIMEdate_extract_month_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1305             :  command("mtime", "day", MTIMEdate_extract_day, false, "extracts day from date ", args(1,2, arg("",int),arg("d",date))),
    1306             :  pattern("batmtime", "day", MTIMEdate_extract_day_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1307             :  pattern("batmtime", "day", MTIMEdate_extract_day_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1308             :  command("mtime", "epoch_ms", MTIMEdate_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("d",date))),
    1309             :  pattern("batmtime", "epoch_ms", MTIMEdate_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("d",date))),
    1310             :  pattern("batmtime", "epoch_ms", MTIMEdate_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("d",date),batarg("s",oid))),
    1311             :  command("mtime", "hours", MTIMEdaytime_extract_hours, false, "extracts hour from daytime", args(1,2, arg("",int),arg("h",daytime))),
    1312             :  pattern("batmtime", "hours", MTIMEdaytime_extract_hours_bulk, false, "", args(1,2, batarg("",int),batarg("d",daytime))),
    1313             :  pattern("batmtime", "hours", MTIMEdaytime_extract_hours_bulk, false, "", args(1,3, batarg("",int),batarg("d",daytime),batarg("s",oid))),
    1314             :  command("mtime", "minutes", MTIMEdaytime_extract_minutes, false, "extracts minutes from daytime", args(1,2, arg("",int),arg("d",daytime))),
    1315             :  pattern("batmtime", "minutes", MTIMEdaytime_extract_minutes_bulk, false, "", args(1,2, batarg("",int),batarg("d",daytime))),
    1316             :  pattern("batmtime", "minutes", MTIMEdaytime_extract_minutes_bulk, false, "", args(1,3, batarg("",int),batarg("d",daytime),batarg("s",oid))),
    1317             :  command("mtime", "sql_seconds", MTIMEdaytime_extract_sql_seconds, false, "extracts seconds (with fractional milliseconds) from daytime", args(1,2, arg("",int),arg("d",daytime))),
    1318             :  pattern("batmtime", "sql_seconds", MTIMEdaytime_extract_sql_seconds_bulk, false, "", args(1,2, batarg("",int),batarg("d",daytime))),
    1319             :  pattern("batmtime", "sql_seconds", MTIMEdaytime_extract_sql_seconds_bulk, false, "", args(1,3, batarg("",int),batarg("d",daytime),batarg("s",oid))),
    1320             :  command("mtime", "epoch_ms", MTIMEdaytime_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("d",daytime))),
    1321             :  pattern("batmtime", "epoch_ms", MTIMEdaytime_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("d",daytime))),
    1322             :  pattern("batmtime", "epoch_ms", MTIMEdaytime_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("d",daytime),batarg("s",oid))),
    1323             :  command("mtime", "addmonths", MTIMEdate_addmonths, false, "returns the date after a number of\nmonths (possibly negative).", args(1,3, arg("",date),arg("value",date),arg("months",int))),
    1324             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk, false, "", args(1,3, batarg("",date),batarg("value",date),batarg("months",int))),
    1325             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p1, false, "", args(1,3, batarg("",date),arg("value",date),batarg("months",int))),
    1326             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p2, false, "", args(1,3, batarg("",date),batarg("value",date),arg("months",int))),
    1327             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk, false, "", args(1,5, batarg("",date),batarg("value",date),batarg("months",int),batarg("s1",oid),batarg("s2",oid))),
    1328             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p1, false, "", args(1,4, batarg("",date),arg("value",date),batarg("months",int),batarg("s",oid))),
    1329             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p2, false, "", args(1,4, batarg("",date),batarg("value",date),arg("months",int),batarg("s",oid))),
    1330             :  command("mtime", "diff", MTIMEdate_diff, false, "returns the number of days\nbetween 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",date),arg("val2",date))),
    1331             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",date),batarg("val2",date))),
    1332             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",date),batarg("val2",date))),
    1333             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",date),arg("val2",date))),
    1334             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",date),batarg("val2",date),batarg("s1",oid),batarg("s2",oid))),
    1335             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",date),batarg("val2",date),batarg("s",oid))),
    1336             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",date),arg("val2",date),batarg("s",oid))),
    1337             :  command("mtime", "dayofyear", MTIMEdate_extract_dayofyear, false, "Returns N where d is the Nth day\nof the year (january 1 returns 1)", args(1,2, arg("",int),arg("d",date))),
    1338             :  pattern("batmtime", "dayofyear", MTIMEdate_extract_dayofyear_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1339             :  pattern("batmtime", "dayofyear", MTIMEdate_extract_dayofyear_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1340             :  command("mtime", "weekofyear", MTIMEdate_extract_weekofyear, false, "Returns the week number in the year.", args(1,2, arg("",int),arg("d",date))),
    1341             :  pattern("batmtime", "weekofyear", MTIMEdate_extract_weekofyear_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1342             :  pattern("batmtime", "weekofyear", MTIMEdate_extract_weekofyear_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1343             :  command("mtime", "usweekofyear", MTIMEdate_extract_usweekofyear, false, "Returns the week number in the year, US style.", args(1,2, arg("",int),arg("d",date))),
    1344             :  pattern("batmtime", "usweekofyear", MTIMEdate_extract_usweekofyear_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1345             :  pattern("batmtime", "usweekofyear", MTIMEdate_extract_usweekofyear_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1346             :  command("mtime", "dayofweek", MTIMEdate_extract_dayofweek, false, "Returns the current day of the week\nwhere 1=monday, .., 7=sunday", args(1,2, arg("",int),arg("d",date))),
    1347             :  pattern("batmtime", "dayofweek", MTIMEdate_extract_dayofweek_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1348             :  pattern("batmtime", "dayofweek", MTIMEdate_extract_dayofweek_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1349             :  command("mtime", "diff", MTIMEtimestamp_diff_msec, false, "returns the number of milliseconds\nbetween 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",timestamp))),
    1350             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp))),
    1351             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp))),
    1352             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp))),
    1353             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1354             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    1355             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    1356             :  command("mtime", "str_to_date", MTIMEstr_to_date, false, "create a date from the string, using the specified format (see man strptime)", args(1,3, arg("",date),arg("s",str),arg("format",str))),
    1357             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk, false, "", args(1,3, batarg("",date),batarg("s",str),batarg("format",str))),
    1358             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p1, false, "", args(1,3, batarg("",date),arg("s",str),batarg("format",str))),
    1359             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p2, false, "", args(1,3, batarg("",date),batarg("s",str),arg("format",str))),
    1360             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk, false, "", args(1,5, batarg("",date),batarg("s",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1361             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p1, false, "", args(1,4, batarg("",date),arg("s",str),batarg("format",str),batarg("s",oid))),
    1362             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p2, false, "", args(1,4, batarg("",date),batarg("s",str),arg("format",str),batarg("s",oid))),
    1363             :  command("mtime", "date_to_str", MTIMEdate_to_str, false, "create a string from the date, using the specified format (see man strftime)", args(1,3, arg("",str),arg("d",date),arg("format",str))),
    1364             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk, false, "", args(1,3, batarg("",str),batarg("d",str),batarg("format",str))),
    1365             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p1, false, "", args(1,3, batarg("",str),arg("d",date),batarg("format",str))),
    1366             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p2, false, "", args(1,3, batarg("",str),batarg("d",date),arg("format",str))),
    1367             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk, false, "", args(1,5, batarg("",str),batarg("d",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1368             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",date),batarg("format",str),batarg("s",oid))),
    1369             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",date),arg("format",str),batarg("s",oid))),
    1370             :  command("mtime", "str_to_time", MTIMEstr_to_time, false, "create a time from the string, using the specified format (see man strptime)", args(1,3, arg("",daytime),arg("s",str),arg("format",str))),
    1371             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk, false, "", args(1,3, batarg("",daytime),batarg("s",str),batarg("format",str))),
    1372             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p1, false, "", args(1,3, batarg("",daytime),arg("s",str),batarg("format",str))),
    1373             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p2, false, "", args(1,3, batarg("",daytime),batarg("s",str),arg("format",str))),
    1374             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk, false, "", args(1,5, batarg("",daytime),batarg("s",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1375             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p1, false, "", args(1,4, batarg("",daytime),arg("s",str),batarg("format",str),batarg("s",oid))),
    1376             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p2, false, "", args(1,4, batarg("",daytime),batarg("s",str),arg("format",str),batarg("s",oid))),
    1377             :  command("mtime", "time_to_str", MTIMEtime_to_str, false, "create a string from the time, using the specified format (see man strftime)", args(1,3, arg("",str),arg("d",daytime),arg("format",str))),
    1378             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk, false, "", args(1,3, batarg("",str),batarg("d",daytime),batarg("format",str))),
    1379             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p1, false, "", args(1,3, batarg("",str),arg("d",daytime),batarg("format",str))),
    1380             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p2, false, "", args(1,3, batarg("",str),batarg("d",daytime),arg("format",str))),
    1381             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk, false, "", args(1,5, batarg("",str),batarg("d",daytime),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1382             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",daytime),batarg("format",str),batarg("s",oid))),
    1383             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",daytime),arg("format",str),batarg("s",oid))),
    1384             :  command("mtime", "str_to_timestamp", MTIMEstr_to_timestamp, false, "create a timestamp from the string, using the specified format (see man strptime)", args(1,3, arg("",timestamp),arg("s",str),arg("format",str))),
    1385             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk, false, "", args(1,3, batarg("",timestamp),batarg("d",str),batarg("format",str))),
    1386             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("s",str),batarg("format",str))),
    1387             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("s",str),arg("format",str))),
    1388             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk, false, "", args(1,5, batarg("",timestamp),batarg("d",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1389             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("s",str),batarg("format",str),batarg("s",oid))),
    1390             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("s",str),arg("format",str),batarg("s",oid))),
    1391             :  command("mtime", "timestamp_to_str", MTIMEtimestamp_to_str, false, "create a string from the time, using the specified format (see man strftime)", args(1,3, arg("",str),arg("d",timestamp),arg("format",str))),
    1392             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk, false, "", args(1,3, batarg("",str),batarg("d",timestamp),batarg("format",str))),
    1393             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p1, false, "", args(1,3, batarg("",str),arg("d",timestamp),batarg("format",str))),
    1394             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p2, false, "", args(1,3, batarg("",str),batarg("d",timestamp),arg("format",str))),
    1395             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk, false, "", args(1,5, batarg("",str),batarg("d",timestamp),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1396             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",timestamp),batarg("format",str),batarg("s",oid))),
    1397             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",timestamp),arg("format",str),batarg("s",oid))),
    1398             :  command("mtime", "current_timestamp", MTIMEcurrent_timestamp, false, "", args(1,1, arg("",timestamp))),
    1399             :  command("mtime", "current_date", MTIMEcurrent_date, false, "", args(1,1, arg("",date))),
    1400             :  command("mtime", "current_time", MTIMEcurrent_time, false, "", args(1,1, arg("",daytime))),
    1401             :  command("mtime", "century", MTIMEtimestamp_century, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1402             :  pattern("batmtime", "century", MTIMEtimestamp_century_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1403             :  pattern("batmtime", "century", MTIMEtimestamp_century_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1404             :  command("mtime", "decade", MTIMEtimestamp_decade, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1405             :  pattern("batmtime", "decade", MTIMEtimestamp_decade_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1406             :  pattern("batmtime", "decade", MTIMEtimestamp_decade_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1407             :  command("mtime", "year", MTIMEtimestamp_year, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1408             :  pattern("batmtime", "year", MTIMEtimestamp_year_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1409             :  pattern("batmtime", "year", MTIMEtimestamp_year_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1410             :  command("mtime", "quarter", MTIMEtimestamp_quarter, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1411             :  pattern("batmtime", "quarter", MTIMEtimestamp_quarter_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1412             :  pattern("batmtime", "quarter", MTIMEtimestamp_quarter_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1413             :  command("mtime", "month", MTIMEtimestamp_month, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1414             :  pattern("batmtime", "month", MTIMEtimestamp_month_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1415             :  pattern("batmtime", "month", MTIMEtimestamp_month_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1416             :  command("mtime", "day", MTIMEtimestamp_day, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1417             :  pattern("batmtime", "day", MTIMEtimestamp_day_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1418             :  pattern("batmtime", "day", MTIMEtimestamp_day_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1419             :  command("mtime", "hours", MTIMEtimestamp_hours, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1420             :  pattern("batmtime", "hours", MTIMEtimestamp_hours_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1421             :  pattern("batmtime", "hours", MTIMEtimestamp_hours_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1422             :  command("mtime", "minutes", MTIMEtimestamp_minutes, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1423             :  pattern("batmtime", "minutes", MTIMEtimestamp_minutes_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1424             :  pattern("batmtime", "minutes", MTIMEtimestamp_minutes_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1425             :  command("mtime", "sql_seconds", MTIMEtimestamp_sql_seconds, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1426             :  pattern("batmtime", "sql_seconds", MTIMEtimestamp_sql_seconds_bulk, false, "", args(1,2, batarg("",int),batarg("d",timestamp))),
    1427             :  pattern("batmtime", "sql_seconds", MTIMEtimestamp_sql_seconds_bulk, false, "", args(1,3, batarg("",int),batarg("d",timestamp),batarg("s",oid))),
    1428             :  command("mtime", "epoch_ms", MTIMEtimestamp_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("t",timestamp))),
    1429             :  pattern("batmtime", "epoch_ms", MTIMEtimestamp_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("t",timestamp))),
    1430             :  pattern("batmtime", "epoch_ms", MTIMEtimestamp_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("t",timestamp),batarg("s",oid))),
    1431             :  command("mtime", "year", MTIMEsql_year, false, "", args(1,2, arg("",int),arg("months",int))),
    1432             :  pattern("batmtime", "year", MTIMEsql_year_bulk, false, "", args(1,2, batarg("",int),batarg("months",int))),
    1433             :  pattern("batmtime", "year", MTIMEsql_year_bulk, false, "", args(1,3, batarg("",int),batarg("months",int),batarg("s",oid))),
    1434             :  command("mtime", "month", MTIMEsql_month, false, "", args(1,2, arg("",int),arg("months",int))),
    1435             :  pattern("batmtime", "month", MTIMEsql_month_bulk, false, "", args(1,2, batarg("",int),batarg("months",int))),
    1436             :  pattern("batmtime", "month", MTIMEsql_month_bulk, false, "", args(1,3, batarg("",int),batarg("months",int),batarg("s",oid))),
    1437             :  command("mtime", "day", MTIMEsql_day, false, "", args(1,2, arg("",lng),arg("msecs",lng))),
    1438             :  pattern("batmtime", "day", MTIMEsql_day_bulk, false, "", args(1,2, batarg("",lng),batarg("msecs",lng))),
    1439             :  pattern("batmtime", "day", MTIMEsql_day_bulk, false, "", args(1,3, batarg("",lng),batarg("msecs",lng),batarg("s",oid))),
    1440             :  command("mtime", "hours", MTIMEsql_hours, false, "", args(1,2, arg("",int),arg("msecs",lng))),
    1441             :  pattern("batmtime", "hours", MTIMEsql_hours_bulk, false, "", args(1,2, batarg("",int),batarg("msecs",lng))),
    1442             :  pattern("batmtime", "hours", MTIMEsql_hours_bulk, false, "", args(1,3, batarg("",int),batarg("msecs",lng),batarg("s",oid))),
    1443             :  command("mtime", "minutes", MTIMEsql_minutes, false, "", args(1,2, arg("",int),arg("msecs",lng))),
    1444             :  pattern("batmtime", "minutes", MTIMEsql_minutes_bulk, false, "", args(1,2, batarg("",int),batarg("msecs",lng))),
    1445             :  pattern("batmtime", "minutes", MTIMEsql_minutes_bulk, false, "", args(1,3, batarg("",int),batarg("msecs",lng),batarg("s",oid))),
    1446             :  command("mtime", "seconds", MTIMEsql_seconds, false, "", args(1,2, arg("",int),arg("msecs",lng))),
    1447             :  pattern("batmtime", "seconds", MTIMEsql_seconds_bulk, false, "", args(1,2, batarg("",int),batarg("msecs",lng))),
    1448             :  pattern("batmtime", "seconds", MTIMEsql_seconds_bulk, false, "", args(1,3, batarg("",int),batarg("msecs",lng),batarg("s",oid))),
    1449             :  command("mtime", "epoch_ms", MTIMEmsec_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("msecs",lng))),
    1450             :  pattern("batmtime", "epoch_ms", MTIMEmsec_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("msecs",lng))),
    1451             :  pattern("batmtime", "epoch_ms", MTIMEmsec_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("msecs",lng),batarg("s",oid))),
    1452             :  command("calc", "date", MTIMEdate_fromstr, false, "", args(1,2, arg("",date),arg("s",str))),
    1453             :  command("calc", "date", MTIMEdate_date, false, "", args(1,2, arg("",date),arg("d",date))),
    1454             :  command("calc", "date", MTIMEtimestamp_extract_date, false, "", args(1,2, arg("",date),arg("t",timestamp))),
    1455             :  command("calc", "timestamp", MTIMEtimestamp_fromstr, false, "", args(1,2, arg("",timestamp),arg("s",str))),
    1456             :  command("calc", "timestamp", MTIMEtimestamp_timestamp, false, "", args(1,2, arg("",timestamp),arg("t",timestamp))),
    1457             :  command("calc", "timestamp", MTIMEtimestamp_fromdate, false, "", args(1,2, arg("",timestamp),arg("d",date))),
    1458             :  command("calc", "timestamp", MTIMEtimestamp_fromsecond, false, "", args(1,2, arg("",timestamp),arg("secs",int))),
    1459             :  command("calc", "timestamp", MTIMEtimestamp_frommsec, false, "", args(1,2, arg("",timestamp),arg("msecs",lng))),
    1460             :  command("calc", "daytime", MTIMEdaytime_fromstr, false, "", args(1,2, arg("",daytime),arg("s",str))),
    1461             :  command("calc", "daytime", MTIMEdaytime_daytime, false, "", args(1,2, arg("",daytime),arg("d",daytime))),
    1462             :  command("calc", "daytime", MTIMEdaytime_fromseconds, false, "", args(1,2, arg("",daytime),arg("s",lng))),
    1463             :  command("calc", "daytime", MTIMEtimestamp_extract_daytime, false, "", args(1,2, arg("",daytime),arg("t",timestamp))),
    1464             :  pattern("batcalc", "date", MTIMEdate_fromstr_bulk, false, "", args(1,3, batarg("",date),batarg("s",str),batarg("s",oid))),
    1465             :  pattern("batcalc", "date", MTIMEdate_date_bulk, false, "", args(1,3, batarg("",date),batarg("d",date),batarg("s",oid))),
    1466             :  pattern("batcalc", "date", MTIMEtimestamp_extract_date_bulk, false, "", args(1,3, batarg("",date),batarg("t",timestamp),batarg("s",oid))),
    1467             :  pattern("batcalc", "timestamp", MTIMEtimestamp_fromstr_bulk, false, "", args(1,3, batarg("",timestamp),batarg("s",str),batarg("s",oid))),
    1468             :  pattern("batcalc", "timestamp", MTIMEtimestamp_timestamp_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("s",oid))),
    1469             :  pattern("batcalc", "timestamp", MTIMEtimestamp_fromdate_bulk, false, "", args(1,3, batarg("",timestamp),batarg("d",date),batarg("s",oid))),
    1470             :  pattern("batcalc", "timestamp", MTIMEtimestamp_fromsecond_bulk, false, "", args(1,3, batarg("",timestamp),batarg("secs",int),batarg("s",oid))),
    1471             :  pattern("batcalc", "timestamp", MTIMEtimestamp_frommsec_bulk, false, "", args(1,3, batarg("",timestamp),batarg("msecs",lng),batarg("s",oid))),
    1472             :  pattern("batcalc", "daytime", MTIMEdaytime_fromstr_bulk, false, "", args(1,3, batarg("",daytime),batarg("s",str),batarg("s",oid))),
    1473             :  pattern("batcalc", "daytime", MTIMEdaytime_daytime_bulk, false, "", args(1,3, batarg("",daytime),batarg("d",daytime),batarg("s",oid))),
    1474             :  pattern("batcalc", "daytime", MTIMEdaytime_fromseconds_bulk, false, "", args(1,3, batarg("",daytime),batarg("s",lng),batarg("s",oid))),
    1475             :  pattern("batcalc", "daytime", MTIMEtimestamp_extract_daytime_bulk, false, "", args(1,3, batarg("",daytime),batarg("t",timestamp),batarg("s",oid))),
    1476             :  { .imp=NULL }
    1477             : };
    1478             : #include "mal_import.h"
    1479             : #ifdef _MSC_VER
    1480             : #undef read
    1481             : #pragma section(".CRT$XCU",read)
    1482             : #endif
    1483         259 : LIB_STARTUP_FUNC(init_mtime_mal)
    1484         259 : { mal_module("mtime", NULL, mtime_init_funcs); }

Generated by: LCOV version 1.14