Author: benj
Date: Thu Jan 12 17:13:33 2017
New Revision: 1781

URL: http://svn.gna.org/viewcvs/gdtc?rev=1781&view=rev
Log:
Handle time gracefully


Modified:
    trunk/gdtc/include/utils.php

Modified: trunk/gdtc/include/utils.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/utils.php?rev=1781&r1=1780&r2=1781&view=diff
==============================================================================
--- trunk/gdtc/include/utils.php        (original)
+++ trunk/gdtc/include/utils.php        Thu Jan 12 17:13:33 2017
@@ -607,38 +607,38 @@
 function arg2sqldate ( $value, $sql_syntax = true )
 {
     if ( ! $value || $value == 'NULL' )
-    {
-       if ( $sql_syntax )
-           return "NULL";
-       else
-           return '';
-    }    
+        {
+            if ( $sql_syntax )
+                return "NULL";
+            else
+                return '';
+        }    
 
     // Convert dd/mm/yyyy to yyyy-mm-dd
-    if ( preg_match ( '/([0-9]*)\/([0-9]*)\/([0-9]*)/', $value, $matches ) )
-    {
-       /* That's lame but I could not find another way to say that,
-        * say, 07 == 2007 and 69 == 1969. */
-       if ( $matches [ 3 ] != '0000' && $matches [ 3 ] < 15 )
-       {
-           $matches [ 3 ] = 2000 + $matches [ 3 ];
-       }
-       else if ( $matches [ 3 ] != '0000' && $matches [ 3 ] < 100 )
-       {
-           $matches [ 3 ] = 1900 + $matches [ 3 ];
-       }
-       $value = $matches [ 3 ] . '-' . $matches [ 2 ] . '-' . $matches [ 1 ]; 
-    }
-
-    if ( preg_match ( '/([0-9]*):([0-9]*):?([0-9]*)?/', $value, $matches ) )
-    {
-       $value .= ' ' . $matches [ 1 ] . '-' . $matches [ 2 ];
-    }   
+       if ( preg_match ( '/([0-9]*)\/([0-9]*)\/([0-9]*)/', $value, $matches ) )
+        {
+            /* That's lame but I could not find another way to say that,
+             * say, 07 == 2007 and 69 == 1969. */
+            if ( $matches [ 3 ] != '0000' && $matches [ 3 ] < 15 )
+                {
+                    $matches [ 3 ] = 2000 + $matches [ 3 ];
+                }
+            else if ( $matches [ 3 ] != '0000' && $matches [ 3 ] < 100 )
+                {
+                    $matches [ 3 ] = 1900 + $matches [ 3 ];
+                }
+            $ret = $matches [ 3 ] . '-' . $matches [ 2 ] . '-' . $matches [ 1 
]; 
+       
+            if ( preg_match ( '/ ([0-9]*):([0-9]*):([0-9]*) *$/', $value, 
$matches ) )
+                {
+                    $ret .= ' ' . $matches [ 1 ] . ':' . $matches [ 2 ] . ':' 
. $matches [ 3 ];
+                }
+        }
     
     if ( $sql_syntax )
-       return "'$value'";
+        return "'$ret'";
     else
-       return $value;
+        return $ret;
 }
 
 


_______________________________________________
Gdtc-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gdtc-commits

Reply via email to