HTMLDateTimeField: Properly handle empty input
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 14 Oct 2016 16:37:10 +0000 (12:37 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 14 Oct 2016 16:39:31 +0000 (12:39 -0400)
i.e. don't parse it as "now" in date or datetime mode.

Bug: T148200
Change-Id: I5a3839540222160e8d7376b5b961147c41d48885

includes/htmlform/fields/HTMLDateTimeField.php

index 66f89f9..3390a56 100644 (file)
@@ -126,6 +126,9 @@ class HTMLDateTimeField extends HTMLTextField {
 
        protected function parseDate( $value ) {
                $value = trim( $value );
+               if ( $value === '' ) {
+                       return false;
+               }
 
                if ( $this->mType === 'date' ) {
                        $value .= ' T00:00:00+0000';
@@ -138,7 +141,7 @@ class HTMLDateTimeField extends HTMLTextField {
                        $date = new DateTime( $value, new DateTimeZone( 'GMT' ) );
                        return $date->getTimestamp();
                } catch ( Exception $ex ) {
-                       return 0;
+                       return false;
                }
        }