This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
Date: Mon, 16 Oct 2000 21:47:36 +0100 (BST) From: Matt Sergeant <matt@sergeant.org> To: "David E. Wheeler" <David@Wheeler.net> Subject: Re: ht_time vs. strftime On Mon, 16 Oct 2000, David E. Wheeler wrote: > Hi All, > > Can anyone tell me why these are not equivalent? Shouldn't strftime know > that the time returned from gmtime() is GMT? I'm trying to create a > library that'll use ht_time when $ENV{MOD_PERL} is true, ans strftime > otherwise. But they need to be consistent! > > use Apache::Util 'ht_time'; > my $t = ht_time; > print "$t\n"; # prints "Mon, 16 Oct 2000 20:33:42 GMT" > > use POSIX 'strftime'; > my $a = strftime("%a, %d %b %Y %T %Z", gmtime); > print "$a\n"; # prints Mon, 16 Oct 2000 21:33:42 PDT Sadly gmtime doesn't return any component indicating the timezone. Of course why not print out GMT instead of %Z? Alternatively, why not use Time::Object? It implements strftime without the overhead of POSIX.pm, and does it in XS too. -- <Matt/> /|| ** Director and CTO ** //|| ** AxKit.com Ltd ** ** XML Application Serving ** // || ** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\ === Date: Mon, 16 Oct 2000 13:55:07 -0700 From: "David E. Wheeler" <David@Wheeler.net> To: Matt Sergeant <matt@sergeant.org> Subject: Re: ht_time vs. strftime Matt Sergeant wrote: > > Sadly gmtime doesn't return any component indicating the timezone. Of > course why not print out GMT instead of %Z? Because it won't always be GMT. > Alternatively, why not use Time::Object? It implements strftime without > the overhead of POSIX.pm, and does it in XS too. Does it know Time Zones? Here's what I've got so far. The idea is to get &$format_date to work correctly everywhere. BEGIN { if ($ENV{MOD_PERL}) { use Apache::Util; $format_date = \&Apache::Util::ht_time; } else { use POSIX; $format_date = sub { POSIX::strftime($_[1] || "%a, %d %b %Y %T %Z", $_[0] ? localtime($_[0]) : gmtime); }; } } Thanks, David -- David E. Wheeler Phone: (415) 645-9365 Software Engineer Fax: (415) 645-9204 Salon Internet ICQ: 15726394 dw@salon.com AIM: dwTheory === Date: Mon, 16 Oct 2000 22:36:46 +0100 (BST) From: Matt Sergeant <matt@sergeant.org> To: "David E. Wheeler" <David@Wheeler.net> Subject: Re: ht_time vs. strftime On Mon, 16 Oct 2000, David E. Wheeler wrote: > Matt Sergeant wrote: > > > > Sadly gmtime doesn't return any component indicating the timezone. Of > > course why not print out GMT instead of %Z? > > Because it won't always be GMT. I'm confused. Why are you using gmtime then? > > Alternatively, why not use Time::Object? It implements strftime without > > the overhead of POSIX.pm, and does it in XS too. > > Does it know Time Zones? It just does strftime, so you can do what you've got below without loading POSIX. Plus its OO so it makes more sense (IMHO). > Here's what I've got so far. The idea is to get > &$format_date to work correctly everywhere. > > BEGIN { > if ($ENV{MOD_PERL}) { > use Apache::Util; > $format_date = \&Apache::Util::ht_time; > } else { > use POSIX; > $format_date = sub { > POSIX::strftime($_[1] || "%a, %d %b %Y %T %Z", $_[0] ? > localtime($_[0]) : gmtime); > }; I'm not sure I understand the correctness of this. Shouldn't it be: gmtime($_[0] || time) or localtime($_[0] || time) ?? -- <Matt/> /|| ** Director and CTO ** //|| ** AxKit.com Ltd ** ** XML Application Serving ** // || ** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\ === Date: Mon, 16 Oct 2000 15:47:13 -0700 From: "David E. Wheeler" <David@Wheeler.net> To: Matt Sergeant <matt@sergeant.org> Subject: Re: ht_time vs. strftime Matt Sergeant wrote: > > On Mon, 16 Oct 2000, David E. Wheeler wrote: > > I'm confused. Why are you using gmtime then? Because if no time is supplied, I want it to default to GMT. I'm setting up an app in which the database will store date/time in GMT only, but will serve it out to users in their own local timezones. So sometimes it'll be GMT and sometimes it won't. > > Does it know Time Zones? > > It just does strftime, so you can do what you've got below without loading > POSIX. Plus its OO so it makes more sense (IMHO). So %Z still won't work properly when I use gmtime. > I'm not sure I understand the correctness of this. Shouldn't it be: > > gmtime($_[0] || time) > > or > > localtime($_[0] || time) > No, because if no time is supplied, I want UTC. If a time is supplied, I want no alteration to that time (gmtime would correct it). The goal is to get it to act exactly as ht_time does. Maybe this: BEGIN { if ($ENV{MOD_PERL}) { use Apache::Util; $format_date = \&Apache::Util::ht_time; } else { use POSIX; $format_date = sub { POSIX::strftime($_[1] || $_[0] ? "%a, %d %b %Y %T %Z" : "%a, %d %b %Y %T GMT", $_[0] ? localtime($_[0]) : (gmtime)[0..7]); }; } } Which also corrects for the one hour difference between them (why would gmtime() ever return true for daylight savings??? It does! D -- David E. Wheeler Software Engineer Salon Internet ICQ: 15726394 dw@salon.com AIM: dwTheory === Date: Tue, 17 Oct 2000 08:42:40 +0100 (BST) From: Matt Sergeant <matt@sergeant.org> To: "David E. Wheeler" <David@Wheeler.net> Subject: Re: ht_time vs. strftime On Mon, 16 Oct 2000, David E. Wheeler wrote: > Matt Sergeant wrote: > > > > On Mon, 16 Oct 2000, David E. Wheeler wrote: > > > > I'm confused. Why are you using gmtime then? > > Because if no time is supplied, I want it to default to GMT. I'm setting > up an app in which the database will store date/time in GMT only, but > will serve it out to users in their own local timezones. So sometimes > it'll be GMT and sometimes it won't. Gotcha. > BEGIN { > if ($ENV{MOD_PERL}) { > use Apache::Util; > $format_date = \&Apache::Util::ht_time; > } else { > use POSIX; > $format_date = sub { > POSIX::strftime($_[1] || $_[0] ? "%a, %d %b %Y %T %Z" : > "%a, %d %b %Y %T GMT", $_[0] ? localtime($_[0]) : > (gmtime)[0..7]); > }; > } > } You should still switch to Time::Object. Loading POSIX.pm still loads in the .so which contains loads of cruft for things you don't want/need. Whereas loading Time::Object is a lot smaller. Of course I'm not sure how you'd fix the isdst thing with Time::Object, since it does strftime internally... -- <Matt/> /|| ** Director and CTO ** //|| ** AxKit.com Ltd ** ** XML Application Serving ** // || ** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\ === Date: Tue, 17 Oct 2000 10:11:36 -0700 From: "David E. Wheeler" <David@Wheeler.net> To: Matt Sergeant <matt@sergeant.org> Subject: Re: ht_time vs. strftime Matt Sergeant wrote: > You should still switch to Time::Object. Loading POSIX.pm still loads in > the .so which contains loads of cruft for things you don't > want/need. Whereas loading Time::Object is a lot smaller. Of course I'm > not sure how you'd fix the isdst thing with Time::Object, since it does > strftime internally... Perhaps you could add something like ht_time() has - it takes a third argument indicating whether the time passed is UTC. If it is, it uses gmtime internally, otherwise it uses localtime. And it looks like ht_time()'s implementation of gmtime() properly returns the time zone and doesn't add in DST stuff. Is that doable in Time::Object, or are you using Perl's gmtime() there? http://src.openresources.com/debian/src/web/HTML/S/ncsa_1.4.2.orig%20ncsa-1.4.2.orig%20src%20util.c.html#117 David -- David E. Wheeler Phone: (415) 645-9365 Software Engineer Fax: (415) 645-9204 Salon Internet ICQ: 15726394 dw@salon.com AIM: dwTheory === Date: Tue, 17 Oct 2000 20:46:37 +0100 (BST) From: Matt Sergeant <matt@sergeant.org> To: "David E. Wheeler" <David@Wheeler.net> Subject: Re: ht_time vs. strftime On Tue, 17 Oct 2000, David E. Wheeler wrote: > Matt Sergeant wrote: > > > You should still switch to Time::Object. Loading POSIX.pm still loads in > > the .so which contains loads of cruft for things you don't > > want/need. Whereas loading Time::Object is a lot smaller. Of course I'm > > not sure how you'd fix the isdst thing with Time::Object, since it does > > strftime internally... > > Perhaps you could add something like ht_time() has - it takes a third > argument indicating whether the time passed is UTC. If it is, it uses > gmtime internally, otherwise it uses localtime. And it looks like > ht_time()'s implementation of gmtime() properly returns the time zone > and doesn't add in DST stuff. Is that doable in Time::Object, or are you > using Perl's gmtime() there? Its doable - I could add in the code for ht_time almost verbatim, although I *am* using Perl's gmtime. -- <Matt/> /|| ** Director and CTO ** //|| ** AxKit.com Ltd ** ** XML Application Serving ** // || ** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\ === Date: Tue, 17 Oct 2000 14:03:22 -0700 From: "David E. Wheeler" <David@Wheeler.net> To: Matt Sergeant <matt@sergeant.org> Subject: Re: ht_time vs. strftime Matt Sergeant wrote: > > Its doable - I could add in the code for ht_time almost verbatim, although > I *am* using Perl's gmtime. Could you not use the same gmtime that ht_time uses? D -- David E. Wheeler Software Engineer Salon Internet ICQ: 15726394 dw@salon.com AIM: dwTheory