Skip to content

Commit 332872a

Browse files
author
drhyde
committed
Use ISO 8601 format date/times in log file
1 parent cbd1e8f commit 332872a

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

rsnapshot-program.pl

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# #
2727
########################################################################
2828

29-
# $Id: rsnapshot-program.pl,v 1.431 2012/04/04 12:09:07 drhyde Exp $
29+
# $Id: rsnapshot-program.pl,v 1.432 2012/04/24 21:37:11 drhyde Exp $
3030

3131
# tabstops are set to 4 spaces
3232
# in vi, do: set ts=4 sw=4
@@ -2167,33 +2167,19 @@ sub get_current_date {
21672167
# 4 = month + 1
21682168
# 5 = year + 1900
21692169

2170-
# example date format (just like Apache logs)
2171-
# 28/Feb/2004:23:45:59
2172-
2173-
my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
2174-
2170+
# example date format (ISO 8601)
2171+
# 2012-04-24T22:30:13 (used to be 28/Feb/2004:23:45:59, like Apache)
21752172
my @fields = localtime(time());
21762173

2177-
my $datestr =
2178-
# day of month
2179-
sprintf("%02i", $fields[3]) .
2180-
'/' .
2181-
# name of month
2182-
$months[$fields[4]] .
2183-
'/' .
2184-
# year
2185-
($fields[5]+1900) .
2186-
':' .
2187-
# hours (24 hour clock)
2188-
sprintf("%02i", $fields[2]) .
2189-
':' .
2190-
# minutes
2191-
sprintf("%02i", $fields[1]) .
2192-
':' .
2193-
# seconds
2194-
sprintf("%02i", $fields[0]);
2195-
2196-
return ($datestr);
2174+
return sprintf(
2175+
"%04i-%02i-%02iT%02i:%02i:%02i",
2176+
$fields[5] + 1900,
2177+
$fields[4] + 1,
2178+
$fields[3],
2179+
$fields[2],
2180+
$fields[1],
2181+
$fields[0]
2182+
);
21972183
}
21982184

21992185
# accepts no arguments

0 commit comments

Comments
 (0)