Skip to content

Commit

Permalink
push for test
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrowder committed Feb 24, 2024
1 parent 830a5ad commit 7292526
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
Revision history for Holidays-US-Federal

{{$NEXT}}
- Add new subroutine with tests:
+ get-fedholidays-hashlist(:$year --> Hash)

0.0.5 2024-02-07T10:57:16-06:00
- Use recoommended "%( )" bracket pair for hashes
Expand Down
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -38,12 +38,21 @@ for @d -> $D {
}
```

For simpler use, we can get a hash also keyed by Date, but whose values are lists of holiday events:

my %us = get-fedholidays-hashlist :$year;
for %us.keys.sort -> $date {
for @(%us{$date}) -> $holiday {
my $n = $holiday.name;
}
}

DESCRIPTION
===========

**Holidays::US::Federal** is a module that provides information on the eleven official U.S. federal holidays as of 2023-03-08 according to data available online at [https://www.opm.gov/policy-data-oversight/pay-leave/federal-holidays/](https://www.opm.gov/policy-data-oversight/pay-leave/federal-holidays/). A description of the rules for traditional dates and when holidays are actually observed as paid holidays off for federal employees is also found on the site. All the data reflect current laws in Title 5 US Code Section 6103.

This module provides a routine which provides a hash of the holidays for a given year keyed by each holiday's traditional date. Each key is a Raku `Date`, and the key's value is a `class FedHoliday is Date::Event` object. The data are perpetual for any given year as long as Title 5 US Code Section 6103 stays unchanged.
This module provides two routines which provide a hash of the holidays for a given year keyed by each holiday's traditional date. Each key is a Raku `Date`, and the key's value is either (1) a `class FedHoliday is Date::Event` object or a list of the same. The data are perpetual for any given year as long as Title 5 US Code Section 6103 stays unchanged.

For this collection there should be no overlapping holidays. Each instance is one with two different date attributes: (1) the traditional `date` and (2) the `date-observed` which is the paid day-off for most federal government employees (as well as for many other employees in the US labor force). If the dates are identical, then that date is the only one to use on a calendar. If they are different, then both should be used.

Expand Down
19 changes: 16 additions & 3 deletions docs/README.rakudoc
Expand Up @@ -36,6 +36,18 @@ for @d -> $D {
}
=end code

For simpler use, we can get a hash also keyed by Date, but whose values
are lists of holiday events:

=begin code
my %us = get-fedholidays-hashlist :$year;
for %us.keys.sort -> $date {
for @(%us{$date}) -> $holiday {
my $n = $holiday.name;
}
}
=end code

=head1 DESCRIPTION

B<Holidays::US::Federal> is a module that provides information on the
Expand All @@ -47,10 +59,11 @@ actually observed as paid holidays off for federal employees is also
found on the site. All the data reflect current laws in Title 5 US
Code Section 6103.

This module provides a routine which provides a hash of the holidays
This module provides two routines which provide a hash of the holidays
for a given year keyed by each holiday's traditional date. Each
key is a Raku C<Date>, and the key's value is a C<class FedHoliday is Date::Event>
object. The data are perpetual for any given year as long as Title 5
key is a Raku C<Date>, and the key's value is either (1)
a C<class FedHoliday is Date::Event> object or a list of the same.
The data are perpetual for any given year as long as Title 5
US Code Section 6103 stays unchanged.

For this collection there should be no overlapping holidays. Each
Expand Down
17 changes: 17 additions & 0 deletions lib/Holidays/US/Federal.rakumod
Expand Up @@ -7,6 +7,23 @@ use Holidays::US::Data;
# The class is instantiated when defined in routine 'calc-holiday-dates'.
class FedHoliday is Date::Event {}

our sub get-fedholidays-hashlist(:$year!, :$debug --> Hash) is export {
# The hash is keyed by Date with value of an array of events on
# that Date.
my %h;
for %fedholidays.keys -> $id {
my FedHoliday $h = calc-holiday-dates :$year, :$id, :$debug;
my $date = $h.date;
if %h{$date}:exists {
%h{$date}.push: $h;
}
else {
%h{$date}.push: $h;
}
}
%h;
}

our sub get-fedholidays(:$year!, :$set-id!, :$debug --> Hash) is export {
my %h;
for %fedholidays.keys -> $id {
Expand Down
6 changes: 3 additions & 3 deletions t/2027-tests.t
Expand Up @@ -51,17 +51,17 @@ for @d -> $D {
is $h.etype, "Holiday", "EType is 100 (holiday)";

my $show-on-cal;
if $d == $do {
if $d eq $do {
# traditional and observed
# show traditional name on calendar
$show-on-cal = $ns;
}
elsif $date == $d {
elsif $date eq $d {
# traditional
# show traditional name on calendar
$show-on-cal = $ns;
}
elsif $date == $do {
elsif $date eq $do {
# observed
# show "Fed. Holiday" on calendar
}
Expand Down
121 changes: 121 additions & 0 deletions t/3-list-tests.t
@@ -0,0 +1,121 @@
use Test;
use Holidays::US::Federal;

# YEAR: 2027

# holidays: id and name:
# 1 New Year's Day
# 2 Martin Luther King's Birthday
# 3 George Washington's Birthday
# 4 Memorial Day
# 5 Juneteenth National Independence Day
# 6 Independence Day
# 7 Labor Day
# 8 Columbus Day
# 9 Veterans Day
# 10 Thanksgiving
# 11 Christmas

my $year = 2027;

my %h = get-fedholidays-hashlist :$year;
for %h.keys -> $D {
my $date = Date.new: $D;
for @(%h{$date}) -> $h {
isa-ok $h, Date::Event;

my Date $d = $h.date;
my $do = $h.date-observed;
my $n = $h.name;
my $ns = $h.short-name;
my $id = $h.id;
is $h.etype(100), "Holiday", "EType is 100 (holiday)";
is $h.etype, "Holiday", "EType is 100 (holiday)";

my $show-on-cal;
if $d eq $do {
# traditional and observed
# show traditional name on calendar
$show-on-cal = $ns;
}
elsif $date eq $d {
# traditional
# show traditional name on calendar
$show-on-cal = $ns;
}
elsif $date eq $do {
# observed
# show "Fed. Holiday" on calendar
}

# tests
die "FATAL: \$id '$id' is an Int!!" if $id ~~ Int;
with $id {
when /^:i new/ {
# new years day
# traditional
is $date, $d;
is $date, $do;
}
when /^:i mlk/ {
# mlk
is $date, $d;
is $date, $do;
}
when /^:i gwb/ {
# gw bday
is $date, $d;
is $date, $do;
}
when /^:i mem/ {
# memorial day
is $date, $d;
is $date, $do;
}
when /^:i june/ {
# juneteenth
# traditional
is $date, $d;
is $date-1, $do;
}
when /^:i jul4/ {
# independence day
# traditional
is $date, $d;
is $date+1, $do;
}
when /^:i lab/ {
# labor day
is $date, $d;
is $date, $do;
}
when /^:i col/ {
# columbus day
is $date, $d;
is $date, $do;
}
when /^:i vet/ {
# veterans day
# traditional
is $date, $d;
is $date, $do;
}
when /^:i thank/ {
# thanksgiving
is $date, $d;
is $date, $do;
}
when /^:i christ/ {
# christmas day
# traditional
is $date, $d;
is $date-1, $do;
}
default {
die "FATAL: Unexpected 'when' \$_: '$_'";
}
}
} # end of the Date array loop
}

done-testing;

0 comments on commit 7292526

Please sign in to comment.