Source for file class.TIME.php

Documentation is available at class.TIME.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * Stellt verschiedene Funktionen zum Umrechen der SQL-Zeit zur Verfügung
  6.  *
  7.  * @author kay koch
  8.  * @package src
  9.  * @since 04.2005
  10.  * @subpackage tools
  11.  * @version 1.0
  12.  */
  13.  
  14. if (version_compare(PHP_VERSION'5')) {
  15.     die('This file was generated for PHP 5');
  16. }
  17.  
  18. /* user defined includes */
  19. // section -64--88-122--2-7e76ee3:1035fed717c:-7ff5-includes begin
  20. // section -64--88-122--2-7e76ee3:1035fed717c:-7ff5-includes end
  21.  
  22. /* user defined constants */
  23. // section -64--88-122--2-7e76ee3:1035fed717c:-7ff5-constants begin
  24. // section -64--88-122--2-7e76ee3:1035fed717c:-7ff5-constants end
  25.  
  26. /**
  27.  * Stellt verschiedene Funktionen zum Umrechen der SQL-Zeit zur Verfügung
  28.  *
  29.  * @access public
  30.  * @author kay koch
  31.  * @package src
  32.  * @since 04.2005
  33.  * @subpackage tools
  34.  * @version 1.0
  35.  */
  36. {
  37.     // --- ATTRIBUTES ---
  38.  
  39.     
  40.     /**
  41.      * Array mit deutschen Wochentagen
  42.      *
  43.      * [1] = Montag
  44.      * [2]=Dienstag
  45.      * .
  46.      * .
  47.      * [7]:Sonntag
  48.      *
  49.      * @access private
  50.      * @var array 
  51.      */
  52.     private static $arrWeekdays array("1"=>"Montag""2"=>"Dienstag""3"=>"Mittwoch""4"=>"Donnerstag""5"=>"Freitag""6"=>"Samstag""7"=>"Sonntag");
  53.     private static $arrMonths array("1"=>"Januar","2"=>"Februar","3"=>"März","4"=>"April","5"=>"Mai","6"=>"Juni","7"=>"Juli","8"=>"August","9"=>"September","10"=>"Oktober","11"=>"November","12"=>"Dezember");
  54.     // --- OPERATIONS ---
  55.  
  56.     
  57.     /**
  58.      * Wandelt SQL-Zeitangaben in gewünschte Formatierungen um
  59.      *
  60.      * @access public
  61.      * @author Kay Koch, <kay.koch@gmx.de>
  62.      * @param string 
  63.      * @param string 
  64.      * @return string 
  65.      */
  66.     public static function sqlT2realT($sqlTime$format="%a, %d. %B %Y")
  67.     {
  68.         $returnValue = (string) '';
  69.  
  70.         // section -64--88-122--2-7e76ee3:1035fed717c:-7ff4 begin
  71.         // SQL-Zeit in Jahr, Monat und Tag umwandeln
  72.         list($y$m$dsplit("-"$sqlTime);
  73.         // Formatierung durchführen
  74.         $returnValue strftime($formatmktime(000$m$d$y));
  75.         // Sonntag wird an das Ende der Woche verschoben wenn der Wochentag verlangt war
  76.         if (($format == "%w"AND ($returnValue == 0))
  77.             $returnValue 7;
  78.         // section -64--88-122--2-7e76ee3:1035fed717c:-7ff4 end
  79.  
  80.         return (string) $returnValue;
  81.     }
  82.  
  83.     /**
  84.      * liefert aus einem dem laufenden Tag im Jahr:
  85.      *
  86.      * [0]: Tag im SQL-Format
  87.      * [1]: Wochentag (Mo=1,Di=2...So=7)
  88.      *
  89.      * @access public
  90.      * @author Kay Koch, <kay.koch@gmx.de>
  91.      * @param void 
  92.      * @return array 
  93.      */
  94.     public static function yearDay2SQL($dayInYear)
  95.     {
  96.         $returnValue array();
  97.  
  98.         // section -64--88-122--2-2ea88049:103eaafb81d:-7fd4 begin
  99.         $timestamp mktime(0001$dayInYear)// Unix-Timestamp
  100.         $weekday strftime("%w"$timestamp)// Wochentag
  101.         $returnValue[0strftime("%Y-%m-%d"$timestamp)// Timestamp in SQL-Format
  102.         $returnValue[1($weekday == 07:$weekday// Mo=1, Di=2 ... So=7;
  103.         // section -64--88-122--2-2ea88049:103eaafb81d:-7fd4 end
  104.  
  105.         return (array) $returnValue;
  106.     }
  107.  
  108.     /**
  109.      * startet einen Timer zur überprüfung der Laufzeit
  110.      *
  111.      * @access public
  112.      * @author Kay Koch, <kay.koch@gmx.de>
  113.      * @param string 
  114.      * @return int 
  115.      */
  116.     public static function start_timer($event)
  117.     {
  118.         $returnValue = (int) 0;
  119.  
  120.         // section -64--88-122--2-5c2c8d5:103f4c97e55:-7fdb begin
  121.         list($low$highexplode(" "microtime());
  122.         $returnValue $high $low;
  123.         // flush();
  124.         // $t = src_tools_TIME::start_timer("");
  125.         // section -64--88-122--2-5c2c8d5:103f4c97e55:-7fdb end
  126.  
  127.         return (int) $returnValue;
  128.     }
  129.  
  130.     /**
  131.      * gibt die Laufzeit seit start_timer, bzw. sich selbst  aus
  132.      *
  133.      * @access public
  134.      * @author Kay Koch, <kay.koch@gmx.de>
  135.      * @param int 
  136.      * @param string 
  137.      * @return float 
  138.      */
  139.     public static function next_timer($start$event)
  140.     {
  141.         $returnValue = (float) 0.0;
  142.  
  143.         // section -64--88-122--2-5c2c8d5:103f4c97e55:-7fd8 begin
  144.         list($low$highexplode(" "microtime());
  145.         $returnValue $high $low;
  146.         $used $returnValue $start;
  147.         printf("<br>$event: %8.4f Sekunden<br>\n"$used);
  148.         $f substr($_SERVER["SCRIPT_NAME"]1);
  149.         Print "letzte Änderung: " strftime("%A, %d.%m %Y - %H:%Mh"filemtime(basename($_SERVER["SCRIPT_NAME"])));
  150.         // flush();
  151.         //$t = src_tools_TIME::next_timer ($t, "benötigte Zeit für den Seitenaufbau");
  152.         // section -64--88-122--2-5c2c8d5:103f4c97e55:-7fd8 end
  153.  
  154.         return (float) $returnValue;
  155.     }
  156.  
  157.     /**
  158.      * wandelt den Wochentag (zahl) in einen Wochentag (Name) um
  159.      *
  160.      * @access public
  161.      * @author Kay Koch, <kay.koch@gmx.de>
  162.      * @param int 
  163.      * @return string 
  164.      */
  165.     public static function dayNr2dayName($weekday)
  166.     {
  167.         $returnValue = (string) '';
  168.  
  169.         // section -64--88-122--2-556c3468:1044bd6a64b:-7fc0 begin
  170.         $returnValue self::$arrWeekdays[$weekday];
  171.         // section -64--88-122--2-556c3468:1044bd6a64b:-7fc0 end
  172.  
  173.         return (string) $returnValue;
  174.     }
  175.  
  176.     /**
  177.      * liefert ein OptionList mit den Wochentagen aus
  178.      *
  179.      * @access public
  180.      * @author Kay Koch, <kay.koch@gmx.de>
  181.      * @param int 
  182.      * @return string 
  183.      */
  184.     public static function getWeekOL($weekday="")
  185.     {
  186.         $returnValue = (string) '';
  187.  
  188.         // section -64--88-122--2--5ee49331:10456be0103:-7fbc begin
  189.  
  190.         foreach(self::$arrWeekdays as $key=>$dayName{
  191.             $selected ($weekday == $key"SELECTED" "";
  192.             $returnValue .= "<option $selected value='$key'>$dayName</option>\n";
  193.         }
  194.         // section -64--88-122--2--5ee49331:10456be0103:-7fbc end
  195.  
  196.         return (string) $returnValue;
  197.     }
  198.  
  199.     /**
  200.      * liefert ein OptionList mit den Monaten aus
  201.      *
  202.      * @access public
  203.      * @author Kay Koch, <kay.koch@gmx.de>
  204.      * @param int 
  205.      * @return string 
  206.      */
  207.     public static function getMonthOL($month="")
  208.     {
  209.         $returnValue = (string) '';
  210.  
  211.         // section -64--88-122--2--5ee49331:10456be0103:-7fbc begin
  212.  
  213.         foreach(self::$arrMonths as $key=>$monthName{
  214.             $selected ($month == $key"SELECTED" "";
  215.             $returnValue .= "<option $selected value='$key'>$monthName</option>\n";
  216.         }
  217.         // section -64--88-122--2--5ee49331:10456be0103:-7fbc end
  218.  
  219.         return (string) $returnValue;
  220.     }
  221.     /**
  222.      * liefert ein OptionList mit den Tagen eines Monats aus
  223.      *
  224.      * @access public
  225.      * @author Kay Koch, <kay.koch@gmx.de>
  226.      * @param int 
  227.      * @return string 
  228.      */
  229.     public static function getDayOL($vDay="",$maxDay=31)
  230.     {
  231.         $returnValue = (string) '';
  232.  
  233.         // section -64--88-122--2--5ee49331:10456be0103:-7fbc begin
  234.  
  235.         for$day 1$day<=$maxDay$day++{
  236.             $selected ($day == $vDay"SELECTED" "";
  237.             $returnValue .= "<option $selected value='$day'>$day</option>\n";
  238.         }
  239.         // section -64--88-122--2--5ee49331:10456be0103:-7fbc end
  240.  
  241.         return (string) $returnValue;
  242.     }
  243.     /**
  244.      * liefert ein OptionList mit den Zeiten eines Tages aus
  245.      *
  246.      * @access public
  247.      * @author Kay Koch, <kay.koch@gmx.de>
  248.      * @param int 
  249.      * @return string 
  250.      */
  251.     public static function getHourOL($hour="",$startHour="01:00",$endHour="24:00")
  252.     {
  253.         $returnValue = (string) '';
  254.  
  255.         try
  256.         {
  257.             if($startHour$endHour)
  258.                 throw new Exception ();
  259.             $startHour = (int)substr($startHour,0,3);
  260.             $endHour = (int)substr($endHour,0,3);
  261.             $hour = (int)substr($hour,0,3);
  262.              for ($actHour $startHour$actHour<= $endHour$actHour++){
  263.                  $longHour ($actHour 10)"0".$actHour.":00" $actHour.":00";
  264.                  $selected ($hour == $actHour"SELECTED" "";
  265.                  $returnValue .= "<option $selected value='$longHour'>$longHour h</option>\n";
  266.              }
  267.         catch (Exception $e)
  268.         {
  269.             src_tools_ERROR :: setError($e__METHOD__);
  270.         }
  271.  
  272.         return (string) $returnValue;
  273.     }
  274.  
  275.     /**
  276.      * addiert zu einem SQL-Datum Tage hinzu und liefert das Ergebnis zurück
  277.      *
  278.      * @access public
  279.      * @author Kay Koch, <kay.koch@gmx.de>
  280.      * @param date 
  281.      * @param int 
  282.      * @return date 
  283.      */
  284.     public static function addDays2SQL($sqlTime$days 0)
  285.     {
  286.         $returnValue null;
  287.  
  288.         // section -64--88-60-100--6299d47e:109acba51de:-7ff5 begin
  289.         list($y$m$dsplit("-"$sqlTime);
  290.         $returnValue strftime("%Y-%m-%d"mktime(0,0,0$m$d+$days$y));
  291.         // section -64--88-60-100--6299d47e:109acba51de:-7ff5 end
  292.  
  293.         return $returnValue;
  294.     }
  295.     public static function time2longTime($stunde){
  296.         $returnValue = (string) '';
  297.         //
  298.         if (strlen($stunde== 5)
  299.             $stunde.=":00";
  300.         $returnValue =  $stunde;
  301.         //
  302.         return (string) $returnValue;
  303.     }
  304.     public static function time2shortTime($stunde){
  305.         return (string) substr($stunde,0,5);
  306.     }
  307.     public static function formatDate ($d$m$y{
  308.         return $y "-" sprintf('%02d',$m"-" sprintf('%02d',$d);
  309.     }
  310.     public static function formatHour ($h,$add=0{
  311.         $h +=$add;
  312.         return sprintf('%02d'$h":00";
  313.     }
  314.    /**
  315.     *
  316.     * getFeiertage
  317.     * Karfreitag (beweglicher Feiertag; 2 Tage vor Ostern)
  318.     * Ostersonntag
  319.     * Ostermontag (beweglicher Feiertag; 1 Tag nach Ostern)
  320.     * Maifeiertag (fester Feiertag am 1. Mai)
  321.     * Christi Himmelfahrt (beweglicher Feiertag; 39 Tage nach Ostern)
  322.     * Pfingstsonntag (beweglicher Feiertag; 49 Tage nach Ostern)
  323.     * Pfingstmontag (beweglicher Feiertag; 50 Tage nach Ostern)
  324.     * Fronleichnam (beweglicher Feiertag; 60 Tage nach Ostern)
  325.     * Mariä Himmelfahrt (fester Feiertag am 15. August)
  326.     * Tag der deutschen Einheit(fester Feiertag am 3. Oktober)
  327.    *
  328.    * @ author kaykoch
  329.    * @ access public
  330.    * @ since 1.0 - 20.03 .2007
  331.    * @ return array Feld mit Feiertagen
  332.    */
  333.    public static function getFeiertage({
  334.       $returnValue array ();
  335.       $year date("Y");
  336.       $easterday date("Y-m-d"easter_date($year));
  337.       $returnValue['karfreitag'src_tools_TIME :: addDays2SQL($easterday-2);
  338.       #$returnValue['ostersonntag'] = $easterday;
  339.       $returnValue['ostermontag'src_tools_TIME :: addDays2SQL($easterday1);
  340.       $returnValue['erstermai'$year "-05-01";
  341.       $returnValue['christihimmelfahrt'src_tools_TIME :: addDays2SQL($easterday39);
  342.       #$returnValue['pfingstsonntag'] = src_tools_TIME::addDays2SQL($easterday,49);
  343.       $returnValue['pfingstmontag'src_tools_TIME :: addDays2SQL($easterday50);
  344.       $returnValue['fronleichnam'src_tools_TIME :: addDays2SQL($easterday60);
  345.       #$returnValue['mariahimmelfahrt'] = $year . "-08-15";
  346.       $returnValue['deutscheeinheit'$year "-10-03";
  347.  
  348.       return $returnValue;
  349.    }
  350. /* end of class src_tools_TIME */
  351.  
  352. ?>

Documentation generated on Sat, 24 Mar 2007 10:00:10 +0100 by phpDocumentor 1.3.1