|
From: | Vincent Caron <address@hidden> |
Subject: | [cvsreport] fixed date timezone handling (I hope) |
Date: | Fri, 08 Aug 2003 11:11:00 -0400 |
Commit from zerodeux | 2003-08-08 11:10 EDT |
fixed date timezone handling (I hope)
Module | File name | Revision | |||
---|---|---|---|---|---|
cvsreport | ChangeLog | 1.25 | >>> | 1.26 | |
cvsreport | cvsreport | 1.27 | >>> | 1.28 |
cvsreport/ChangeLog 1.25 >>> 1.26 |
---|
Line 1 |
+ 2003/08/08 17:12 zerodeux + - parse_utc_date: now really parse UTC dates + - get_local_date: now really returns local time + - get_diff(): added diff format to temp file mangling + |
2003/07/31 03:26 zerodeux - added 'my' command: let user defines its own variables |
cvsreport/cvsreport 1.27 >>> 1.28 |
---|
Line 20 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use Getopt::Long qw(:config no_auto_abbrev no_ignore_case bundling); |
- use POSIX qw(mktime strftime); |
+ use POSIX qw(mktime strftime tzset); |
use Fcntl qw(:flock); use Cwd qw(getcwd); use strict; |
Line 162 |
return sprintf ("%d-%.2d-%.2d %.2d:%.2d:%.2d +0000", $now[5]+1900, $now[4]+1, $now[3], $now[2], $now[1], $now[0]); } |
- # Convert CVS formated date to UTC timestamp. |
+ # Parse a CVS formated date (year-month-day hour:minute +timezone). + # (we ignore timezone since 'cvs history' always uses UTC) |
# |
- # Parse a CVS formated date (year-month-day hour:minute +timezone), return seconds elapsed - # since Epoch. Warning, input must be tokenized in YMD, HM and zone triplet (sorry). - # - # $date_utc = get_time_utc split(/ /, "2003-06-30 16:55 +0200"); - # $date_str = get_date_str $date_utc; - # (display '2003-06-30 14:55 UTC') - # - sub get_time_utc { - my ($year, $month, $day) = split /-/, shift; - my ($hour, $min) = split /:/, shift; - my $zone = shift; - - # FIXME: the 1..24 hour field range is not what man 2 says but works here (TM). - my $ctime = mktime(0, $min, $hour + 1, $day, $month - 1, $year - 1900); - - if ($zone ne '') { - # remove starting '+' or '-' - $zone =~ s/^([\+\-])//; - - # Compute zone time shift in minutes - my $zone_shift = (substr $zone, 0, 2) * 60 + (substr $zone, 2, 2); - $zone_shift = -$zone_shift if $1 eq '-'; - - # Adjust ctime to UTC - my $ctime -= $zone_shift * 60; - } |
+ sub parse_utc_date { + my ($ymd, $hm, $zone) = split / /, shift; + my ($year, $month, $day) = split /[-\/]/, $ymd; + my ($hour, $min) = split /:/, $hm; + + # Save TZ, wether it is defined or not. + my $tz = defined $ENV{TZ} ? $ENV{TZ} : undef; + # Go UTC. + $ENV{TZ} = ''; + tzset(); + + my $ctime = mktime(0, $min, $hour, $day, $month - 1, $year - 1900); + + # Restore local timezone. + if (defined $tz) { $ENV{TZ} = $tz; } else { delete $ENV{TZ}; } + tzset(); |
return $ctime; } |
- # Converts time stamp to human readable UTC time |
+ # Converts time stamp to human readable date, using local timezone. |
# |
- sub get_date_str { |
+ sub get_local_date { |
my $ctime = shift; |
- return strftime "%Y-%m-%d %H:%M UTC", gmtime($ctime); |
+ return strftime "%Y-%m-%d %H:%M %Z", localtime($ctime); |
} # Returns true if a cvsroot value is a local path |
Line 603 |
# Actually we could parse directly $CVSROOT/CVSROOT/history but that would break remote usage. my @tokens = split / +/; my ($action, $date_ymd, $date_hm, $date_zone, $xuser, $revision, $file, $path, undef, $method) = @tokens; |
- my $xdate = get_time_utc $date_ymd, $date_hm, $date_zone; |
+ my $xdate = parse_utc_date "$date_ymd $date_hm $date_zone"; |
my $fullpath = "$path/$file"; ($xbranch, $xmessage) = get_file_info($fullpath, $revision) if not ($single_cset and $h_count > 0); |
Line 767 |
sub text_cset { my $cset = shift; |
- my $date = get_date_str $history[$cset->{h_start}]->{date}; |
+ my $date = get_local_date $history[$cset->{h_start}]->{date}; |
# If we're not on trunk, display branch name my $branch = $cset->{branch}; |
Line 952 |
sub html_cset_begin { my $cset = shift; |
- my $date = get_date_str $history[$cset->{h_start}]->{date}; |
+ my $date = get_local_date $history[$cset->{h_start}]->{date}; |
# If we're not on trunk, display branch name my $branch = $cset->{branch}; |
[Prev in Thread] | Current Thread | [Next in Thread] |