您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DateComponent.php 1.6KB

3 年前
3 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 static function getDayByNumber($number, $lang = 'fr')
  19. {
  20. if ($lang == 'fr') {
  21. $daysArray = [
  22. 1 => 'Lundi',
  23. 2 => 'Mardi',
  24. 3 => 'Mercredi',
  25. 4 => 'Jeudi',
  26. 5 => 'Vendredi',
  27. 6 => 'Samedi',
  28. 7 => 'Dimanche'
  29. ];
  30. } else {
  31. $daysArray = [
  32. 1 => 'Monday',
  33. 2 => 'Tuesday',
  34. 3 => 'Wednesday',
  35. 4 => 'Thursday',
  36. 5 => 'Friday',
  37. 6 => 'Saturday',
  38. 7 => 'Sunday',
  39. ];
  40. }
  41. if (isset($daysArray[$number])) {
  42. return $daysArray[$number];
  43. }
  44. return '';
  45. }
  46. // getDeliverySlotHour
  47. public function getHour(\DateTime $date)
  48. {
  49. $timestamp = $date->getTimestamp() ;
  50. $hour = $this->date('%kh', $timestamp) ;
  51. $minutes = $this->date('%M', $timestamp) ;
  52. if($minutes != '00') {
  53. $hour .= $minutes ;
  54. }
  55. return $hour ;
  56. }
  57. }