# # The labels hash, under an assumed name # my %labels = ( calendar => 'Calendar' , month3 => [ qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) ] , week1 => [ qw(M T W T F S S) ] , add_days => 'Additional Days' , month => [ qw(January February March April May June July August September October November December) ] , title1 => "Year to letter" , title2 => { b => "Beginning of Year", m => "Middle of Year", e => "End of Year" } , title3 => "Month names and day names" , year_ttl => "Year" ); # # Formatting a Gregorian date # $labels{format} = sub { my ($y, $m, $d, $l) = @_; return "$d $labels{month}[$m-1] $y" if ($l eq 'en'); return "$labels{month}[$m-1] $d, $y" }; # # Instructions for use, for greg to rev # $labels{usage1} = <<'EOT';

How to convert $gr_date

Look at the first table. The Gregorian year $y belongs to the interval $begint - $end_of_interval{$begint} and its last two digits are $y2. The cell in the corresponding line and column contains the three letters $word.

Look at the next three tables. The month $labels{month}[$m-1] appears in the $labels{title2}{$part} table, at the head of which is the fomula $labels{year_ttl} - $offset. So you can compute that the French Revolutionary year is $ryear. Of the three letters $word, the letter $letter appears in the same table. The corresponding cell contains two formulas: @formulas. Choose the one that will convert the day number $d into a number in the 1-30 range. That is, up to and including $limit $labels{month}[$m - 1], use the first formula $formulas[0], and later use the second formula $formulas[1]. Since the Gregorian day number is $d, you use $formula, and you get $abridged. The final step consists in retrieving the day's full name and the month's full name in the last table, which gives $rev_date. EOT $labels{usage2} = <<'EOT';

How to convert $gr_date

What about September? The first step is the same, and gives the same three letters $word.

But $labels{month}[8] appears both in the $labels{title2}{m} table, and in the $labels{title2}{e} table. The first one gives two formulas for the day: $formulas[0] and $formulas[1] ($mletter column), and one for the year: $labels{year_ttl} - 1792. The second table gives $formulas[2] for the day ($eletter column) and $labels{year_ttl} - 1791 for the year.

Try the last formula $formulas[2], then the prior one $formulas[1], then the first one $formulas[0], until you have a result greater than or equal to 1.

For $d $labels{month}[8] $y, you would choose $formula, with the corresponding year formula $labels{year_ttl} - $offset, which gives you $abridged, or better $rev_date. EOT # # Instructions for French Rev to Gregorian # $labels{usage3} = <<'EOT';

How to convert $title_date

Look at the first table. The French Revolutionary year $y belongs to the interval $begint - $end_of_interval{$begint} and its last two digits are $y2. The cell in the corresponding line and column contains the two letters $word.

Look at the next two tables. The month $fr_month[$m-1] appears in the $labels{title2}{$part} table. Of the two letters $word, the letter $letter appears in the same table. The corresponding cell contains two formulas: @formulas. Choose the one that will convert the day number $d into a number in the proper range for the Gregorian month. That is, up to and including $limit $fr_month[$m - 1], use the first formula $formulas[0], and later use the second formula $formulas[1]. Since the French Revolutionary day number is $d, you use $formula. Using the year formula next to the column headers, you get $gr_date. EOT $labels{usage4} = <<'EOT';

Special cases

For $labels{add_days}, there is only one formula, which is much simpler.

For $fr_month[3], the cell is split in two, because there are two formulas for the year, $labels{year_ttl} + 1791 and $labels{year_ttl} + 1792.

$fr_month[5] is in both tables. For $fr_month[5] $y, in column $bletter you obtain the $formulas[0] formula, and in column $eletter you obtain the $formulas[1] formula. Except for that, everything else is the same. That is, up to and including $limit $fr_month[5], use the first formula $formulas[0], and later use the second formula $formulas[1]. For example, if you want to convert $title_date, since the French Revolutionary day number is $d, you use $formula, and you get $gr_date. EOT # # do cannot return a list value. Therefore, instead of a hash, we return a # hash reference. # \%labels;