22 'date' =>
'[0-9]{4}-[01][0-9]-[0-3][0-9]',
23 'time' =>
'[0-2][0-9]:[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?',
24 'datetime' =>
'[0-9]{4}-[01][0-9]-[0-3][0-9][T ][0-2][0-9]:[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?Z?',
33 parent::__construct( $params );
35 $this->mType = array_key_exists(
'type', $params )
39 if ( !in_array( $this->mType, [
'date',
'time',
'datetime' ] ) ) {
40 throw new InvalidArgumentException(
"Invalid type '$this->mType'" );
43 if ( $this->mPlaceholder ===
'' ) {
45 $this->mPlaceholder = $this->
msg(
"htmlform-{$this->mType}-placeholder" )->text();
48 $this->mClass .=
' mw-htmlform-datetime-field';
52 $parentList = array_diff( $list, [
'min',
'max' ] );
53 $ret = parent::getAttributes( $parentList );
55 if ( in_array(
'min', $list ) && isset( $this->mParams[
'min'] ) ) {
56 $min = $this->
parseDate( $this->mParams[
'min'] );
61 if ( in_array(
'max', $list ) && isset( $this->mParams[
'max'] ) ) {
62 $max = $this->
parseDate( $this->mParams[
'max'] );
77 if ( !$request->getCheck( $this->mName ) ) {
81 $value = $request->getText( $this->mName );
83 return $date ? $this->
formatDate( $date ) : $value;
87 $p = parent::validate( $value, $alldata );
93 if ( $value ===
'' ) {
101 return $this->
msg(
"htmlform-{$this->mType}-invalid" );
104 if ( isset( $this->mParams[
'min'] ) ) {
105 $min = $this->
parseDate( $this->mParams[
'min'] );
106 if ( $min && $date < $min ) {
108 return $this->
msg(
"htmlform-{$this->mType}-toolow", $this->
formatDate( $min ) );
112 if ( isset( $this->mParams[
'max'] ) ) {
113 $max = $this->
parseDate( $this->mParams[
'max'] );
114 if ( $max && $date > $max ) {
116 return $this->
msg(
"htmlform-{$this->mType}-toohigh", $this->
formatDate( $max ) );
124 $value = trim( $value ??
'' );
125 if ( $value ===
'' ) {
129 if ( $this->mType ===
'date' ) {
130 $value .=
' T00:00:00+0000';
132 if ( $this->mType ===
'time' ) {
133 $value =
'1970-01-01 ' . $value .
'+0000';
137 $date =
new DateTime( $value,
new DateTimeZone(
'GMT' ) );
138 return $date->getTimestamp();
139 }
catch ( Exception $ex ) {
145 switch ( $this->mType ) {
147 return gmdate(
'Y-m-d', $value );
150 return gmdate(
'H:i:s', $value );
153 return gmdate(
'Y-m-d\\TH:i:s\\Z', $value );
165 if ( isset( $this->mParams[
'min'] ) ) {
166 $min = $this->
parseDate( $this->mParams[
'min'] );
171 if ( isset( $this->mParams[
'max'] ) ) {
172 $max = $this->
parseDate( $this->mParams[
'max'] );
178 if ( $this->mType ===
'date' ) {
179 $this->mParent->getOutput()->addModuleStyles(
'mediawiki.widgets.DateInputWidget.styles' );
187 if ( $this->mType ===
'date' ) {
188 return [
'mediawiki.widgets.DateInputWidget' ];
190 return [
'mediawiki.widgets.datetime' ];
A field that will contain a date and/or time.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
shouldInfuseOOUI()
Whether the field should be automatically infused.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
__construct( $params)
Stable to call.
getAttributes(array $list)
Returns the given attributes from the parameters Stable to override.