DateUtils.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Lc\ShopBundle\Services ;
  3. class DateUtils
  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. 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. }
  31. else {
  32. $daysArray = [
  33. 1 => 'Monday',
  34. 2 => 'Tuesday',
  35. 3 => 'Wednesday',
  36. 4 => 'Thursday',
  37. 5 => 'Friday',
  38. 6 => 'Saturday',
  39. 7 => 'Sunday',
  40. ] ;
  41. }
  42. if(isset($daysArray[$number])) {
  43. return $daysArray[$number] ;
  44. }
  45. return '' ;
  46. }
  47. }