Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Care to simplify some working code?

by RichardK (Parson)
on Sep 29, 2011 at 11:36 UTC ( [id://928529]=note: print w/replies, xml ) Need Help??


in reply to Care to simplify some working code?

Inspired by BrowserUk's clever solution -- how about this ?

use strict; use warnings; use Time::Local; use Test::More "no_plan"; sub lastq_bday { my( $y, $m, $d ) = unpack 'A4A2A2', shift; my $q = int( ($m-1) /3 ) * 3; my $first = timelocal(0,0,12,1,$q,$y); $first -= 60*60*24; # last day of previous quarter my @t = localtime($first); $t[3] -= 2 if $t[6] == 0; #Sunday $t[3] -= 1 if $t[6] == 6; #Saturday return sprintf ("%d%02d%02d",1900+$t[5],$t[4]+1,$t[3]); } is ( lastq_bday("20110901"),"20110630"); is ( lastq_bday("20120101"),"20111230"); is ( lastq_bday("20110215"),"20101231"); is ( lastq_bday("20110407"),"20110331"); is ( lastq_bday("20110808"),"20110630"); is ( lastq_bday("20110101"),"20101231");

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-18 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found