Date.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ X2zk0Pl/yxRFz/jtj6HhV2E5k2oNy4gFDuI9GTrrCLM=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * date view helper class
  14. *
  15. * Theory of operation:
  16. * - dates are saved based on the timezone set in the admin area
  17. */
  18. namespace Ppb\View\Helper;
  19. use Cube\View\Helper\AbstractHelper;
  20. class Date extends AbstractHelper
  21. {
  22. /**
  23. *
  24. * the format the date will be output in (strftime format required)
  25. *
  26. * @var string
  27. */
  28. protected $_format;
  29. /**
  30. *
  31. * class constructor
  32. *
  33. * @param string $format the format the date will be output in (strftime format required)
  34. */
  35. public function __construct($format)
  36. {
  37. $this->_format = $format;
  38. }
  39. /**
  40. *
  41. * display a formatted date
  42. *
  43. * @param string $date
  44. * @param bool $dateOnly
  45. * @param string $format
  46. * @return string
  47. */
  48. public function date($date, $dateOnly = false, $format = null)
  49. {
  50. if ($date === null) {
  51. return 'n/a';
  52. }
  53. if (!is_numeric($date)) {
  54. $date = strtotime($date);
  55. }
  56. if ($format === null) {
  57. $format = $this->_format;
  58. }
  59. if ($dateOnly){
  60. $format = trim(str_ireplace('%H:%M:%S', '', $format));
  61. }
  62. return strftime($format, $date);
  63. }
  64. }