1 # Copyright 2002-2007 Interchange Development Group and others
2 # Copyright 1996-2002 Red Hat, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version. See the LICENSE file for details.
9 # $Id: datetime2epoch.filter,v 1.2 2007-03-30 23:40:44 pajamian Exp $
11 CodeDef datetime2epoch Filter
12 CodeDef datetime2epoch Description Date and optional time to seconds since the UNIX Epoch
13 CodeDef datetime2epoch Routine <<EOR
17 my ($year, $mon, $day, $hr, $min, $sec, $time);
22 $val =~ m%^\s*(\d\d)[-/]+(\d+)[-/]+(\d+)% and do {
23 ($year, $mon, $day) = ($3, $1, $2);
25 $val =~ /:(\d\d):?(\d\d)?:?(\d\d)?\s*$/
26 and $time = sprintf('T%02d:%02d:%02d', $1, $2 || 0, $3 || 0);
28 if (length($year) < 4) {
30 $year = $year < 50 ? $year + 2000 : $year + 1900;
32 $val = sprintf('%d-%02d-%02d%s', $year, $mon || 1, $day || 1, $time);
35 $val =~ /^\s*(\d\d\d\d)-(\d\d)-(\d\d)(?:[T\s](\d\d)?(?::(\d\d)?(?::(\d\d)?)?)?)?/;
36 ($year, $mon, $day, $hr, $min, $sec) = ($1, $2, $3, $4 || 0, $5 || 0,$6 || 0);
38 $time = timelocal($sec, $min, $hr, $day, --$mon, $year);
41 logError("bad time value passed to datetime2epoch: %s", $@);