[ic] Modification of a passed Date Value
Mike Heins
mike at perusion.com
Tue Mar 2 13:00:32 EST 2004
Quoting Kevin Walsh (kevin at cursor.biz):
> Gary Norton [gnorton at broadgap.com] wrote:
> > If I have a stored in the following format: 20040218 (YYYYMMDD)
> >
> > I would like to modify that format by adding 3 days, or perhaps
> > subtracting 2.
> >
> > > From the docs it looks like I can use the convert_date tag to do this,
> > > but only if I do not pass a date:
> >
> > [convert_date -2][/convert_date] will subtract 2 days from the current
> > date/time.
> >
> > [convert_date -2]20040218[/convert_date] ignores the -2 and just formats
> > the date.
> >
> > The time tag looks like it only works with the current time as well. I
> > don't' seem to be able to pass it a date value.
> >
> > Am I using these tags incorrectly?
> >
> It seems that tag wasn't written to apply the "days" offset to a
> supplied date value - only to the current date (when no overriding
> date value has been supplied).
>
> The following patch seems to work, so I will apply it to the 5.1.x
> development CVS unless anyone has an objection, or can suggest a better
> way to do it:
>
> ======================================================================
> *** convert_date.tag 29 Jan 2002 05:52:42 -0000 1.1
> --- convert_date.tag 2 Mar 2004 16:26:38 -0000
> ***************
> *** 8,13 ****
> --- 8,14 ----
> sub {
> my ($days, $opt, $text) = @_;
> my @t;
> + my $now;
>
> if(! ref $opt) {
> my $raw = $opt ? 1 : 0;
> ***************
> *** 32,42 ****
> $t[5] -= 1900;
> }
> else {
> ! my $now = time();
> ! if ($days) {
> ! $now += $days * 86400;
> ! }
> ! @t = localtime($now);
> }
>
> if (defined $opt->{raw} and Vend::Util::is_yes($opt->{raw})) {
> --- 33,46 ----
> $t[5] -= 1900;
> }
> else {
> ! $now = time();
> ! @t = localtime($now) unless $days;
> ! }
> !
> ! if ($days) {
> ! $now ||= mktime(@t);
> ! $now += $days * 86400;
> ! @t = localtime($now);
> }
I think this might be better:
if($days) {
$days .= ' days' if $days =~ /^[-\s\d]+$/;
$now += Vend::Config::time_to_seconds($days);
}
At that point, $days might be better called $adj.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.765.647.1295 tollfree 800-949-1889 <mike at perusion.com>
I am a great believer in luck, and I find that the harder I work
the more luck I have. -- Thomas Jefferson
More information about the interchange-users
mailing list