/** Explode time to human readable form. */ log4cxx_status_t explode( apr_time_exp_t * result, log4cxx_time_t input ) const { apr_status_t stat; // APR 1.1 and early mishandles microseconds on dates // before 1970, APR bug 32520 if (LOG4CXX_UNLIKELY(input < 0 && apr_time_usec(input) < 0)) { apr_time_t floorTime = (apr_time_sec(input) -1) * APR_USEC_PER_SEC; stat = apr_time_exp_tz(result, floorTime, offset); result->tm_usec = (int) (input - floorTime); } else { stat = apr_time_exp_tz( result, input, offset ); } return stat; }
int lua_apr_time_explode(lua_State *L) { apr_time_exp_t components; apr_status_t status; apr_time_t time; char *field; int i; time = time_check(L, 1); if (!lua_toboolean(L, 2)) /* Explode the time according to the local timezone by default. */ status = apr_time_exp_lt(&components, time); else /* Or explode the time according to (an offset from) GMT instead. */ status = apr_time_exp_tz(&components, time, lua_isboolean(L, 2) ? 0 : (apr_int32_t) luaL_checkinteger(L, 2)); if (status != APR_SUCCESS) return push_error_status(L, status); /* Copy numeric fields of exploded time to Lua table. */ lua_createtable(L, 0, count(fields) + 1); for (i = 0; i < count(fields); i++) { field = (char*)&components + fields[i].byte_offset; lua_pushinteger(L, *(apr_int32_t*)field + fields[i].value_offset); lua_setfield(L, -2, fields[i].name); } /* Copy boolean `isdst' field. */ lua_pushboolean(L, components.tm_isdst); lua_setfield(L, -2, "isdst"); return 1; }
APR_DECLARE(apr_status_t) apr_time_exp_lt(apr_time_exp_t *result, apr_time_t input) { #if defined(__EMX__) /* EMX gcc (OS/2) has a timezone global we can use */ return apr_time_exp_tz(result, input, -timezone); #else explode_time(result, input, 0, 1); return APR_SUCCESS; #endif /* __EMX__ */ }
static void test_strftimeoffset(CuTest *tc) { apr_status_t rv; apr_time_exp_t xt; char str[STR_SIZE]; apr_size_t sz; apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */ apr_time_exp_tz(&xt, now, hr_off); rv = apr_strftime(str, &sz, STR_SIZE, "%T", &xt); if (rv == APR_ENOTIMPL) { CuNotImpl(tc, "apr_strftime"); } CuAssertTrue(tc, rv == APR_SUCCESS); }
static void badge_emit_timestamp(request_rec * r, const char * fromto, time_t value, int rdonly, badge_timestamp * ts, int errflags, int yearerr, int montherr, int dayerr, int hourerr, int minerr, int secerr) { apr_time_exp_t exptime; apr_time_t aprtime; apr_size_t len; char buf[100]; /** *** Emit a timestamp in an html table row, either as normal text *** from `value' or as input fields with values from `*ts' *** according to the `rdonly' flag. **/ ap_rvputs(r, "<tr><td>Valid ", fromto, "</td><td>", NULL); if (rdonly) { apr_time_ansi_put(&aprtime, value); apr_time_exp_tz(&exptime, aprtime, 0); apr_strftime(buf, &len, sizeof buf - 1, "%c", &exptime); buf[len] = '\0'; ap_rvputs(r, ap_escape_html(r->pool, buf), NULL); } else { ap_rvputs(r, "Y<input type=\"text\" name=\"", fromto, "-year\" value=\"", ts->year? ap_escape_html(r->pool, ts->year): "", "\"", badge_arg_err(errflags & yearerr), " />", NULL); badge_emit_range_select(r, "M", fromto, "month", 1, 12, ts->month, errflags & montherr); badge_emit_range_select(r, "D", fromto, "day", 1, 31, ts->day, errflags & dayerr); badge_emit_range_select(r, "H", fromto, "hour", 0, 23, ts->hour, errflags & hourerr); badge_emit_range_select(r, "M", fromto, "min", 0, 59, ts->min, errflags & minerr); badge_emit_range_select(r, "S", fromto, "sec", 0, 59, ts->sec, errflags & secerr); } ap_rvputs(r, "</td></tr>\n", NULL); }
static void test_exp_tz(CuTest *tc) { apr_status_t rv; apr_time_exp_t xt; apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */ rv = apr_time_exp_tz(&xt, now, hr_off); if (rv == APR_ENOTIMPL) { CuNotImpl(tc, "apr_time_exp_tz"); } CuAssertTrue(tc, rv == APR_SUCCESS); CuAssertTrue(tc, (xt.tm_usec == 186711) && (xt.tm_sec == 36) && (xt.tm_min == 5) && (xt.tm_hour == 14) && (xt.tm_mday == 14) && (xt.tm_mon == 8) && (xt.tm_year == 102) && (xt.tm_wday == 6) && (xt.tm_yday == 256)); }
SWITCH_DECLARE(switch_status_t) switch_time_exp_tz(switch_time_exp_t *result, switch_time_t input, switch_int32_t offs) { return apr_time_exp_tz((apr_time_exp_t *) result, input, (apr_int32_t) offs); }
APR_DECLARE(apr_status_t) apr_time_exp_gmt(apr_time_exp_t *result, apr_time_t input) { return apr_time_exp_tz(result, input, 0); }
/* Deprecated */ APR_DECLARE(apr_status_t) apr_explode_time(apr_time_exp_t *result, apr_time_t input, apr_int32_t offs) { return apr_time_exp_tz(result, input, offs); }