Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: The darned Feb problem :)

by Reverend Phil (Pilgrim)
on Apr 24, 2002 at 19:05 UTC ( [id://161731]=note: print w/replies, xml ) Need Help??


in reply to The darned Feb problem :)
in thread where does the time go?

Ahh, while the deeper parts of this thread explain why that's a nasty thing to do for specific dates, in this particular application you should be fine. Our noble friend Anonymous Monk is just looking to roll the month back, so he can take those month values and work with them. Of course, he'll want to check to see if he's working with December and January, but otherwise, grabbing the month (and throwing a zero onto the front of a short one) should suffice. Working with the previous code (hacking stupidly, rather than grabbing a pretty module here), and handling both this and last month...
($month, $year) = (localtime)[4..5]; # convert from index to 'normal' $this_months_year = $year + 1900; $last_months_year = $this_months_year; $this_month = $month + 1; # fix month if = 0 $last_month = $month; $last_month or $last_month = 12; # roll back year if this month is january ($this_month == 1) and $last_months_year--; $this = sprintf("%04d%02d", $this_months_year, $this_month); $last = sprintf("%04d%02d", $last_months_year, $last_month); @files_this = <companyname.com-$this??_log>; @files_last = <companyname.com-$last??_log>;

I think that looks a bit ugly, but that should at least illustrate why it's a good idea to peek into those date related modules. As a sidenote.. did I miss anything else in there, or should that ugly hack do the trick?

-=rev=-

Replies are listed 'Best First'.
Nice ugly hack
by RMGir (Prior) on Apr 24, 2002 at 19:29 UTC
    NICE ugly hack :)

    In fact, I used to have code very much like that.

    Then someone changed the interval from "1 month" to "20 days", and I started wishing I'd used Date::Calc right from the start...

    But your way should work fine for what he needs, as long as the specs don't change down the road.
    --
    Mike

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-26 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found