1 # Copyright 2002-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: convert_date.tag,v 1.9 2009-05-01 13:50:00 pajamian Exp $
10 UserTag convert-date Order adjust
11 UserTag convert-date PosNumber 1
12 UserTag convert-date addAttr
13 UserTag convert-date AttrAlias fmt format
14 UserTag convert-date AttrAlias days adjust
15 UserTag convert-date HasEndTag
16 UserTag convert-date Interpolate
17 UserTag convert-date Version $Revision: 1.9 $
18 UserTag convert-date Routine <<EOR
20 my ($adjust, $opt, $text) = @_;
25 my $raw = $opt ? 1 : 0;
27 $opt->{raw} = 1 if $raw;
30 my $fmt = $opt->{format} || '';
31 if($text =~ /^(\d\d\d\d)-(\d?\d)-(\d?\d)$/) {
36 elsif($text =~ /\d/) {
38 $text =~ /(\d\d\d\d)(\d\d)(\d\d)(?:(\d\d)(\d\d))?/;
46 elsif (exists $opt->{empty}) {
51 @t = localtime($now) unless $adjust;
58 $now ||= POSIX::mktime(@t);
59 $adjust .= ' days' if $adjust =~ /^[-\s\d]+$/;
60 @t = localtime(adjust_time($adjust, $now, $opt->{compensate_dst}));
63 if (defined $opt->{raw} and Vend::Util::is_yes($opt->{raw})) {
64 $fmt = $t[2] && $text ? '%Y%m%d%H%M' : '%Y%m%d';
69 $fmt = '%d-%b-%Y %I:%M%p';
76 my $locale = $opt->{locale} || $Scratch->{mv_locale};
78 $current = POSIX::setlocale(&POSIX::LC_TIME);
79 POSIX::setlocale(&POSIX::LC_TIME, $locale);
80 $out = POSIX::strftime($fmt, @t);
81 POSIX::setlocale(&POSIX::LC_TIME, $current);
83 $out = POSIX::strftime($fmt, @t);
85 $out =~ s/\b0(\d)\b/$1/g if $opt->{zerofix};