Yaron Koren has submitted this change and it was merged.

Change subject: Split off getStringForCurrentTime() from formHTML() code
......................................................................


Split off getStringForCurrentTime() from formHTML() code

Change-Id: I3fbbc5e1ca2e4aa76f8675c6b0c709bac9176c62
---
M includes/SF_FormPrinter.php
1 file changed, 52 insertions(+), 40 deletions(-)

Approvals:
  Yaron Koren: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index 9b620b5..4af32e5 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -366,6 +366,57 @@
        }
 
        /**
+        * Get a string representing the current time, for the time zone
+        * specified in the wiki.
+        */
+       function getStringForCurrentTime( $includeTime, $includeTimezone ) {
+               global $wgLocaltimezone, $wgAmericanDates, $sfg24HourTime;
+
+               if ( isset( $wgLocaltimezone ) ) {
+                       $serverTimezone = date_default_timezone_get();
+                       date_default_timezone_set( $wgLocaltimezone );
+               }
+               $cur_time = time();
+               $year = date( "Y", $cur_time );
+               $month = date( "n", $cur_time );
+               $day = date( "j", $cur_time );
+               if ( $wgAmericanDates == true ) {
+                       $month_names = SFFormUtils::getMonthNames();
+                       $month_name = $month_names[$month - 1];
+                       $curTimeString = "$month_name $day, $year";
+               } else {
+                       $curTimeString = "$year/$month/$day";
+               }
+               if ( isset( $wgLocaltimezone ) ) {
+                       date_default_timezone_set( $serverTimezone );
+               }
+               if ( !$includeTime ) {
+                       return $curTimeString;
+               }
+
+               if ( $sfg24HourTime ) {
+                       $hour = str_pad( intval( substr( date( "G", $cur_time 
), 0, 2 ) ), 2, '0', STR_PAD_LEFT );
+               } else {
+                       $hour = str_pad( intval( substr( date( "g", $cur_time 
), 0, 2 ) ), 2, '0', STR_PAD_LEFT );
+               }
+               $minute = str_pad( intval( substr( date( "i", $cur_time ), 0, 2 
) ), 2, '0', STR_PAD_LEFT );
+               $second = str_pad( intval( substr( date( "s", $cur_time ), 0, 2 
) ), 2, '0', STR_PAD_LEFT );
+               if ( $sfg24HourTime ) {
+                       $curTimeString .= " $hour:$minute:$second";
+               } else {
+                       $ampm = date( "A", $cur_time );
+                       $curTimeString .= " $hour:$minute:$second $ampm";
+               }
+
+               if ( $includeTimezone ) {
+                       $timezone = date( "T", $cur_time );
+                       $curTimeString .= " $timezone";
+               }
+
+               return $curTimeString;
+       }
+
+       /**
         * If the value passed in for a certain field, when a form is
         * submitted, is an array, then it might be from a checkbox
         * or date input - in that case, convert it into a string.
@@ -1411,46 +1462,7 @@
                                                        if ( $input_type == 
'date' || $input_type == 'datetime' ||
                                                                        
$input_type == 'year' ||
                                                                        ( 
$input_type == '' && $form_field->getTemplateField()->getPropertyType() == 
'_dat' ) ) {
-                                                               // Get current 
time, for the time zone specified in the wiki.
-                                                               global 
$wgLocaltimezone;
-                                                               if ( isset( 
$wgLocaltimezone ) ) {
-                                                                       
$serverTimezone = date_default_timezone_get();
-                                                                       
date_default_timezone_set( $wgLocaltimezone );
-                                                               }
-                                                               $cur_time = 
time();
-                                                               $year = date( 
"Y", $cur_time );
-                                                               $month = date( 
"n", $cur_time );
-                                                               $day = date( 
"j", $cur_time );
-                                                               global 
$wgAmericanDates, $sfg24HourTime;
-                                                               if ( 
$wgAmericanDates == true ) {
-                                                                       
$month_names = SFFormUtils::getMonthNames();
-                                                                       
$month_name = $month_names[$month - 1];
-                                                                       
$cur_value_in_template = "$month_name $day, $year";
-                                                               } else {
-                                                                       
$cur_value_in_template = "$year/$month/$day";
-                                                               }
-                                                               if ( isset( 
$wgLocaltimezone ) ) {
-                                                                       
date_default_timezone_set( $serverTimezone );
-                                                               }
-                                                               if ( 
$input_type ==     'datetime' ) {
-                                                                       if ( 
$sfg24HourTime ) {
-                                                                               
$hour = str_pad( intval( substr( date( "G", $cur_time ), 0, 2 ) ), 2, '0', 
STR_PAD_LEFT );
-                                                                       } else {
-                                                                               
$hour = str_pad( intval( substr( date( "g", $cur_time ), 0, 2 ) ), 2, '0', 
STR_PAD_LEFT );
-                                                                       }
-                                                                       $minute 
= str_pad( intval( substr( date( "i", $cur_time ), 0, 2 ) ), 2, '0', 
STR_PAD_LEFT );
-                                                                       $second 
= str_pad( intval( substr( date( "s", $cur_time ), 0, 2 ) ), 2, '0', 
STR_PAD_LEFT );
-                                                                       if ( 
$sfg24HourTime ) {
-                                                                               
$cur_value_in_template .= " $hour:$minute:$second";
-                                                                       } else {
-                                                                               
$ampm = date( "A", $cur_time );
-                                                                               
$cur_value_in_template .= " $hour:$minute:$second $ampm";
-                                                                       }
-                                                               }
-                                                               if ( 
array_key_exists( 'include timezone', $field_args ) ) {
-                                                                       
$timezone = date( "T", $cur_time );
-                                                                       
$cur_value_in_template .= " $timezone";
-                                                               }
+                                                               
$cur_value_in_template = self::getStringForCurrentTime( $input_type == 
'datetime', array_key_exists( 'include timezone', $field_args ) );
                                                        }
                                                }
                                                // If the field is a text 
field, and its default value was set

-- 
To view, visit https://gerrit.wikimedia.org/r/260062
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3fbbc5e1ca2e4aa76f8675c6b0c709bac9176c62
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to