You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB
PHP

#!/usr/bin/php
<?php
define('RESET', "\033[0m");
define('BOLD', "\033[1m");
define('INVERT', "\033[7m");
$options = getopt('fwmy', ['full', 'week-day', 'month-day', 'year-day']);
$display_current_year = $options['full'] ?? $options['f'] ?? null;
$options['week-day'] = $options['week-day'] ?? $options['w'] ?? null;
$options['month-day'] = $options['month-day'] ?? $options['m'] ?? null;
$options['year-day'] = $options['year-day'] ?? $options['y'] ?? true;
require 'libdit.php';
$curr_day = get_dit(format: '%d');
$wkd = get_dit(format: '%w');
// Display column names
echo 'déc ';
foreach (['zér', 'uni', 'duo', 'tri', 'qua', 'qui', 'sex', 'sep', 'oct', 'non'] as $day_in_wkd_nbr => $day_in_wkd_abbr) {
if ($day_in_wkd_nbr == $curr_day % 10)
echo BOLD . $day_in_wkd_abbr . RESET;
else
echo $day_in_wkd_abbr;
echo ' ';
}
echo PHP_EOL;
if (isset($display_current_year)) {
$start_day = 1;
$stop_day = 365 + date('L');
} else {
$start_day = ($wkd - 1) * 10;
$stop_day = (($wkd + 2) * 10) - 1;
}
for ($day = $start_day ; $day <= $stop_day ; $day++) {
$septenary_day_abbr = match (date_format(date_create_from_format('!Y z', date('Y') . ' ' . $day - 1), 'N')) {
'1' => 'lun',
'2' => 'mar',
'3' => 'mer',
'4' => 'jeu',
'5' => 'ven',
'6' => 'sam',
'7' => 'dim',
};
if ($day % 10 === 0 AND $day !== $start_day)
echo PHP_EOL;
$i_wkd = intdiv($day, 10);
if ($day % 10 === 0 OR $day === 1)
if ($i_wkd == $wkd)
echo BOLD . str_pad($i_wkd, 2, ' ', STR_PAD_LEFT) . RESET . ' ';
else
echo str_pad($i_wkd, 2, ' ', STR_PAD_LEFT) . ' ';
if ($day === 1)
echo ' ';
if (isset($options['month-day']))
$content = str_pad(date_format(date_create_from_format('!Y z', date('Y') . ' ' . $day - 1), 'j'), 3, ' ', STR_PAD_LEFT);
else if (isset($options['week-day']))
$content = $septenary_day_abbr;
else if (isset($options['year-day']))
$content = str_pad($day, 3, ' ', STR_PAD_LEFT);
if ($day == $curr_day)
echo INVERT . BOLD . $content . RESET . ' ';
else
if ($content === 'lun' OR $content === ' 1')
echo BOLD . $content . RESET . ' ';
else
echo $content . ' ';
}
echo PHP_EOL;