mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 09:52:22 +00:00
This commit is contained in:
+279
-224
@@ -1,225 +1,280 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006 Technikum-Wien
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
|
||||
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
|
||||
* Rudolf Hangl <rudolf.hangl@technikum-wien.at>.
|
||||
*/
|
||||
|
||||
class datum
|
||||
{
|
||||
public $ts_day=86400; // Timestamp eines Tages
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem String im
|
||||
* Format "31.12.2007 14:30"
|
||||
*/
|
||||
public function mktime_datumundzeit($datumundzeit)
|
||||
{
|
||||
if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4}) ([0-9]{2}):([0-9]{2})",$datumundzeit, $regs))
|
||||
return mktime($regs[4],$regs[5],0,$regs[2],$regs[1],$regs[3]);
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem String im
|
||||
* Format "31.12.2007"
|
||||
*/
|
||||
public function mktime_datum($datum)
|
||||
{
|
||||
if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$datum, $regs))
|
||||
{
|
||||
return mktime(0,0,0,$regs[2],$regs[1],$regs[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem Datum im
|
||||
* ISO-Format "2007-01-31"
|
||||
*/
|
||||
public function mktime_fromdate($datum)
|
||||
{
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$datum, $regs))
|
||||
{
|
||||
return mktime(0,0,0,$regs[2],$regs[3],$regs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem String im
|
||||
* Format "2007-01-31 14:30:12"
|
||||
*/
|
||||
public function mktime_fromtimestamp($timestamp)
|
||||
{
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$timestamp, $regs))
|
||||
{
|
||||
return mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Springt von einen UNIX Timestamp ($datum) $wochen nach vor bzw. hinten
|
||||
*/
|
||||
public function jump_week($datum, $wochen)
|
||||
{
|
||||
$stunde_vor=date("G",$datum);
|
||||
// Eine Woche sind 604800 Sekunden
|
||||
$datum+=604800*$wochen;
|
||||
$stunde_nach=date("G",$datum);
|
||||
if ($stunde_nach!=$stunde_vor)
|
||||
$datum+=3600;
|
||||
return $datum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Springt von einen UNIX Timestamp ($datum) $days nach vor bzw. hinten
|
||||
*/
|
||||
public function jump_day($datum, $days)
|
||||
{
|
||||
$stunde_vor=date("G",$datum);
|
||||
// Ein Tag sind 86400 Sekunden
|
||||
$datum+=86400*$days;
|
||||
$stunde_nach=date("G",$datum);
|
||||
if ($stunde_nach!=$stunde_vor)
|
||||
$datum+=3600;
|
||||
return $datum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Konvertiert das ISO Datumsformat (YYYY-MM-DD)
|
||||
* nach (DD.MM.YYYY)
|
||||
*/
|
||||
public function convertISODate($datum)
|
||||
{
|
||||
return (mb_strlen($datum)>0?date('d.m.Y',strtotime($datum)):'');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prueft Uhrzeit auf Gueltigkeit (HH:MM:SS)
|
||||
* @return true wenn ok, false wenn falsches Format
|
||||
*/
|
||||
public function checkUhrzeit($uhrzeit)
|
||||
{
|
||||
if(mb_ereg("([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$",$uhrzeit))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist
|
||||
* @return true wenn ok, false wenn falsches Format
|
||||
*/
|
||||
public function checkDatum($datum)
|
||||
{
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum) || mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert ein Datum im angegeben Format
|
||||
* ToDo: Liefert aktuellen Timestamp wenn Sonderzeichen uebergeben werden
|
||||
* zB '---'
|
||||
* @param $datum
|
||||
* @param $format
|
||||
* @param $strict wenn das Datum aus einem Suchfeld komment, dann strict auf TRUE setzen da sonst
|
||||
* Eintraege wie zB 'last Monday' oder 'a' auch in ein Datum umgewandelt werden.
|
||||
* @return Formatierten Timestamp wenn ok, false im Fehlerfall
|
||||
*/
|
||||
public function formatDatum($datum, $format='Y-m-d H:i:s', $strict=false)
|
||||
{
|
||||
if(trim($datum)=='')
|
||||
return '';
|
||||
|
||||
$ts='';
|
||||
$error=false;
|
||||
|
||||
//2008-12-31
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime(0,0,0,$regs[2],$regs[3],$regs[1]);
|
||||
|
||||
//2008-12-31 12:30
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],0,$regs[2],$regs[3],$regs[1]);
|
||||
|
||||
//2008-12-31 12:30:15
|
||||
if(ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);
|
||||
|
||||
if($ts=='')
|
||||
{
|
||||
//1.12.2008
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})",$datum, $regs))
|
||||
$ts = mktime(0,0,0,$regs[2],$regs[1],$regs[3]);
|
||||
|
||||
//1.12.2008 12:30
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],0,$regs[2],$regs[1],$regs[3]);
|
||||
|
||||
//1.12.2008 12:30:15
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[1],$regs[3]);
|
||||
}
|
||||
|
||||
if($ts=='' && !$strict)
|
||||
{
|
||||
$ts = strtotime($datum);
|
||||
|
||||
if(!$ts || $ts==-1)
|
||||
{
|
||||
//wenn strtotime fehlschlaegt liefert diese -1 zurueck, ab php5.1.0 jedoch false
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($ts!='' && !$error)
|
||||
return date($format, $ts);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/* Copyright (C) 2006 Technikum-Wien
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
|
||||
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
|
||||
* Rudolf Hangl <rudolf.hangl@technikum-wien.at>.
|
||||
*/
|
||||
|
||||
class datum
|
||||
{
|
||||
public $ts_day=86400; // Timestamp eines Tages
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem String im
|
||||
* Format "31.12.2007 14:30"
|
||||
*/
|
||||
public function mktime_datumundzeit($datumundzeit)
|
||||
{
|
||||
if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4}) ([0-9]{2}):([0-9]{2})",$datumundzeit, $regs))
|
||||
return mktime($regs[4],$regs[5],0,$regs[2],$regs[1],$regs[3]);
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem String im
|
||||
* Format "31.12.2007"
|
||||
*/
|
||||
public function mktime_datum($datum)
|
||||
{
|
||||
if(mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$datum, $regs))
|
||||
{
|
||||
return mktime(0,0,0,$regs[2],$regs[1],$regs[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem Datum im
|
||||
* ISO-Format "2007-01-31"
|
||||
*/
|
||||
public function mktime_fromdate($datum)
|
||||
{
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$datum, $regs))
|
||||
{
|
||||
return mktime(0,0,0,$regs[2],$regs[3],$regs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert einen UNIX Timestamp von einem String im
|
||||
* Format "2007-01-31 14:30:12"
|
||||
*/
|
||||
public function mktime_fromtimestamp($timestamp)
|
||||
{
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$timestamp, $regs))
|
||||
{
|
||||
return mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Falsches Datumsformat';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Springt von einen UNIX Timestamp ($datum) $wochen nach vor bzw. hinten
|
||||
*/
|
||||
public function jump_week($datum, $wochen)
|
||||
{
|
||||
$stunde_vor=date("G",$datum);
|
||||
// Eine Woche sind 604800 Sekunden
|
||||
$datum+=604800*$wochen;
|
||||
$stunde_nach=date("G",$datum);
|
||||
if ($stunde_nach!=$stunde_vor)
|
||||
$datum+=3600;
|
||||
return $datum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Springt von einen UNIX Timestamp ($datum) $days nach vor bzw. hinten
|
||||
*/
|
||||
public function jump_day($datum, $days)
|
||||
{
|
||||
$stunde_vor=date("G",$datum);
|
||||
// Ein Tag sind 86400 Sekunden
|
||||
$datum+=86400*$days;
|
||||
$stunde_nach=date("G",$datum);
|
||||
if ($stunde_nach!=$stunde_vor)
|
||||
$datum+=3600;
|
||||
return $datum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Konvertiert das ISO Datumsformat (YYYY-MM-DD)
|
||||
* nach (DD.MM.YYYY)
|
||||
*/
|
||||
public function convertISODate($datum)
|
||||
{
|
||||
return (mb_strlen($datum)>0?date('d.m.Y',strtotime($datum)):'');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prueft Uhrzeit auf Gueltigkeit (HH:MM:SS)
|
||||
* @return true wenn ok, false wenn falsches Format
|
||||
*/
|
||||
public function checkUhrzeit($uhrzeit)
|
||||
{
|
||||
if(mb_ereg("([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$",$uhrzeit))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prueft ob das Datum im Format dd.mm.YYYY oder YYYY-mm-dd ist
|
||||
* @return true wenn ok, false wenn falsches Format
|
||||
*/
|
||||
public function checkDatum($datum)
|
||||
{
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})$",$datum) || mb_ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})$",$datum))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* Prueft und Liefert ein Datum im angegeben Format
|
||||
* fuer die Formatierung wird die Funktion formatDatum verwendet
|
||||
* @param $datum
|
||||
* @param $format
|
||||
* @param $strict wenn das Datum aus einem Suchfeld komment, dann strict auf TRUE setzen da sonst
|
||||
* Eintraege wie zB 'last Monday' oder 'a' auch in ein Datum umgewandelt werden.
|
||||
* @return Formatierten Timestamp wenn ok, false im Fehlerfall
|
||||
*/
|
||||
function checkformatDatum($datum, $format='Y-m-d H:i:s', $strict=false)
|
||||
{
|
||||
|
||||
@list($day, $month, $year) = @explode(".", $datum);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
@list($day, $month, $year) = @explode("-", $datum);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
@list($year, $month, $day) = @explode(".", $datum);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
@list($year, $month, $day) = @explode("-", $datum);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
|
||||
if (strlen($datum)==6)
|
||||
{
|
||||
$year="20".substr($datum,0,2);
|
||||
$month=substr($datum,2,2);
|
||||
$day=substr($datum,4,2);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
}
|
||||
else if (strlen($datum)==8)
|
||||
{
|
||||
$year=substr($datum,0,4);
|
||||
$month=substr($datum,4,2);
|
||||
$day=substr($datum, 6,2);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
|
||||
$year=substr($datum,5,4);
|
||||
$month=substr($datum,3,2);
|
||||
$day=substr($datum, 0,2);
|
||||
if (@checkdate($month, $day, $year))
|
||||
return $this->formatDatum($datum, $format, $strict);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Liefert ein Datum im angegeben Format
|
||||
* ToDo: Liefert aktuellen Timestamp wenn Sonderzeichen uebergeben werden
|
||||
* zB '---'
|
||||
* @param $datum
|
||||
* @param $format
|
||||
* @param $strict wenn das Datum aus einem Suchfeld komment, dann strict auf TRUE setzen da sonst
|
||||
* Eintraege wie zB 'last Monday' oder 'a' auch in ein Datum umgewandelt werden.
|
||||
* @return Formatierten Timestamp wenn ok, false im Fehlerfall
|
||||
*/
|
||||
public function formatDatum($datum, $format='Y-m-d H:i:s', $strict=false)
|
||||
{
|
||||
if(trim($datum)=='')
|
||||
return '';
|
||||
|
||||
$ts='';
|
||||
$error=false;
|
||||
|
||||
//2008-12-31
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime(0,0,0,$regs[2],$regs[3],$regs[1]);
|
||||
|
||||
//2008-12-31 12:30
|
||||
if(mb_ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],0,$regs[2],$regs[3],$regs[1]);
|
||||
|
||||
//2008-12-31 12:30:15
|
||||
if(ereg("([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);
|
||||
|
||||
if($ts=='')
|
||||
{
|
||||
//1.12.2008
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})",$datum, $regs))
|
||||
$ts = mktime(0,0,0,$regs[2],$regs[1],$regs[3]);
|
||||
|
||||
//1.12.2008 12:30
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],0,$regs[2],$regs[1],$regs[3]);
|
||||
|
||||
//1.12.2008 12:30:15
|
||||
if(mb_ereg("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})",$datum, $regs))
|
||||
$ts = mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[1],$regs[3]);
|
||||
}
|
||||
|
||||
if($ts=='' && !$strict)
|
||||
{
|
||||
$ts = strtotime($datum);
|
||||
|
||||
if(!$ts || $ts==-1)
|
||||
{
|
||||
//wenn strtotime fehlschlaegt liefert diese -1 zurueck, ab php5.1.0 jedoch false
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($ts!='' && !$error)
|
||||
return date($format, $ts);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user