renamed ngx.get_today() to ngx.today(), ngx.get_now() to ngx.now(), and ngx.get_now_ts() to ngx.time().
This commit is contained in:
Родитель
9ecb1f0730
Коммит
ad2b41ff65
|
@ -503,23 +503,23 @@ Decode `str` as a base64 digest to the raw form
|
|||
|
||||
newstr = ngx.decode_base64(str)
|
||||
|
||||
ngx.get_today()
|
||||
ngx.today()
|
||||
---------------
|
||||
Returns today's date (in the format `yyyy-mm-dd`) from nginx cached time (no syscall involved unlike Lua's date library).
|
||||
.
|
||||
|
||||
ngx.get_now()
|
||||
ngx.now()
|
||||
-------------
|
||||
Returns the current timestamp (in the format `yyyy-mm-dd hh:mm:ss`) of the nginx cached time (no syscall involved unlike Lua's date library).
|
||||
|
||||
ngx.get_now_ts()
|
||||
ngx.time()
|
||||
----------------
|
||||
|
||||
Returns the current timestamp (in seconds) of the nginx cached time (no syscall involved unlike Lua's date library).
|
||||
|
||||
ngx.cookie_time(sec)
|
||||
--------------------
|
||||
Returns a formated string can be used as the cookie expiration time. The parameter `sec` is the timestamp in seconds (like those returned from `ngx.get_now_ts`).
|
||||
Returns a formated string can be used as the cookie expiration time. The parameter `sec` is the timestamp in seconds (like those returned from `ngx.time`).
|
||||
|
||||
ngx.say(ngx.cookie_time(1290079655))
|
||||
# yields "Thu, 18-Nov-10 11:27:35 GMT"
|
||||
|
|
|
@ -107,13 +107,25 @@ ngx_http_lua_set_by_lua_env(lua_State *L, ngx_http_request_t *r, size_t nargs,
|
|||
lua_setfield(L, -2, "md5");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now_ts);
|
||||
lua_setfield(L, -2, "get_now_ts");
|
||||
lua_setfield(L, -2, "get_now_ts"); /* deprecated */
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now_ts);
|
||||
lua_setfield(L, -2, "time");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now);
|
||||
lua_setfield(L, -2, "get_now");
|
||||
lua_setfield(L, -2, "get_now"); /* deprecated */
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now);
|
||||
lua_setfield(L, -2, "now");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_today);
|
||||
lua_setfield(L, -2, "get_today");
|
||||
lua_setfield(L, -2, "get_today"); /* deprecated */
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_today);
|
||||
lua_setfield(L, -2, "today");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_cookie_time);
|
||||
lua_setfield(L, -2, "cookie_time");
|
||||
|
||||
lua_setfield(L, -2, "ngx");
|
||||
/* }}} */
|
||||
|
|
|
@ -504,13 +504,22 @@ init_ngx_lua_globals(lua_State *L)
|
|||
lua_setfield(L, -2, "md5");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now_ts);
|
||||
lua_setfield(L, -2, "get_now_ts");
|
||||
lua_setfield(L, -2, "get_now_ts"); /* deprecated */
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now_ts);
|
||||
lua_setfield(L, -2, "time");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now);
|
||||
lua_setfield(L, -2, "get_now");
|
||||
lua_setfield(L, -2, "get_now"); /* deprecated */
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_now);
|
||||
lua_setfield(L, -2, "now");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_today);
|
||||
lua_setfield(L, -2, "get_today");
|
||||
lua_setfield(L, -2, "get_today"); /* deprecated */
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_get_today);
|
||||
lua_setfield(L, -2, "today");
|
||||
|
||||
lua_pushcfunction(L, ngx_http_lua_ngx_cookie_time);
|
||||
lua_setfield(L, -2, "cookie_time");
|
||||
|
|
|
@ -16,10 +16,10 @@ run_tests();
|
|||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: use ngx.get_today in content_by_lua
|
||||
=== TEST 1: use ngx.today in content_by_lua
|
||||
--- config
|
||||
location = /today {
|
||||
content_by_lua 'ngx.say(ngx.get_today())';
|
||||
content_by_lua 'ngx.say(ngx.today())';
|
||||
}
|
||||
--- request
|
||||
GET /today
|
||||
|
@ -27,10 +27,10 @@ GET /today
|
|||
|
||||
|
||||
|
||||
=== TEST 2: use ngx.get_today in set_by_lua
|
||||
=== TEST 2: use ngx.today in set_by_lua
|
||||
--- config
|
||||
location = /today {
|
||||
set_by_lua $a 'return ngx.get_today()';
|
||||
set_by_lua $a 'return ngx.today()';
|
||||
echo $a;
|
||||
}
|
||||
--- request
|
|
@ -1,4 +1,4 @@
|
|||
# vim:set ft=perl ts=4 sw=4 et fdm=marker:
|
||||
# vim:set ft= ts=4 sw=4 et fdm=marker:
|
||||
use lib 'lib';
|
||||
use Test::Nginx::Socket;
|
||||
|
||||
|
@ -16,10 +16,10 @@ run_tests();
|
|||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: use ngx.get_now in content_by_lua
|
||||
=== TEST 1: use ngx.now in content_by_lua
|
||||
--- config
|
||||
location = /now {
|
||||
content_by_lua 'ngx.say(ngx.get_now())';
|
||||
content_by_lua 'ngx.say(ngx.now())';
|
||||
}
|
||||
--- request
|
||||
GET /now
|
||||
|
@ -27,10 +27,10 @@ GET /now
|
|||
|
||||
|
||||
|
||||
=== TEST 2: use ngx.get_now in set_by_lua
|
||||
=== TEST 2: use ngx.now in set_by_lua
|
||||
--- config
|
||||
location = /now {
|
||||
set_by_lua $a 'return ngx.get_now()';
|
||||
set_by_lua $a 'return ngx.now()';
|
||||
echo $a;
|
||||
}
|
||||
--- request
|
||||
|
@ -39,24 +39,24 @@ GET /now
|
|||
|
||||
|
||||
|
||||
=== TEST 3: use ngx.get_now_ts in content_by_lua
|
||||
=== TEST 3: use ngx.time in content_by_lua
|
||||
--- config
|
||||
location = /now_ts {
|
||||
content_by_lua 'ngx.say(ngx.get_now_ts())';
|
||||
location = /time {
|
||||
content_by_lua 'ngx.say(ngx.time())';
|
||||
}
|
||||
--- request
|
||||
GET /now_ts
|
||||
GET /time
|
||||
--- response_body_like: ^\d{10}$
|
||||
|
||||
|
||||
|
||||
=== TEST 4: use ngx.get_now_ts in set_by_lua
|
||||
=== TEST 4: use ngx.time in set_by_lua
|
||||
--- config
|
||||
location = /now_ts {
|
||||
set_by_lua $a 'return ngx.get_now_ts()';
|
||||
location = /time {
|
||||
set_by_lua $a 'return ngx.time()';
|
||||
echo $a;
|
||||
}
|
||||
--- request
|
||||
GET /now_ts
|
||||
GET /time
|
||||
--- response_body_like: ^\d{10}$
|
||||
|
|
@ -21,7 +21,7 @@ __DATA__
|
|||
--- config
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
ngx.say(ngx.cookie_time(1290079655))
|
||||
ngx.say(ngx.cookie_time(ngx.time()))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
|
|
Загрузка…
Ссылка в новой задаче