[ic] Modification of a passed Date Value

Kevin Walsh kevin at cursor.biz
Tue Mar 2 14:28:09 EST 2004


The following patch (code/UserTag/convert_date.tag) will allow this:

Test page:

    No args: [convert-date][/convert-date]<br>
    2 days before now: [convert-date adjust="-2"][/convert-date]<br>
    2 hours before now: [convert-date adjust="-2 hours"][/convert-date]<br>
    2 hours after now: [convert-date adjust="2 hours"][/convert-date]<br>
    2 days before 20040218: [convert-date adjust="-2"]20040218[/convert-date]<br>
    2 days before 2004-02-18: [convert-date adjust="-2"]2004-02-18[/convert-date]<br>
    3 days after 2004-02-18: [convert-date days="3"]2004-02-18[/convert-date]<br>
    20040218: [convert-date]20040218[/convert-date]<br>
    2004-02-18: [convert-date]2004-02-18[/convert-date]<br>

Results:

    No args: 02-Mar-2004 07:24PM
    2 days before now: 29-Feb-2004 07:24PM
    2 hours before now: 02-Mar-2004 05:24PM
    2 hours after now: 02-Mar-2004 09:24PM
    2 days before 20040218: 16-Feb-2004
    2 days before 2004-02-18: 16-Feb-2004
    3 days after 2004-02-18: 21-Feb-2004
    20040218: 18-Feb-2004
    2004-02-18: 18-Feb-2004

======================================================================
*** convert_date.tag    29 Jan 2002 05:52:42 -0000      1.1
--- convert_date.tag    2 Mar 2004 19:21:17 -0000
***************
*** 1,13 ****
! UserTag convert-date Order days
  UserTag convert-date PosNumber 1
  UserTag convert-date addAttr
  UserTag convert-date AttrAlias fmt format
  UserTag convert-date HasEndTag
  UserTag convert-date Interpolate
  UserTag convert-date Routine <<EOR
  sub {
!     my ($days, $opt, $text) = @_;
      my @t;

        if(! ref $opt) {
                my $raw = $opt ? 1 : 0;
--- 1,15 ----
! UserTag convert-date Order adjust
  UserTag convert-date PosNumber 1
  UserTag convert-date addAttr
  UserTag convert-date AttrAlias fmt format
+ UserTag convert-date AttrAlias days adjust
  UserTag convert-date HasEndTag
  UserTag convert-date Interpolate
  UserTag convert-date Routine <<EOR
  sub {
!     my ($adjust, $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})) {
--- 34,53 ----
                                        $t[5] -= 1900;
        }
        else {
!                                       $now = time();
!                                       @t = localtime($now) unless $adjust;
!       }
!
!       if ($adjust) {
!               $now ||= mktime(@t);
!               $adjust .= ' days' if $adjust =~ /^[-\s\d]+$/;
!
!               if ($adjust =~ s/^\s*-\s*//) {
!                       @t = localtime($now - Vend::Config::time_to_seconds($adjust));
!               }
!               else {
!                       @t = localtime($now + Vend::Config::time_to_seconds($adjust));
!               }
        }

        if (defined $opt->{raw} and Vend::Util::is_yes($opt->{raw})) {
======================================================================

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin at cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/



More information about the interchange-users mailing list