datetimefield.class.inc.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Form\Field;
  19. use \AttributeDatetime;
  20. use \Combodo\iTop\Form\Field\StringField;
  21. /**
  22. * A field for Dates and Date & Times, supporting custom formats
  23. */
  24. class DateTimeField extends StringField
  25. {
  26. protected $sJSDateTimeFormat;
  27. protected $sPHPDateTimeFormat;
  28. /**
  29. *
  30. * @return string
  31. */
  32. public function GetPHPDateTimeFormat()
  33. {
  34. return $this->sPHPDateTimeFormat;
  35. }
  36. /**
  37. *
  38. * @param string $sFormat
  39. * @return \Combodo\iTop\Form\Field\DateTimeField
  40. */
  41. public function SetPHPDateTimeFormat($sDateTimeFormat)
  42. {
  43. $this->sPHPDateTimeFormat = $sDateTimeFormat;
  44. return $this;
  45. }
  46. /**
  47. *
  48. * @return string
  49. */
  50. public function GetJSDateTimeFormat()
  51. {
  52. return $this->sDateTimeFormat;
  53. }
  54. /**
  55. *
  56. * @param string $sFormat
  57. * @return \Combodo\iTop\Form\Field\DateTimeField
  58. */
  59. public function SetJSDateTimeFormat($sDateTimeFormat)
  60. {
  61. $this->sDateTimeFormat = $sDateTimeFormat;
  62. return $this;
  63. }
  64. public function GetDisplayValue()
  65. {
  66. return AttributeDatetime::GetFormat()->Format($this->currentValue);
  67. }
  68. }