Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: date ranges as days

by punkish (Priest)
on Feb 23, 2011 at 20:33 UTC ( [id://889860]=note: print w/replies, xml ) Need Help??


in reply to date ranges as days

Thanks wind and ikegami. Once again, my apologies for this very simple problem that I should have figured out myself. I am adding my own solution to your contributions for the benefit of the archives

use Time::JulianDay; my @start = (1981, 2, 1); my @end = (1982, 2, 5); my $days = days('start' => \@start, 'end' => \@end, 'type' => 'yearly' +); my $days = days('start' => \@start, 'end' => \@end, 'type' => 'range') +; sub days { my (%a) = @_; my ($start, $end, $type) = ($a{'start'}, $a{'end'}, $a{'type'}); if ($type eq 'range') { my $j0 = julian_day(1980, 1, 1); my $j1 = julian_day(@$start); my $j2 = julian_day(@$end); return (($j1 - $j0), ($j2 - $j0)); } elsif ($type eq 'yearly') { my $start_year = $start->[0]; my $end_year = $end->[0]; my %days; for my $year ($start_year .. $end_year) { my $j0 = julian_day($year, 1, 1); my $j1; my $j2; if ($year == $start_year) { $j1 = julian_day($year, $start->[1], $start->[2]); $j2 = julian_day($year, 12, 31); } elsif ($year == $end_year) { $j1 = julian_day($year, 1, 1); $j2 = julian_day($year, $end->[1], $end->[2]); + } else { $j1 = julian_day($year, 1, 1); $j2 = julian_day($year, 12, 31); } $days{"$year"} = [($j1 - $j0) .. ($j2 - $j0)]; } return \%days; } }
--

when small people start casting long shadows, it is time to go to bed

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found