* Add enclair_db option to UserDB.pm. Allows logging of enclair password
[interchange.git] / code / Filter / date2time.filter
1 # Copyright 2002-2007 Interchange Development Group and others
2 # Copyright 1996-2002 Red Hat, Inc.
3
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.
8
9 # $Id: date2time.filter,v 1.6 2007-03-30 23:40:44 pajamian Exp $
10
11 CodeDef date2time Filter
12 CodeDef date2time Description Date to UNIX time (deprecated - use datetime2epoch instead)
13 CodeDef date2time Visibility private
14 CodeDef date2time Routine <<EOR
15 sub {
16         my $val = shift;
17         use Time::Local;
18
19         $val =~ s/\0+//g;
20         if($val =~ m:(\d+)[-/]+(\d+)[-/]+(\d+):) {
21                 my ($yr, $mon, $day) = ($3, $1, $2);
22
23                 my $time;
24                 $val =~ /:(\d+)$/
25                         and $time = $1;
26                 if(length($yr) < 4) {
27                         $yr =~ s/^0//;
28                         $yr = $yr < 50 ? $yr + 2000 : $yr + 1900;
29                 }
30                 $mon =~ s/^0//;
31                 $day =~ s/^0//;
32                 $val = sprintf("%d%02d%02d", $yr, $mon, $day);
33                 return $val unless $time;
34                 $val .= sprintf('%04d', $time);
35         }
36
37         my $time;
38         $val =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?/;
39         my ($yr, $mon, $day, $hr, $min) = ($1 || 0, $2 || 1, $3 || 1, $4 || 0, $5 || 0);
40         $mon--;
41         eval {
42                 $time = timelocal(0, $min, $hr, $day, $mon, $yr);
43         };
44         if($@) {
45                 logError("bad time value passed to date2time: %s", $@);
46                 return 0;
47         }
48         return $time;
49 }
50 EOR