Permalink
Browse files

renamed ngx.get_today() to ngx.today(), ngx.get_now() to ngx.now(), a…

…nd ngx.get_now_ts() to ngx.time().
  • Loading branch information...
1 parent 9ecb1f0 commit ad2b41ff6563e6704e8a62703f751471227e18a9 @agentzh agentzh committed Nov 18, 2010
Showing with 49 additions and 28 deletions.
  1. +4 −4 README.markdown
  2. +15 −3 src/ngx_http_lua_setby.c
  3. +12 −3 src/ngx_http_lua_util.c
  4. +4 −4 t/{008-get_today.t → 008-today.t}
  5. +13 −13 t/{012-get_now.t → 012-now.t}
  6. +1 −1 t/021-time.t
View
@@ -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"
View
@@ -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"); /* deprecated */
lua_pushcfunction(L, ngx_http_lua_ngx_get_now);
- lua_setfield(L, -2, "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");
/* }}} */
View
@@ -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"); /* deprecated */
lua_pushcfunction(L, ngx_http_lua_ngx_get_now);
- lua_setfield(L, -2, "get_now");
+ lua_setfield(L, -2, "now");
+
+ lua_pushcfunction(L, ngx_http_lua_ngx_get_today);
+ lua_setfield(L, -2, "get_today"); /* deprecated */
lua_pushcfunction(L, ngx_http_lua_ngx_get_today);
- lua_setfield(L, -2, "get_today");
+ lua_setfield(L, -2, "today");
lua_pushcfunction(L, ngx_http_lua_ngx_cookie_time);
lua_setfield(L, -2, "cookie_time");
@@ -16,21 +16,21 @@ 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
--- response_body_like: ^\d{4}-\d{2}-\d{2}$
-=== 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,21 +16,21 @@ 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
--- response_body_like: ^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$
-=== 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}$
View
@@ -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

0 comments on commit ad2b41f

Please sign in to comment.