Welcome! Log In Create A New Profile

Advanced

Re: Похоже на багу в date_local в ssi

March 30, 2010 12:18PM
On Fri, Feb 19, 2010 at 04:02:34PM +0300, Maxim Dounin wrote:

> On Fri, Feb 19, 2010 at 03:13:24PM +0300, Oleg Motienko wrote:
>
> > Привет всем.
> >
> > В ssi вот такая конструкция выдаёт время на 180 секунд вперед.
> > <!--# config timefmt="%s" --><!--# echo var="date_local" -->
> >
> > А такая - верное.
> > <!--# config timefmt="%s" --><!--# echo var="date_gmt" -->
> >
> > Почему-то возникает предположение, что 180 - это моя таймзона (GMT +3)* 60.
> > Только, почему-то 180 секунд, а не минут.
>
> Патч.
>
> Maxim Dounin

> # HG changeset patch
> # User Maxim Dounin <mdounin@mdounin.ru>
> # Date 1266584382 -10800
> # Node ID 843f000d1b37757c0753853d671c94192dcb8dcc
> # Parent 9009f1982e02d6f0614d4ddeae0672042442775a
> SSI: time format "%s" means seconds since the Epoch in UTC
>
> Adding local timezone offset is wrong here at all.
>
> diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c
> --- a/src/http/modules/ngx_http_ssi_filter_module.c
> +++ b/src/http/modules/ngx_http_ssi_filter_module.c
> @@ -2615,8 +2615,7 @@ ngx_http_ssi_date_gmt_local_variable(ngx
> return NGX_ERROR;
> }
>
> - v->len = ngx_sprintf(v->data, "%T", tp->sec + (gmt ? 0 : tp->gmtoff))
> - - v->data;
> + v->len = ngx_sprintf(v->data, "%T", tp->sec) - v->data;
>
> return NGX_OK;
> }

С этим strftime(%s) не просто: под FreeBSD 8.0 такая программка
----------
#include <time.h>
#include <sys/time.h>
#include <stdio.h>

main()
{
time_t t;
struct timeval tv;
struct tm *tm;
char buf[20];

gettimeofday(&tv, NULL);
printf("GToD: %d\n", tv.tv_sec);

t = time(NULL);
printf("TIME: %d\n", t);

tm = gmtime(&t);
strftime(buf, 20, "GMTM: %s", tm);
printf("%s\n", buf);

tm = localtime(&t);
strftime(buf, 20, "LOCT: %s", tm);
printf("%s\n", buf);
}
----------

выдаёт

GToD: 1269965127
TIME: 1269965127
GMTM: 1269954327
LOCT: 1269965127

При том, что date и date +%s выдают соответственно

Tue Mar 30 20:05:27 MSD 2010

1269965127

То есть, strftime(%s) для GMT выдаёт время на 3 часа меньше UTC (даже не 4).


--
Игорь Сысоев
http://sysoev.ru

_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

Re: Похоже на багу в date_local в ssi

Igor Sysoev March 30, 2010 12:18PM

Re: Похоже на багу в date_local в ssi

Maxim Dounin March 30, 2010 01:46PM

Re: Похоже на багу в date_local в ssi

Igor Sysoev March 31, 2010 03:24AM

Re: Похоже на багу в date_local в ssi

tony123 April 09, 2010 02:59AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 136
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready