2018 twenty-four merry days of Perl Feed

Sign o' The Times

Calendar::List - 2018-12-01

Manic Monday

It is a well known fact that all of Santa's Elves are enthusiastic Perl Developers in their free time, contributing regularly to many of the amazing Perl projects we've come to know and love. However, what you might not know is that they are also part of the Elven Perl Monger group, meeting up on every second Thursday of the month for social occasions, and every third Thursday for technical presentations. It has been said (often) that they should have them the other way around, so they have more time to recover from the social occasions!

It was coming towards the end of the year, and The Wise Old Elf was getting around to updating the Elven Perl Monger website with all the dates for 2019. He always kept getting reminded he was really bad with dates, so this year he wanted to get them all right first time.

As per usual, he started to look around CPAN, and came across a little known module, Calendar::List. It seemed to be able to figure out dates, and have some options to help him filter out days he wasn't interested in. After a bit of reading, he got something useful to begin with.

Calendar::List took two date format fields, and a set of configuration parameters. The date fields allowed The Wise Old Elf to use the EPOCH timestamp to order numerically, and the second format field to present the date as he wished. The configuration parameters, enabled him to specify days he didn't want, the number of entries he wanted to return, and make sure he only got back dates from 2019.

Diamonds And Pearls

The Wise Old Elf, pleased with himself, proudly showed off his new code at the very next Elven technical meeting.

use Calendar::List;

my %config = (
  'options' => 52,
  'exclude' => {
      'monday' => 1,
      'tuesday' => 1,
      'wednesday' => 1,
      'friday' => 1,
      'saturday' => 1,
      'sunday' => 1
  },
  'start' => '01-01-2019',
  'end' => '01-01-2020',
);

my %hash = calendar_list('EPOCH' => 'DDEXT MONTH YYYY', \%config);
my %match; # counts the dates per month;
my @dates; # dates to print out

for my $item (sort keys %hash) {
    my ($mon) = $hash{$item} =~ /^\w+\W+(\w+)\W+\w+/;
    $match{$mon}++;

    push @dates, $hash{$item} . ' (Social)' if($match{$mon} == 2);
    push @dates, $hash{$item} . ' (Technical)' if($match{$mon} == 3);
}

Some of the more learned elves shook their heads, and muttered "He's done it again" to themselves. "What have I done again?" The Wise Old Elf enquired. "You've forgotten the European Perl Conference again, and next year it's in Riga, so we're definitely going!", came the reply. "Oh!" said The Wise Old Elf.

"It's OK", said Sugarplum Stripyboughs, stepping forward, "we only have to change the configuration parameters, and you'll be sorted". A few moments later, she'd made a few changes:

my %config = (
  'options' => 52,
  'exclude' => {
      'monday' => 1,
      'tuesday' => 1,
      'wednesday' => 1,
      'friday' => 1,
      'weekend' => 1,
      'holidays' => [ '07-08-2019', '08-08-2019', '09-08-2019' ]
  },
  'start' => '01-01-2019',
  'end' => '01-01-2020',
);

"Note I also changed 'saturday' and 'sunday' to 'weekend' too, saves you a line of code." said Sugarplum. "Excellent, thank you." The Wise Old Elf said with relief. "Now I can update the website."

Around The World In A Day

The Wise Old Elf, after updating the website, sat back and thought how useful that script had been in helping him. "I only need to update a few lines for next year, and I'll be done. Just hope I remember where I put the script!"

Gravatar Image This article contributed by: Barbie <barbie@cpan.org>