Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

[patch-offer] treat 0000-00-00 whether as current or empty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
cybot
Smarty Regular


Joined: 20 Apr 2005
Posts: 83

PostPosted: Mon Jun 11, 2007 5:02 pm    Post subject: [patch-offer] treat 0000-00-00 whether as current or empty Reply with quote

currently html_select_date display 1-1-0 (d-m-y) when providing a time="0000-00-00"

it would be nice if there would be an option to define this behavior

zero_date=asis <- default, like it is now
zero_date=empty <- selects empty options
zero_date=current <- uses current time

i would like to provide a patch for this if it will be applied

also it would be helpfull to tell html_select_date to use 0 as empty values ...

empty_as_zero=false <- default
empty_as_zero=true

this will make it more easy to work with MySQL datetime values
Back to top
View user's profile Send private message
cybot
Smarty Regular


Joined: 20 Apr 2005
Posts: 83

PostPosted: Tue Jun 12, 2007 9:34 am    Post subject: Reply with quote

i added a mysql_mode parameter:

* overriding day/month_value_format
* overriding day/month/year_empty_value
* defines day/month/year_empty if not set
* do not list years from 0 to 2007 if year is 0000

also you now can define day/month/year_empty_value

Code:
Index: libs/plugins/function.html_select_date.php
===================================================================
RCS file: /repository/smarty/libs/plugins/function.html_select_date.php,v
retrieving revision 1.36
diff -u -r1.36 function.html_select_date.php
--- libs/plugins/function.html_select_date.php   6 Mar 2007 20:13:55 -0000   1.36
+++ libs/plugins/function.html_select_date.php   12 Jun 2007 09:15:41 -0000
@@ -83,6 +83,13 @@
     $month_empty     = null;
     $year_empty      = null;
     $extra_attrs     = '';
+    $mysql_mode      = false;
+    $day_empty_value = '';
+    $month_empty_value = '';
+    $year_empty_value = '';
 
     foreach ($params as $_key=>$_value) {
         switch ($_key) {
@@ -120,6 +124,7 @@
             case 'display_years':
             case 'year_as_text':
             case 'reverse_years':
+            case 'mysql_mode':
                 $$_key = (bool)$_value;
                 break;
 
@@ -133,6 +138,24 @@
         }
     }
 
+    if ($mysql_mode) {
+        $month_value_format = "%m";
+        $day_value_format = "%d";
+        $day_empty_value = '00';
+        $month_empty_value = '00';
+        $year_empty_value = '0000';
+
+        if (null === $day_empty) {
+            $day_empty = $day_empty_value;
+        }
+        if (null === $month_empty) {
+            $month_empty = $month_empty_value;
+        }
+        if (null === $year_empty) {
+            $year_empty = $year_empty_value;
+        }
+    }
+
     if (preg_match('!^-\d+$!', $time)) {
         // negative timestamp, use date()
         $time = date('Y-m-d', $time);
@@ -163,7 +186,7 @@
             $start_year = strftime('%Y') - $match[2];
         }
     }
-    if (strlen($time[0]) > 0) {
+    if (strlen($time[0]) > 0 && !($mysql_mode && $time[0] === '0000')) {
         if ($start_year > $time[0] && !isset($params['start_year'])) {
             // force start year to include given date if not explicitly set
             $start_year = $time[0];
@@ -175,7 +198,7 @@
         $month_values = array();
         if(isset($month_empty)) {
             $month_names[''] = $month_empty;
-            $month_values[''] = '';
+            $month_values[''] = $month_empty_value;
         }
         for ($i = 1; $i <= 12; $i++) {
             $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
@@ -222,7 +245,7 @@
         $days = array();
         if (isset($day_empty)) {
             $days[''] = $day_empty;
-            $day_values[''] = '';
+            $day_values[''] = $day_empty_value;
         }
         for ($i = 1; $i <= 31; $i++) {
             $days[] = sprintf($day_format, $i);
@@ -279,7 +304,7 @@
             $yearvals = $years;
             if(isset($year_empty)) {
                 array_unshift($years, $year_empty);
-                array_unshift($yearvals, '');
+                array_unshift($yearvals, $year_empty_value);
             }
             $year_result .= '<select name="' . $year_name . '"';
             if (null !== $year_size){
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP