Skip to content

Commit 5f6e740

Browse files
spacewanderagentzh
authored andcommitted
feature: added pure C APIs for the remaining time related Lua APIs (for lua-resyt-core).
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 6d0ecd6 commit 5f6e740

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/ngx_http_lua_time.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,77 @@ ngx_http_lua_ffi_time(void)
272272
{
273273
return (long) ngx_time();
274274
}
275+
276+
277+
void
278+
ngx_http_lua_ffi_update_time(void)
279+
{
280+
ngx_time_update();
281+
}
282+
283+
284+
void
285+
ngx_http_lua_ffi_today(u_char *buf)
286+
{
287+
ngx_tm_t tm;
288+
289+
ngx_gmtime(ngx_time() + ngx_cached_time->gmtoff * 60, &tm);
290+
291+
ngx_sprintf(buf, "%04d-%02d-%02d", tm.ngx_tm_year, tm.ngx_tm_mon,
292+
tm.ngx_tm_mday);
293+
}
294+
295+
296+
void
297+
ngx_http_lua_ffi_localtime(u_char *buf)
298+
{
299+
ngx_tm_t tm;
300+
301+
ngx_gmtime(ngx_time() + ngx_cached_time->gmtoff * 60, &tm);
302+
303+
ngx_sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", tm.ngx_tm_year,
304+
tm.ngx_tm_mon, tm.ngx_tm_mday, tm.ngx_tm_hour, tm.ngx_tm_min,
305+
tm.ngx_tm_sec);
306+
}
307+
308+
309+
void
310+
ngx_http_lua_ffi_utctime(u_char *buf)
311+
{
312+
ngx_tm_t tm;
313+
314+
ngx_gmtime(ngx_time(), &tm);
315+
316+
ngx_sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", tm.ngx_tm_year,
317+
tm.ngx_tm_mon, tm.ngx_tm_mday, tm.ngx_tm_hour, tm.ngx_tm_min,
318+
tm.ngx_tm_sec);
319+
}
320+
321+
322+
int
323+
ngx_http_lua_ffi_cookie_time(u_char *buf, long t)
324+
{
325+
u_char *p;
326+
327+
p = ngx_http_cookie_time(buf, t);
328+
return p - buf;
329+
}
330+
331+
332+
void
333+
ngx_http_lua_ffi_http_time(u_char *buf, long t)
334+
{
335+
ngx_http_time(buf, t);
336+
}
337+
338+
339+
void
340+
ngx_http_lua_ffi_parse_http_time(const u_char *str, size_t len,
341+
long *time)
342+
{
343+
/* ngx_http_parse_time doesn't modify 'str' actually */
344+
*time = ngx_http_parse_time((u_char *) str, len);
345+
}
275346
#endif /* NGX_LUA_NO_FFI_API */
276347

277348

0 commit comments

Comments
 (0)