ea-Geiercode
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file date.inc.php

Documentation is available at date.inc.php

  1. <?php 
  2. /**
  3.  * php functions for date handling
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage code
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: date.inc.php 126 2007-08-16 15:59:55Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * use of extended date functions of adodb library
  29.  */
  30. require_once(eaADODB_DIR 'adodb-time.inc.php');    
  31.  
  32.  
  33. /**
  34.  * checks date an returns formated array
  35.  *
  36.  * @param    string            date
  37.  * @param    format            format
  38.  * @return    boolean/array    false/date array
  39.  */
  40. function checkDateFormat(&$date$format 'DD.MM.YYYY'
  41.     switch ($format{
  42.         case 'DD.MM.YYYY':
  43.             $patternIn '/^\D*(\d{1,2})\D+(\d{1,2})(?:\D+(\d{1,4}))?\D*$/';
  44.             $patternOut 'd.m.Y';
  45.             $vars array(=> 'day'=> 'month'=> 'year');
  46.             break;
  47.         case 'YYYY-MM-DD':
  48.             $patternIn '/^\D*(?:(\d{1,4})\D+)?(\d{1,2})\D+(\d{1,2})\D*$/';
  49.             $patternOut 'Y-m-d';
  50.             $vars array(=> 'day'=> 'month'=> 'year');
  51.             break;
  52.     }
  53.  
  54.     $match array();
  55.     if (!preg_match($patternIn$date$match)) return false;
  56.  
  57.     foreach ($vars as $key => $var{
  58.         switch ($var{
  59.             case 'year':
  60.                 if (!isset($match[$key]|| !$match[$key]$year date('Y');
  61.                 else $year $match[$key];
  62.                 if ($year 100$year += 2000;
  63.                 break;
  64.             case 'month':
  65.                 $month $match[$key];
  66.                 if ($month 12return false;
  67.                 break;
  68.             case 'day':
  69.                 $day $match[$key];
  70.                 if ($day 31return false;
  71.                 break;
  72.         }
  73.     }
  74.     if (!checkdate($month$day$year)) return false;
  75.     
  76.     $time adodb_mktime(000$month$day$year);
  77.     $return['year'adodb_date('Y'$time);
  78.     $return['month'adodb_date('m'$time);
  79.     $return['day'adodb_date('d'$time);
  80.     $return['date'adodb_date($patternOut$time);
  81.     $date $return['date'];
  82.     return $return
  83. }
  84.  
  85. /**
  86.  * returns formated date
  87.  *
  88.  * @param    array    date data
  89.  * @param    format    format
  90.  * @return    string    formated date
  91.  */
  92. function dateFormat(&$data$format 'DD.MM.YYYY'
  93.     switch ($format{
  94.         case 'DD.MM.YYYY':
  95.             $patternOut 'd.m.Y';
  96.             break;
  97.         case 'YYYY-MM-DD':
  98.             $patternOut 'Y-m-d';
  99.             break;
  100.     }
  101.  
  102.     $vars array('month''day''year');
  103.     foreach ($vars as $var
  104.         if (isset($data[$var])) $$var $data[$var];
  105.         else $$var 1;
  106.  
  107.     $time adodb_mktime(000$month$day$year);
  108.     return adodb_date($patternOut$time);
  109. }
  110.  
  111.  
  112. /**
  113.  * split combined month-year string
  114.  *
  115.  * @param    string    combined montz & year
  116.  * @return    array    split data
  117.  */
  118. function splitMonthYear($string
  119.     $match false;
  120.     if (!preg_match('/(\d{4})-(\d{2})/'$string$match)) return false;
  121.     $data['year'$match[1];
  122.     $data['month'$match[2];
  123.     return $data;
  124. }
  125.  
  126. ?>

Documentation generated on Sun, 09 Sep 2007 17:08:18 +0200 by phpDocumentor 1.3.1