Get dates from death date to 50th anniversary

Aug 27, 2020 PHP

Although it is quite a maniac content, I made a function to get dates from death date to Zhongin (up to 49 days every seven days) and year anniversary (one week to 50th anniversary).

##Development environment MAMP

##code

<?php

function calcTyuin($day)
{
    $tyuin_days = [];
    for ($i = 0; $i <7; $i++) {
        if ($i === 0) {
            $date = date_create($day);
        }
        date_add($date, date_interval_create_from_date_string('7 days'));
        $tyuin_days[] = date_format($date,'Y-m-d');
    }

    return $tyuin_days;
}

function calcNenki($day)
{
    $nenki_days = [];
    $add_years = [1, 2, 6, 12, 16, 24, 32, 49];

    foreach ($add_years as $add_year) {
        $date = date_create($day);
        date_add($date, date_interval_create_from_date_string($add_year .'year'));
        $nenki_days[] = date_format($date,'Y-m-d');
    }

    return $nenki_days;
}

$day = '2020-01-01';
$tyuin = [];
$nenki = [];

$tyuin = calcTyuin($day);
$nenki = calcNenki($day);

// middle shade
foreach ($tyuin as $tyuin_day) {
    echo $tyuin_day ."\n";
}

//death anniversary
foreach ($nenki as $nenki_day) {
    echo $nenki_day ."\n";
}

Comment

We have prepared a function to calculate the shade and a function to calculate the year of birth. I just add the days and the years to calculate it.

In the function that calculates the shade, we used a for statement to add 7 days * 6 times to the reference day and store it in the array. In the function to calculate the year anniversary, an array for addition was prepared in advance, and the years of the array for addition were added to the reference days using the foreach statement and stored in the array.

Next, I will try using a recursive function.