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

79 lines
1.9KB

  1. <?php
  2. namespace Lc\SovBundle\Component;
  3. class DateComponent
  4. {
  5. public function date($format, $timestamp)
  6. {
  7. setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8');
  8. return strftime($format, $timestamp);
  9. }
  10. public function getNextDay($day)
  11. {
  12. return new \DateTime('next ' . $day);
  13. }
  14. public function getNextDayByNumber($number)
  15. {
  16. return $this->getNextDay($this->getDayByNumber($number, 'en'));
  17. }
  18. public function getDayByNumber($number, $lang = 'fr')
  19. {
  20. return self::getDayByNumberStatic($number, $lang);
  21. }
  22. public static function getDayByNumberStatic($number, $lang = 'fr')
  23. {
  24. if ($lang == 'fr') {
  25. $daysArray = [
  26. 1 => 'Lundi',
  27. 2 => 'Mardi',
  28. 3 => 'Mercredi',
  29. 4 => 'Jeudi',
  30. 5 => 'Vendredi',
  31. 6 => 'Samedi',
  32. 7 => 'Dimanche'
  33. ];
  34. } else {
  35. $daysArray = [
  36. 1 => 'Monday',
  37. 2 => 'Tuesday',
  38. 3 => 'Wednesday',
  39. 4 => 'Thursday',
  40. 5 => 'Friday',
  41. 6 => 'Saturday',
  42. 7 => 'Sunday',
  43. ];
  44. }
  45. if (isset($daysArray[$number])) {
  46. return $daysArray[$number];
  47. }
  48. return '';
  49. }
  50. // getDeliverySlotHour
  51. public function getHour(\DateTime $date)
  52. {
  53. $timestamp = $date->getTimestamp() ;
  54. $hour = $this->date('%kh', $timestamp) ;
  55. $minutes = $this->date('%M', $timestamp) ;
  56. if($minutes != '00') {
  57. $hour .= $minutes ;
  58. }
  59. return $hour ;
  60. }
  61. public function getTotalMinutes(\DateTimeInterface $time): int
  62. {
  63. return (int) $time->format('H') * 60 + (int) $time->format('i');
  64. }
  65. }