Hi all,
I think the day of year format has an off-by-one problem. This is a classic error when using localtime, as the range returned by localtime is not expected -- it is 0..364 (or 0..365 in leap years.) instead of 1-365 (1 - 366 in leap years)
For example, this test script shows that the day of year is off by one:
use Log::Log4perl::DateFormat;
my $format = Log::Log4perl::DateFormat->new("yyyy-DDD-HH:mm:ss,SSS");
# Simple time, resolution in seconds
my $time = time();
print $format->format($time), "\n";
Run on my system:
# perl log4perl_test.pl
2006-176-15:45:08,000
# date "+%Y-%j-%H:%M:%S"
2006-177-15:45:13
To fix, change DateFormat.pm
push @{$self->{stack}}, [7, sub { $_[0] }];
to
push @{$self->{stack}}, [7, sub { $_[0] + 1}];
Patch, (generated with "diff -Naur" against 1.04, but I believe 1.05 is the same as in 1.04)
--- Log-Log4perl-1.04/lib/Log/Log4perl/DateFormat.pm 2005-03-27 07:45:58.000000000 +0000
+++ DateFormat.pm 2006-06-26 20:03:52.000000000 +0000
@@ -191,7 +191,7 @@
#D - day of the year #
######################
} elsif($first eq "D") {
- push @{$self->{stack}}, [7, sub { $_[0] }];
+ push @{$self->{stack}}, [7, sub { $_[0] + 1}];
return "%${len}s";
######################
If I've made some sort of dumb error, please let me know (it wouldn't be the first time)! :)
|