Help language development. Donate to The Perl Foundation

Date::Calendar::Persian cpan:JFORGET last updated on 2021-02-22

t/04-conversion.rakutest
#
# Checking the conversions when using the arithmetic calendar
#
use v6.c;
use Test;
use Date::Calendar::Persian;

my @test-data = load-data();

plan 2 × @test-data.elems;

for @test-data -> $datum {
  my ($y-pe, $m-pe, $d-pe, $y-gr, $m-gr, $d-gr) = $datum;

  my Date::Calendar::Persian
          $date-pe;
  my Date $date-gr;

  $date-gr .= new($y-gr, $m-gr, $d-gr);
  $date-pe .= new-from-date($date-gr);

  my Str $expected = sprintf("%04d-%02d-%02d", $y-pe, $m-pe, $d-pe);
  is($date-pe.gist, $expected);
}

for @test-data -> $datum {
  my ($y-pe, $m-pe, $d-pe, $y-gr, $m-gr, $d-gr) = $datum;

  my Date::Calendar::Persian
          $date-pe;
  my Date $date-gr;

  $date-pe .= new(year => +$y-pe, month => +$m-pe, day => +$d-pe);
  $date-gr  = $date-pe.to-date;

  my Str $expected = sprintf("%04d-%02d-%02d", $y-gr, $m-gr, $d-gr);
  is($date-gr.gist, $expected);
}

done-testing;

# Test data were computed by choosing Persian dates (not very randomly),
# applying "/usr/share/emacs/25.1/lisp/calendar/cal-persia.el"
# and then "/usr/share/emacs/25.1/lisp/calendar/calendar.el"
sub load-data {
  return (
         <    1  1  1       622  3 22 >
       , <    1 12 29       623  3 21 >
       , <    2  1  1       623  3 22 >
       , <    2 12 29       624  3 20 >
       , <    3  1  1       624  3 21 >
       , <    3 12 29       625  3 20 >
       , <    4  1  1       625  3 21 >
       , <    4 12 30       626  3 21 >
       , <    5  1  1       626  3 22 >
       , <    5 12 29       627  3 21 >
       , <  450  1  1      1071  3 21 >
       , <  450 12 30      1072  3 20 >
       , <  451  1  1      1072  3 21 >
       , <  451 12 29      1073  3 20 >
       , <  452  1  1      1073  3 21 >
       , <  452 12 29      1074  3 20 >
       , <  453  1  1      1074  3 21 >
       , <  453 12 29      1075  3 20 >
       , <  454  1  1      1075  3 21 >
       , <  454 12 30      1076  3 20 >
       , <  455  1  1      1076  3 21 >
       , <  455 12 29      1077  3 20 >
       , <  456  1  1      1077  3 21 >
       , <  456 12 29      1078  3 20 >
       , <  457  1  1      1078  3 21 >
       , <  457 12 29      1079  3 20 >
       , <  458  1  1      1079  3 21 >
       , <  458 12 30      1080  3 20 >
       , <  459  1  1      1080  3 21 >
       , <  459 12 29      1081  3 20 >
       , <  460  1  1      1081  3 21 >
       , <  460 12 29      1082  3 20 >
       , <  461  1  1      1082  3 21 >
       , <  461 12 29      1083  3 20 >
       , <  462  1  1      1083  3 21 >
       , <  462 12 30      1084  3 20 >
       , < 1395  1  1      2016  3 20 >
       , < 1395 12 30      2017  3 20 >
       , < 1396  1  1      2017  3 21 >
       , < 1396 12 29      2018  3 20 >
       , < 1397  1  1      2018  3 21 >
       , < 1397 12 29      2019  3 20 >
       , < 1398  1  1      2019  3 21 >
       , < 1398 12 29      2020  3 19 >
       , < 1399  1  1      2020  3 20 >
       , < 1399 12 30      2021  3 20 >
       , < 1400  1  1      2021  3 21 >
       , < 1400  1 31      2021  4 20 >
       , < 1400  2  1      2021  4 21 >
       , < 1400  2 31      2021  5 21 >
       , < 1400  3  1      2021  5 22 >
       , < 1400  3 31      2021  6 21 >
       , < 1400  4  1      2021  6 22 >
       , < 1400  4 31      2021  7 22 >
       , < 1400  5  1      2021  7 23 >
       , < 1400  5 31      2021  8 22 >
       , < 1400  6  1      2021  8 23 >
       , < 1400  6 31      2021  9 22 >
       , < 1400  7  1      2021  9 23 >
       , < 1400  7 30      2021 10 22 >
       , < 1400  8  1      2021 10 23 >
       , < 1400  8 30      2021 11 21 >
       , < 1400  9  1      2021 11 22 >
       , < 1400  9 30      2021 12 21 >
       , < 1400 10  1      2021 12 22 >
       , < 1400 10 30      2022  1 20 >
       , < 1400 11  1      2022  1 21 >
       , < 1400 11 30      2022  2 19 >
       , < 1400 12  1      2022  2 20 >
       , < 1400 12 29      2022  3 20 >
       , < 1401  1  1      2022  3 21 >
       , < 1401 12 29      2023  3 20 >
       , < 1402  1  1      2023  3 21 >
       , < 1402 12 29      2024  3 19 >
       , < 1403  1  1      2024  3 20 >
       , < 1403 12 29      2025  3 19 >
       , < 1404  1  1      2025  3 20 >
       , < 1404 12 30      2026  3 20 >
  );
}