本文整理汇总了C++中VAL_TIME函数的典型用法代码示例。如果您正苦于以下问题:C++ VAL_TIME函数的具体用法?C++ VAL_TIME怎么用?C++ VAL_TIME使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VAL_TIME函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VAL_TIME
*/ void Adjust_Date_Zone(REBVAL *d, REBFLG to_utc)
/*
** Adjust date and time for the timezone.
** The result should be used for output, not stored.
**
***********************************************************************/
{
REBI64 secs;
REBCNT n;
if (VAL_ZONE(d) == 0) return;
if (VAL_TIME(d) == NO_TIME) {
VAL_TIME(d) = VAL_ZONE(d) = 0;
return;
}
// (compiler should fold the constant)
secs = ((i64)VAL_ZONE(d) * ((i64)ZONE_SECS * SEC_SEC));
if (to_utc) secs = -secs;
secs += VAL_TIME(d);
VAL_TIME(d) = (secs + TIME_IN_DAY) % TIME_IN_DAY;
n = VAL_DAY(d) - 1;
if (secs < 0) n--;
else if (secs >= TIME_IN_DAY) n++;
else return;
VAL_DATE(d) = Normalize_Date(n, VAL_MONTH(d)-1, VAL_YEAR(d), VAL_ZONE(d));
}
示例2: if
//
// Scan_Time: C
//
// Scan string and convert to time. Return zero if error.
//
const REBYTE *Scan_Time(const REBYTE *cp, REBCNT len, REBVAL *value)
{
const REBYTE *sp;
REBYTE merid = FALSE;
REBOOL neg = FALSE;
REBINT part1, part2, part3 = -1;
REBINT part4 = -1;
if (*cp == '-') cp++, neg = TRUE;
else if (*cp == '+') cp++;
if (*cp == '-' || *cp == '+') return 0; // small hole: --1:23
// Can be:
// HH:MM as part1:part2
// HH:MM:SS as part1:part2:part3
// HH:MM:SS.DD as part1:part2:part3.part4
// MM:SS.DD as part1:part2.part4
cp = Grab_Int(cp, &part1);
if (part1 > MAX_HOUR) return 0;
if (*cp++ != ':') return 0;
sp = Grab_Int(cp, &part2);
if (part2 < 0 || sp == cp) return 0;
cp = sp;
if (*cp == ':') { // optional seconds
sp = cp + 1;
cp = Grab_Int(sp, &part3);
if (part3 < 0 || cp == sp) return 0; //part3 = -1;
}
if (*cp == '.' || *cp == ',') {
sp = ++cp;
cp = Grab_Int_Scale(sp, &part4, 9);
if (part4 == 0) part4 = -1;
}
if ((UP_CASE(*cp) == 'A' || UP_CASE(*cp) == 'P') && (UP_CASE(cp[1]) == 'M')) {
merid = (REBYTE)UP_CASE(*cp);
cp += 2;
}
if (part3 >= 0 || part4 < 0) { // HH:MM mode
if (merid) {
if (part1 > 12) return 0;
if (part1 == 12) part1 = 0;
if (merid == 'P') part1 += 12;
}
if (part3 < 0) part3 = 0;
VAL_TIME(value) = HOUR_TIME(part1) + MIN_TIME(part2) + SEC_TIME(part3);
} else { // MM:SS mode
if (merid) return 0; // no AM/PM for minutes
VAL_TIME(value) = MIN_TIME(part1) + SEC_TIME(part2);
}
if (part4 > 0) VAL_TIME(value) += part4;
if (neg) VAL_TIME(value) = -VAL_TIME(value);
VAL_SET(value, REB_TIME);
return cp;
}
示例3: Cmp_Time
//
// Cmp_Time: C
//
// Given two times, compare them.
//
REBINT Cmp_Time(const REBVAL *v1, const REBVAL *v2)
{
REBI64 t1 = VAL_TIME(v1);
REBI64 t2 = VAL_TIME(v2);
if (t1 == NO_TIME) t1 = 0L;
if (t2 == NO_TIME) t2 = 0L;
if (t2 == t1) return 0;
if (t1 > t2) return 1;
return -1;
}
示例4: Cmp_Date
*/ REBINT CT_Date(REBVAL *a, REBVAL *b, REBINT mode)
/*
***********************************************************************/
{
REBINT num = Cmp_Date(a, b);
if (mode >= 2)
return VAL_DATE(a).bits == VAL_DATE(b).bits && VAL_TIME(a) == VAL_TIME(b);
if (mode >= 0) return (num == 0);
if (mode == -1) return (num >= 0);
return (num > 0);
}
示例5: bdb_ufield_db2bdb
int bdb_ufield_db2bdb(bdb_uval_p v, db_val_t* _v)
{
char *s;
VAL_NULL(&(v->v)) = VAL_NULL(_v);
VAL_TYPE(&(v->v)) = VAL_TYPE(_v);
if (!VAL_NULL(&(v->v))) {
switch (VAL_TYPE(_v)) {
case DB_INT:
VAL_INT(&(v->v)) = VAL_INT(_v);
break;
case DB_FLOAT:
VAL_FLOAT(&(v->v)) = VAL_FLOAT(_v);
break;
case DB_DATETIME:
VAL_TIME(&(v->v)) = VAL_TIME(_v);
break;
case DB_BLOB:
s = pkg_malloc(VAL_BLOB(_v).len);
memcpy(s, VAL_BLOB(_v).s, VAL_BLOB(_v).len);
VAL_BLOB(&(v->v)).s = s;
VAL_BLOB(&(v->v)).len = VAL_BLOB(_v).len;
break;
case DB_DOUBLE:
VAL_DOUBLE(&(v->v)) = VAL_DOUBLE(_v);
break;
case DB_STRING:
VAL_STR(&(v->v)).len = strlen(VAL_STRING(_v)) + 1;
s = pkg_malloc(VAL_STR(&(v->v)).len);
strcpy(s, VAL_STRING(_v));
VAL_STRING(&(v->v)) = s;
break;
case DB_STR:
s = pkg_malloc(VAL_STR(_v).len);
memcpy(s, VAL_STR(_v).s, VAL_STR(_v).len);
VAL_STR(&(v->v)).s = s;
VAL_STR(&(v->v)).len = VAL_STR(_v).len;
break;
case DB_BITMAP:
VAL_BITMAP(&(v->v)) = VAL_BITMAP(_v);
break;
default:
LOG(L_ERR, "BDB:bdb_ufield_db2bdb: unknown column type: %0X\n", VAL_TYPE(_v));
return -1;
break;
}
}
return 0;
};
示例6: bdb_set_key
int bdb_set_key(bdb_row_p _r, bdb_val_p _v)
{
/* NULL is not allowed for primary key */
if (VAL_NULL(&(_v->v))) {
LOG(L_ERR, "BDB:bdb_set_key: NULL is not allowed for primary key\n");
return -1;
}
switch (VAL_TYPE(&(_v->v))) {
case DB_INT:
_r->key.data = &VAL_INT(&(_v->v));
_r->key.size = sizeof(VAL_INT(&(_v->v)));
break;
case DB_FLOAT:
_r->key.data = &VAL_FLOAT(&(_v->v));
_r->key.size = sizeof(VAL_FLOAT(&(_v->v)));
break;
case DB_DATETIME:
_r->key.data = &VAL_TIME(&(_v->v));
_r->key.size = sizeof(VAL_TIME(&(_v->v)));
break;
case DB_BLOB:
_r->key.data = VAL_BLOB(&(_v->v)).s;
_r->key.size = VAL_BLOB(&(_v->v)).len;
break;
case DB_DOUBLE:
_r->key.data = &VAL_DOUBLE(&(_v->v));
_r->key.size = sizeof(VAL_DOUBLE(&(_v->v)));
break;
case DB_STRING:
_r->key.data = (void *)VAL_STRING(&(_v->v));
_r->key.size = strlen(VAL_STRING(&(_v->v))) + 1;
break;
case DB_STR:
_r->key.data = VAL_STR(&(_v->v)).s;
_r->key.size = VAL_STR(&(_v->v)).len;
break;
case DB_BITMAP:
_r->key.data = &VAL_BITMAP(&(_v->v));
_r->key.size = sizeof(VAL_BITMAP(&(_v->v)));
break;
default:
LOG(L_ERR, "BDB:bdb_set_skey: unknown column type: %0X\n", VAL_TYPE(&(_v->v)));
return -1;
break;
}
return 0;
};
示例7: VAL_TIME
*/ REBINT Cmp_Time(const REBVAL *v1, const REBVAL *v2)
/*
** Given two times, compare them.
**
***********************************************************************/
{
REBI64 t1 = VAL_TIME(v1);
REBI64 t2 = VAL_TIME(v2);
if (t1 == NO_TIME) t1 = 0L;
if (t2 == NO_TIME) t2 = 0L;
if (t2 == t1) return 0;
if (t1 > t2) return 1;
return -1;
}
示例8: bdb_set_skey
void bdb_set_skey(bdb_srow_p _r, bdb_sval_p _v)
{
/* NULL is not allowed for primary key */
if (VAL_NULL(&(_v->v)))
return;
switch (VAL_TYPE(&(_v->v))) {
case DB_INT:
_r->key.data = &VAL_INT(&(_v->v));
_r->key.size = sizeof(VAL_INT(&(_v->v)));
break;
case DB_FLOAT:
_r->key.data = &VAL_FLOAT(&(_v->v));
_r->key.size = sizeof(VAL_FLOAT(&(_v->v)));
break;
case DB_DATETIME:
_r->key.data = &VAL_TIME(&(_v->v));
_r->key.size = sizeof(VAL_TIME(&(_v->v)));
break;
case DB_BLOB:
_r->key.data = VAL_BLOB(&(_v->v)).s;
_r->key.size = VAL_BLOB(&(_v->v)).len;
break;
case DB_DOUBLE:
_r->key.data = &VAL_DOUBLE(&(_v->v));
_r->key.size = sizeof(VAL_DOUBLE(&(_v->v)));
break;
case DB_STRING:
_r->key.data = (void *)VAL_STRING(&(_v->v));
_r->key.size = strlen(VAL_STRING(&(_v->v))) + 1;
break;
case DB_STR:
_r->key.data = VAL_STR(&(_v->v)).s;
_r->key.size = VAL_STR(&(_v->v)).len;
break;
case DB_BITMAP:
_r->key.data = &VAL_BITMAP(&(_v->v));
_r->key.size = sizeof(VAL_BITMAP(&(_v->v)));
break;
default:
LOG(L_ERR, "BDB:bdb_set_skey: unknown column type: %0X\n", VAL_TYPE(&(_v->v)));
break;
}
#ifdef BDB_EXTRA_DEBUG
LOG(L_NOTICE, "BDB:bdb_set_skey: use key '%.*s' (%d bytes)\n", _r->key.size, (char *)_r->key.data, _r->key.size);
#endif
};
示例9: Split_Time
*/ void Emit_Time(REB_MOLD *mold, const REBVAL *value)
/*
***********************************************************************/
{
REB_TIMEF tf;
const char *fmt;
Split_Time(VAL_TIME(value), &tf); // loses sign
if (tf.s == 0 && tf.n == 0) fmt = "I:2";
else fmt = "I:2:2";
if (VAL_TIME(value) < (REBI64)0) Append_Byte(mold->series, '-');
Emit(mold, fmt, tf.h, tf.m, tf.s, 0);
if (tf.n > 0) Emit(mold, ".i", tf.n);
}
示例10: Emit_Time
//
// Emit_Time: C
//
void Emit_Time(REB_MOLD *mold, const REBVAL *value)
{
REB_TIMEF tf;
const char *fmt;
Split_Time(VAL_TIME(value), &tf); // loses sign
if (tf.s == 0 && tf.n == 0) fmt = "I:2";
else fmt = "I:2:2";
if (VAL_TIME(value) < cast(REBI64, 0))
Append_Codepoint_Raw(mold->series, '-');
Emit(mold, fmt, tf.h, tf.m, tf.s, 0);
if (tf.n > 0) Emit(mold, ".i", tf.n);
}
示例11: db_sqlite_bind_values
static int db_sqlite_bind_values(sqlite3_stmt* stmt, const db_val_t* v, const int n)
{
int i, ret;
if (n>0 && v) {
for (i=0; i<n; i++) {
if (VAL_NULL(v+i)) {
ret=sqlite3_bind_null(stmt, i+1);
goto check_ret;
}
switch(VAL_TYPE(v+i)) {
/* every param has '+1' index because in sqlite the leftmost
* parameter has index '1' */
case DB_INT:
ret=sqlite3_bind_int(stmt, i+1, VAL_INT(v+i));
break;
case DB_BIGINT:
ret=sqlite3_bind_int64(stmt, i+1, VAL_BIGINT(v+i));
break;
case DB_DOUBLE:
ret=sqlite3_bind_double(stmt, i+1, VAL_DOUBLE(v+i));
break;
case DB_STRING:
ret=sqlite3_bind_text(stmt, i+1, VAL_STRING(v+i),
strlen(VAL_STRING(v+i)), SQLITE_STATIC);
break;
case DB_STR:
ret=sqlite3_bind_text(stmt, i+1, VAL_STR(v+i).s,
VAL_STR(v+i).len, SQLITE_STATIC);
break;
case DB_DATETIME:
ret=sqlite3_bind_int64(stmt, i+1, (long int)VAL_TIME(v+i));
break;
case DB_BLOB:
ret=sqlite3_bind_blob(stmt, i+1, (void*)VAL_BLOB(v+i).s,
VAL_BLOB(v+i).len, SQLITE_STATIC);
break;
case DB_BITMAP:
ret=sqlite3_bind_int(stmt, i+1, (int)VAL_BITMAP(v+i));
break;
default:
LM_BUG("invalid db type\n");
return 1;
}
check_ret:
if (ret != SQLITE_OK) {
return ret;
}
}
}
return SQLITE_OK;
}
示例12: MT_Time
//
// MT_Time: C
//
REBFLG MT_Time(REBVAL *out, REBVAL *data, enum Reb_Kind type)
{
REBI64 secs = Make_Time(data);
if (secs == NO_TIME) return FALSE;
VAL_SET(out, REB_TIME);
VAL_TIME(out) = secs;
VAL_DATE(out).bits = 0;
return TRUE;
}
示例13: switch
inline SV *valdata(db_val_t* val) {
SV *data = &PL_sv_undef;
const char* stringval;
switch(VAL_TYPE(val)) {
case DB1_INT:
data = newSViv(VAL_INT(val));
break;
case DB1_BIGINT:
LM_ERR("BIGINT not supported");
data = &PL_sv_undef;
break;
case DB1_DOUBLE:
data = newSVnv(VAL_DOUBLE(val));
break;
case DB1_STRING:
stringval = VAL_STRING(val);
if (strlen(stringval) > 0)
data = newSVpv(stringval, strlen(stringval));
else
data = &PL_sv_undef;
break;
case DB1_STR:
if (VAL_STR(val).len > 0)
data = newSVpv(VAL_STR(val).s, VAL_STR(val).len);
else
data = &PL_sv_undef;
break;
case DB1_DATETIME:
data = newSViv((unsigned int)VAL_TIME(val));
break;
case DB1_BLOB:
if (VAL_BLOB(val).len > 0)
data = newSVpv(VAL_BLOB(val).s,
VAL_BLOB(val).len);
else
data = &PL_sv_undef;
break;
case DB1_BITMAP:
data = newSViv(VAL_BITMAP(val));
break;
}
return data;
}
示例14: Diff_Date
*/ void Subtract_Date(REBVAL *d1, REBVAL *d2, REBVAL *result)
/*
** Called by DIFFERENCE function.
**
***********************************************************************/
{
REBINT diff;
REBI64 t1;
REBI64 t2;
diff = Diff_Date(VAL_DATE(d1), VAL_DATE(d2));
if (cast(REBCNT, abs(diff)) > (((1U << 31) - 1) / SECS_IN_DAY))
Trap(RE_OVERFLOW);
t1 = VAL_TIME(d1);
if (t1 == NO_TIME) t1 = 0L;
t2 = VAL_TIME(d2);
if (t2 == NO_TIME) t2 = 0L;
VAL_SET(result, REB_TIME);
VAL_TIME(result) = (t1 - t2) + ((REBI64)diff * TIME_IN_DAY);
}
示例15: Make_Time
*/ REBFLG MT_Time(REBVAL *out, REBVAL *data, REBCNT type)
/*
***********************************************************************/
{
REBI64 secs = Make_Time(data);
if (secs == NO_TIME) return FALSE;
VAL_SET(out, REB_TIME);
VAL_TIME(out) = secs;
VAL_DATE(out).bits = 0;
return TRUE;
}