Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

boohoo, the above article is mine, but I posted it anonymously by mistake. oh higher powers, if it please you, transfer the XPs of the article to this humble scribe.

I'm a big fan of peanos axioms. So I started with the idea: if it weren't dates we were dealing with, but natural numbers, then I would just sort the numbers, and compute the gaps with one simple loop. I decided to convert you date-format to something that can be sorted numerically (YYYYMM, with month in two digits, like "02"), and I made up a function "nextmonth" for incrementing the date.

sub nextmonth { my($year, $month); $year = substr($_[0], 0, 4); $month = substr($_[0], 4, 2); $month++; while ($month > 12) { $year++; $month-=12; } return $year . sprintf("%02d", $month); } sub find_gaps { my $dates = shift; my(@missing, @keys, $last); # convert your date-format to mine @keys = map { s/-(.)$/0$1/; s/-//; $_ } keys %$dates; # my format can be sorted numerically @keys = sort @keys; # in the loop we need two variables: # $last for the date before the current one, # and $date for the current date $last = shift(@keys); foreach my $date ( @keys ) { while (1) { $last = nextmonth($last); last if $last eq $date; push(@missing, $last); } $last = $date; } # convert my date-format back to yours @missing = map { s/0(.)$/$1/; s/^(....)/$1-/; $_ } @missing; return \@missing; }

share and enjoy

--
Brigitte    'I never met a chocolate I didnt like'    Jellinek
http://www.horus.com/~bjelli/         http://perlwelt.horus.at

In reply to Re: Re: Finding gaps in date ranges by bjelli
in thread Finding gaps in date ranges by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [marto]: I'd be interested in seeing the schema and some test data. I think the move could be done in stages.
    [ambrus]: Corion: did you as the gods release any official opinion about how perlmonks is now on HTTPS?
    [Corion]: Discipulus: I think once we have a test environment again and move to git, contribution and change gets easier
    [Corion]: ambrus: I think there was some discussion and maybe even an entry in Tidings, but I'm not really sure
    [marto]: Back later, got to get the kids ready
    [ambrus]: Also, I still have the suspicion that Perlmonks as a website is still horribly insecure, and that a malicious attacker could take over anyone's account easily, and I should tell the details of why I think this in some Cabal-only place.
    [Corion]: But the site now is on https (only), and now also with one unified SSL certificate for all PM hoss
    [ambrus]: This worries me a lot especially because as a cbstream maintainer, if this happens, I could get falsely blamed for any insecurity.
    [ambrus]: Cbstream itself is also insecure because I abandonned it for too long, and it's really ripe for a full rewrite or something now.
    [ambrus]: But that's a totally different issue.

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (9)
    As of 2018-07-19 08:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (404 votes). Check out past polls.

      Notices?