date2time — convert date (possibly with specified time) to number of seconds since Epoch
The filter replaces date specification in form of
MM[/-]DD[/-]YY(YY)?(:hh(mm)?)?
to a number of seconds since epoch.
If the year specification contains 2 digits only and is less than
50, as is say, 02,
then it is treated as an offset from year 2000, and not
1900. In other words, 05 is understood
as year 2005, 80 is understood as
1980.
Unspecified month or day default to 1, unspecified
hours or minutes default to 0.
Example: Converting dates and times to seconds since Epoch
[filter date2time]01/01/2005[/filter] [filter date2time]01/01/05[/filter] [filter date2time]01-01-2005[/filter] [filter date2time]01-01-05[/filter] [filter date2time]01-01-2005:10[/filter] [filter date2time]01-01-05:1045[/filter]Example in action:
20050101
20050101
20050101
20050101
1104538200
1104576300
This filter is considered deprecated, and is replaced by datetime2epoch.
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The timelocal() function used in the filter comes from the
Time::Local Perl module.
Interchange 5.9.0:
Source: code/Filter/date2time.filter
Lines: 50
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: date2time.filter,v 1.6 2007-03-30 23:40:44 pajamian Exp $
CodeDef date2time Filter
CodeDef date2time Description Date to UNIX time (deprecated - use datetime2epoch instead)
CodeDef date2time Visibility private
CodeDef date2time Routine <<EOR
sub {
my $val = shift;
use Time::Local;
$val =~ s/\0+//g;
if($val =~ m:(\d+)[-/]+(\d+)[-/]+(\d+):) {
my ($yr, $mon, $day) = ($3, $1, $2);
my $time;
$val =~ /:(\d+)$/
and $time = $1;
if(length($yr) < 4) {
$yr =~ s/^0//;
$yr = $yr < 50 ? $yr + 2000 : $yr + 1900;
}
$mon =~ s/^0//;
$day =~ s/^0//;
$val = sprintf("%d%02d%02d", $yr, $mon, $day);
return $val unless $time;
$val .= sprintf('%04d', $time);
}
my $time;
$val =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?/;
my ($yr, $mon, $day, $hr, $min) = ($1 || 0, $2 || 1, $3 || 1, $4 || 0, $5 || 0);
$mon--;
eval {
$time = timelocal(0, $min, $hr, $day, $mon, $yr);
};
if($@) {
logError("bad time value passed to date2time: %s", $@);
return 0;
}
return $time;
}
EOR