[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] noCPAN coding (Jay Hannah)



On 11/23/10 2:00 PM, omaha-pm-request@pm.org wrote:
Message: 1
Date: Mon, 22 Nov 2010 14:33:38 -0600
From: Jay Hannah<jhannah@mutationgrid.com>
Subject: [Omaha.pm] noCPAN coding
To: Nebraska USA Perl Mongers of Omaha<omaha-pm@pm.org>
Message-ID:<4399653A-8521-433F-8625-9C7932C47896@mutationgrid.com>
Content-Type: text/plain; charset=us-ascii

If you can't use CPAN at all (gasp!) how do you detect if $record year/month is more than 7 years ago? I've been using Class::Date and/or DateTime *forever* so this was quite a trip down memory lane today:

    my @localtime = localtime(time);
    my $cutoff_mon = sprintf("%02d", $localtime[4] + 1);
    my $cutoff_year = $localtime[5] + 1900 - 7;  # 7 years ago
    my $disabled;
    if ($record->{"DateLastSeen"}{"Year"} . $record->{"DateLastSeen"}{"Month"} lt "$cutoff_year$cutoff_mon") {
       $disabled = "DISABLED";
    }

:)

Jay Hannah
Software Architect
jhannah@mutationgrid.com | http://mutationgrid.com | 1-402-598-7782

That's the way I fist did date calculations years ago. :-) I remember having these large complex calculations just to do something date::calc does in 2 lines, and yes using $localtime was your friend. :-)

--
Chris Brandstetter

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/IT d+(-) s++:++ a C++++$ UBLISXC*++++$ P++++$ L+++$ E-- W+++ N+ o K-
w-- O M++$ V PS- PE Y+ PGP++ t++ 5+++ X+ R- tv-- b+>+++ DI D+ G+ e+ h++
r
y?
------END GEEK CODE BLOCK------

To Decode: http://www.ebb.org/ungeek/