PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/bors/time/meta.php

https://bitbucket.org/Balancer/bors-core
PHP | 102 lines | 75 code | 27 blank | 0 comment | 14 complexity | bb27e21ce9aae1dc3230500775650455 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. class bors_time_meta extends bors_property
  3. {
  4. var $is_null = false;
  5. static function factory($time)
  6. {
  7. $class_name = get_called_class();
  8. if(!is_numeric($time)) // Это дата в произвольном формате
  9. $time = strtotime($time);
  10. return new $class_name($time);
  11. }
  12. function is_active() { return $this->timestamp() >= time(); }
  13. function is_future() { return $this->timestamp() > time(); }
  14. function is_past() { return $this->timestamp() < time(); }
  15. function __toString()
  16. {
  17. if($this->is_null)
  18. return '';
  19. return $this->full();
  20. }
  21. function full() { return $this->date('d.m.Y H:i:s'); }
  22. function full_nobr() { return str_replace(' ', ' ', $this->full()); }
  23. function short($def = '')
  24. {
  25. if($this->is_null)
  26. return $def;
  27. return bors_lib_time::short($this->timestamp(), $def);
  28. }
  29. function short_ny($def = '')
  30. {
  31. if($this->is_null)
  32. return $def;
  33. return bors_lib_time::short_ny($this->timestamp(), $def);
  34. }
  35. function full_hdate()
  36. {
  37. if($this->is_null)
  38. return '';
  39. if($ts = $this->timestamp())
  40. return bors_lib_date::text($ts);
  41. return NULL;
  42. }
  43. function dmy()
  44. {
  45. if($this->is_null)
  46. return '';
  47. if($ts = $this->timestamp())
  48. return date('d.m.Y', $ts);
  49. return NULL;
  50. }
  51. function hm()
  52. {
  53. if($this->is_null)
  54. return '';
  55. if($ts = $this->timestamp())
  56. return date('H:i', $ts);
  57. return NULL;
  58. }
  59. function dmy_hm()
  60. {
  61. if($this->is_null)
  62. return '';
  63. if($ts = $this->timestamp())
  64. return date('d.m.Y H:i', $ts);
  65. return NULL;
  66. }
  67. function fmt($format)
  68. {
  69. if($this->is_null)
  70. return '';
  71. if($ts = $this->timestamp())
  72. return date($format, $ts);
  73. return NULL;
  74. }
  75. }