Permalink
Browse files

feature: added new API ngx.update_time which calls ngx_time_update in…

… the Nginx core.
  • Loading branch information...
1 parent 79a1965 commit c598e718c16f78c463b2555ca037a181696d8544 @agentzh agentzh committed Nov 24, 2011
Showing with 27 additions and 0 deletions.
  1. +12 −0 src/ngx_http_lua_time.c
  2. +15 −0 t/012-now.t
View
@@ -14,6 +14,7 @@ static int ngx_http_lua_ngx_utctime(lua_State *L);
static int ngx_http_lua_ngx_cookie_time(lua_State *L);
static int ngx_http_lua_ngx_http_time(lua_State *L);
static int ngx_http_lua_ngx_parse_http_time(lua_State *L);
+static int ngx_http_lua_ngx_update_time(lua_State *L);
static int
@@ -97,6 +98,14 @@ ngx_http_lua_ngx_now(lua_State *L)
}
+static int
+ngx_http_lua_ngx_update_time(lua_State *L)
+{
+ ngx_time_update();
+ return 0;
+}
+
+
static int
ngx_http_lua_ngx_utctime(lua_State *L)
{
@@ -213,6 +222,9 @@ ngx_http_lua_inject_time_api(lua_State *L)
lua_pushcfunction(L, ngx_http_lua_ngx_now);
lua_setfield(L, -2, "now");
+ lua_pushcfunction(L, ngx_http_lua_ngx_update_time);
+ lua_setfield(L, -2, "update_time");
+
lua_pushcfunction(L, ngx_http_lua_ngx_today);
lua_setfield(L, -2, "get_today"); /* deprecated */
View
@@ -102,3 +102,18 @@ GET /time
--- request
GET /time
--- response_body_like: ^\d{10,}(\.\d{1,3})?$
+
+
+
+=== TEST 8: use ngx.update_time & ngx.now in content_by_lua
+--- config
+ location = /time {
+ content_by_lua '
+ ngx.update_time()
+ ngx.say(ngx.now())
+ ';
+ }
+--- request
+GET /time
+--- response_body_like: ^\d{10,}(\.\d{1,3})?$
+

0 comments on commit c598e71

Please sign in to comment.