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: duration.filter,v 1.7 2009-05-01 13:50:00 pajamian Exp $
11 CodeDef duration Filter
12 CodeDef duration Description Duration
13 CodeDef duration Routine <<EOR
15 my ($val, undef, $startvar, $durvar, @extra) = @_;
17 ## Accepts two parameters, the name of the CGI variables which
18 ## hold the start date/time and the duration value. With this:
20 # [cgi name=start_date set=200502120800]
21 # [cgi name=length set="12 hours"]
22 # [filter op=duration.start_date.length /]
24 # The filter call will return 20050212200000
26 ## Can also be used like this, with the same output:
28 # [filter duration.-dummy.12.hours]200502120800[/filter]
31 my $start = $CGI->{$startvar} || $val;
32 my $durstring = $CGI->{$durvar};
35 if (!length($durstring) && $durvar =~ /^\d+$/) {
36 $durstring = join(' ', $durvar, @extra);
39 ## Want to allow setting the value directly
40 return $val unless $durstring;
43 if($start =~ m:(\d+)[-/]+(\d+)[-/]+(\d+):) {
44 my ($yr, $mon, $day) = ($3, $1, $2);
51 $yr = $yr < 50 ? $yr + 2000 : $yr + 1900;
55 $start = sprintf("%d%02d%02d", $yr, $mon, $day);
56 return $val unless $time;
57 $start .= sprintf('%04d', $time);
61 $start =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?/;
62 my ($yr, $mon, $day, $hr, $min) = ($1 || 0, $2 || 1, $3 || 1, $4 || 0, $5 || 0);
65 $time = timelocal(0, $min, $hr, $day, $mon, $yr);
68 logError("bad time value passed to duration filter: %s", $@);
72 $time = adjust_time($durstring, $time);
74 return POSIX::strftime("%Y%m%d%H%M%S", localtime($time));