LCOV - code coverage report
Current view: top level - home/build/openresty-1.13.6.1/build/set-misc-nginx-module-0.31/src - ngx_http_set_local_today.c (source / functions) Hit Total Coverage
Test: coverage ngix Lines: 0 42 0.0 %
Date: 2020-03-03 04:25:50 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifndef DDEBUG
       2             : #define DDEBUG 0
       3             : #endif
       4             : #include "ddebug.h"
       5             : 
       6             : #include <ndk.h>
       7             : 
       8             : 
       9             : #ifndef NGX_HTTP_SET_MISC_FMT_DATE_LEN
      10             : #define NGX_HTTP_SET_MISC_FMT_DATE_LEN       256
      11             : #endif
      12             : 
      13             : 
      14             : ngx_int_t
      15           0 : ngx_http_set_local_today(ngx_http_request_t *r, ngx_str_t *res,
      16             :     ngx_http_variable_value_t *v)
      17             : {
      18             :     time_t           now;
      19             :     ngx_tm_t         tm;
      20             :     u_char          *p;
      21             : 
      22             :     /*t = ngx_timeofday();*/
      23             : 
      24           0 :     now = ngx_time();
      25             : 
      26           0 :     ngx_gmtime(now + ngx_cached_time->gmtoff * 60, &tm);
      27             : 
      28             :     dd("tm.ngx_tm_hour:%d", tm.ngx_tm_hour);
      29             : 
      30           0 :     p = ngx_palloc(r->pool, sizeof("yyyy-mm-dd") - 1);
      31           0 :     if (p == NULL) {
      32           0 :         return NGX_ERROR;
      33             :     }
      34             : 
      35           0 :     ngx_sprintf(p, "%04d-%02d-%02d", tm.ngx_tm_year, tm.ngx_tm_mon,
      36             :                 tm.ngx_tm_mday);
      37             : 
      38           0 :     res->data = p;
      39           0 :     res->len = sizeof("yyyy-mm-dd") - 1;
      40             : 
      41           0 :     return NGX_OK;
      42             : }
      43             : 
      44             : 
      45             : ngx_int_t
      46           0 : ngx_http_set_formatted_gmt_time(ngx_http_request_t *r, ngx_str_t *res,
      47             :     ngx_http_variable_value_t *v)
      48             : {
      49             :     time_t           now;
      50             :     u_char          *p;
      51             :     struct tm        tm;
      52             : 
      53           0 :     if (v->not_found || v->len == 0) {
      54           0 :         res->data = NULL;
      55           0 :         res->len = 0;
      56           0 :         return NGX_OK;
      57             :     }
      58             : 
      59           0 :     now = ngx_time();
      60           0 :     ngx_libc_gmtime(now, &tm);
      61             : 
      62           0 :     p = ngx_palloc(r->pool, NGX_HTTP_SET_MISC_FMT_DATE_LEN);
      63           0 :     if (p == NULL) {
      64           0 :         return NGX_ERROR;
      65             :     }
      66             : 
      67           0 :     res->len = strftime((char *) p, NGX_HTTP_SET_MISC_FMT_DATE_LEN,
      68           0 :                         (char *) v->data, &tm);
      69           0 :     if (res->len == 0) {
      70           0 :         return NGX_ERROR;
      71             :     }
      72             : 
      73           0 :     res->data = p;
      74             : 
      75           0 :     return NGX_OK;
      76             : }
      77             : 
      78             : 
      79             : ngx_int_t
      80           0 : ngx_http_set_formatted_local_time(ngx_http_request_t *r, ngx_str_t *res,
      81             :     ngx_http_variable_value_t *v)
      82             : {
      83             :     time_t           now;
      84             :     u_char          *p;
      85             :     struct tm        tm;
      86             : 
      87           0 :     if (v->not_found || v->len == 0) {
      88           0 :         res->data = NULL;
      89           0 :         res->len = 0;
      90           0 :         return NGX_OK;
      91             :     }
      92             : 
      93           0 :     now = ngx_time();
      94           0 :     ngx_libc_localtime(now, &tm);
      95             : 
      96           0 :     p = ngx_palloc(r->pool, NGX_HTTP_SET_MISC_FMT_DATE_LEN);
      97           0 :     if (p == NULL) {
      98           0 :         return NGX_ERROR;
      99             :     }
     100             : 
     101           0 :     res->len = strftime((char *) p, NGX_HTTP_SET_MISC_FMT_DATE_LEN,
     102           0 :                         (char *) v->data, &tm);
     103           0 :     if (res->len == 0) {
     104           0 :         return NGX_ERROR;
     105             :     }
     106             : 
     107           0 :     res->data = p;
     108             : 
     109           0 :     return NGX_OK;
     110             : }

Generated by: LCOV version 1.13