Thanasoft-H2F/gestion/lib/Helpers/DateHelpers.php

68 lines
2.0 KiB
PHP

<?php
namespace OCA\Gestion\Helpers;
use DateTime;
use DateTimeZone;
use Exception;
use IntlDateFormatter;
class DateHelpers
{
public static function isWeekend(string $dateString): bool
{
try {
$date = new DateTime($dateString);
$dayOfWeek = $date->format('N');
return in_array($dayOfWeek, [6, 7]);
} catch (Exception $e) {
// Handle invalid date strings
return false;
}
}
public static function GetMonthPlainString($month){
$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::FULL,
IntlDateFormatter::NONE,
null,
null,
'MMMM'
);
$date = DateTime::createFromFormat('!m', $month);
$monthString = strtoupper($formatter->format($date));
$normalizedMonth = mb_convert_case($monthString, MB_CASE_UPPER, "UTF-8");
return $normalizedMonth;
}
public static function GetDateWithFormatDayAndMonthPlainString(string $date){
$dateTime = new DateTime($date);
$formattedDate = $dateTime->format('d F');
$formattedDate = str_replace(
array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
array('JANVIER', 'FEVRIER', 'MARS', 'AVRIL', 'MAI', 'JUIN', 'JUILLET', 'AOUT', 'SEPTEMBRE', 'OCTOBRE', 'NOVEMBRE', 'DECEMBRE'),
$formattedDate
);
return $formattedDate;
}
public static function GetFullFactureOrDevisNumberByDate($date,$devisNumber,$prefix){
$year = $date->format('y');
$month = $date->format('m');
$devisNumber = str_pad($devisNumber, 2, '0', STR_PAD_LEFT);
$devisNumber = $prefix . $year . $month . $devisNumber;
return $devisNumber;
}
public static function GetLastDayOfTheMonthOfADate($datetime){
$datetime->modify('last day of this month');
$lastDay = $datetime;
return $lastDay;
}
}