#!/home/jf/Documents/prog/rakudo/rakudo-2020.12/install/bin/raku  -I../lib
# -*- encoding: utf-8; indent-tabs-mode: nil -*-
#
# Generate test data for the Bahai calendar class
#
# Copyright (C) 2021, Jean Forget, all rights reserved
#
# This library is free software; you can redistribute it and/or modify
# it under the Artistic License 2.0.
#

use Date::Calendar::Bahai;

#list(1, 200, False);
list(167, 169, True);
list(173, 175, True);
list(179, 181, True);

sub list(Int $yr1, Int $yr2, Bool $detail) {
  for $yr1 .. $yr2 -> $year {
    my Date::Calendar::Bahai $first .= new(year => $year + 1, month =>  1, day =>  1);
    my Date::Calendar::Bahai $last  .= new-from-daycount($first.daycount - 1);
    my Int $nb = $last.daycount;
    my Str $type = 'normal';
    if $last.is-leap {
      $type = 'leap';
    }
    say "              # {$year + 1} begins on {$first.day-name} and $year is $type";
    if $detail {
      for 14 .. 19 -> $day {
        aff($year, 20, $day);
      }
      for 1 .. 6 -> $day {
        aff($year + 1, 1, $day);
      }
    }
  }
}

sub aff(Int $year, Int $mois, Int $day) {
  my Date::Calendar::Bahai $date .= new(year => $year, month => $mois, day => $day);
  my Str $tag = '   ';
  my Int $dow = 1 + ($date.daycount + 4) % 7;
  if $dow == 1 {
    # beginning of week
    $tag = 'vvv';
  }
  if $dow == 4 {
    # middle of week
    $tag = '...';
  }
  if $dow == 7 {
    # end of week
    $tag = '^^^';
  }
  say $date.strftime("            , (%04Y, %2m, %2d, %3j, '%04Y-W00-$dow') # $tag %A %d %B %Y");
}
