Data.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Helper;
  9. use Magento\Framework\App\Action\Action;
  10. /**
  11. * Magefan Blog Helper
  12. */
  13. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  14. {
  15. /**
  16. * Retrieve translated & formated date
  17. * @param string $format
  18. * @param string $dateOrTime
  19. * @return string
  20. */
  21. public static function getTranslatedDate($format, $dateOrTime)
  22. {
  23. $time = is_numeric($dateOrTime) ? $dateOrTime : strtotime($dateOrTime);
  24. $month = ['F' => '%1', 'M' => '%2'];
  25. foreach ($month as $from => $to) {
  26. $format = str_replace($from, $to, $format);
  27. }
  28. $date = date($format, $time);
  29. foreach ($month as $to => $from) {
  30. $date = str_replace($from, __(date($to, $time)), $date);
  31. }
  32. return $date;
  33. }
  34. }