1<?php
2
3// Copyright (C) 2010-2018 Combodo SARL
4//
5//   This file is part of iTop.
6//
7//   iTop is free software; you can redistribute it and/or modify
8//   it under the terms of the GNU Affero General Public License as published by
9//   the Free Software Foundation, either version 3 of the License, or
10//   (at your option) any later version.
11//
12//   iTop is distributed in the hope that it will be useful,
13//   but WITHOUT ANY WARRANTY; without even the implied warranty of
14//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//   GNU Affero General Public License for more details.
16//
17//   You should have received a copy of the GNU Affero General Public License
18//   along with iTop. If not, see <http://www.gnu.org/licenses/>
19
20namespace Combodo\iTop\Form\Field;
21
22use Closure;
23
24/**
25 * A field for Dates and Date & Times, supporting custom formats
26 */
27class DateTimeField extends StringField
28{
29	protected $sJSDateTimeFormat;
30	protected $sPHPDateTimeFormat;
31	protected $bDateOnly;
32
33	/**
34	 * Overloaded constructor
35	 *
36	 * @param string $sId
37	 * @param \Closure $onFinalizeCallback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
38	 */
39	public function __construct($sId, Closure $onFinalizeCallback = null)
40	{
41		parent::__construct($sId, $onFinalizeCallback);
42		$this->bDateOnly = false;
43	}
44
45	/**
46	 * Get the PHP format string
47	 *
48	 * @return string
49	 */
50	public function GetPHPDateTimeFormat()
51	{
52		return $this->sPHPDateTimeFormat;
53	}
54
55	/**
56	 *
57	 * @param string $sPHPDateTimeFormat
58	 *
59	 * @return \Combodo\iTop\Form\Field\DateTimeField
60	 */
61	public function SetPHPDateTimeFormat($sPHPDateTimeFormat)
62	{
63		$this->sPHPDateTimeFormat = $sPHPDateTimeFormat;
64
65		return $this;
66	}
67
68	/**
69	 * @return string
70	 */
71	public function GetJSDateTimeFormat()
72	{
73		return $this->sJSDateTimeFormat;
74	}
75
76	/**
77	 *
78	 * @param string $sJSDateTimeFormat
79	 *
80	 * @return \Combodo\iTop\Form\Field\DateTimeField
81	 */
82	public function SetJSDateTimeFormat($sJSDateTimeFormat)
83	{
84		$this->sJSDateTimeFormat = $sJSDateTimeFormat;
85
86		return $this;
87	}
88
89    /**
90     * Set the DateOnly flag
91     *
92     * @param boolean $bDateOnly
93     *
94     * @return \Combodo\iTop\Form\Field\DateTimeField
95     */
96	public function SetDateOnly($bDateOnly)
97	{
98		$this->bDateOnly = $bDateOnly;
99		return $this;
100	}
101
102	/**
103	 * @return bool
104	 */
105	public function IsDateOnly()
106	{
107		return $this->bDateOnly;
108	}
109
110}
111