core
[ class tree: core ] [ index: core ] [ all elements ]

Source for file DateFormatter.class.php

Documentation is available at DateFormatter.class.php

  1. <?php
  2. /**
  3.  * @package core
  4.  */
  5. ifdefined"LANG" ) )
  6.   /**
  7.    * Including language specific messages.
  8.    */
  9.   include_onceCLASSPATH."core/lang_spec_values/".LANG.".inc.php" );
  10. else
  11. {
  12.   echo "<h3>You have to define the constant LANG!</h3>\r\n";
  13.   echo "Example for german: define( 'LANG', 'de' );\r\n";
  14.   exit();
  15. }
  16.  
  17. /**
  18.  *
  19.  */
  20. require_once CLASSPATH."data_structures/ABSTObject.class.php";
  21.  
  22. /**
  23.  * Carries the dayscount of each month.
  24.  *
  25.  * @var    array  $daysPerMonth 
  26.  * @access public
  27.  */
  28. $GLOBALS["daysPerMonth"array(
  29.                                   31// January
  30.                                   28// February
  31.                                   31// March
  32.                                   30// April
  33.                                   31// May
  34.                                   30// June
  35.                                   31// July
  36.                                   31// August
  37.                                   30// September
  38.                                   31// October
  39.                                   30// November
  40.                                   31  // December
  41.                                 );
  42. /**
  43.  * The number of seconds in a minute. This is useful with the calculation of
  44.  * dates in unix timestamp.
  45.  */
  46. define"MINUTEINSECONDS"60     );
  47. /**
  48.  * The number of seconds in a hour. This is useful with the calculation of
  49.  * dates in unix timestamp.
  50.  */
  51. define"HOURINSECONDS",   3600   );
  52. /**
  53.  * The number of seconds in a day. This is useful with the calculation of
  54.  * dates in unix timestamp.
  55.  */
  56. define"DAYINSECONDS",    86400  );
  57. /**
  58.  * The number of seconds in a week. This is useful with the calculation of
  59.  * dates in unix timestamp.
  60.  */
  61. define"WEEKINSECONDS",   604800 );
  62. /**
  63.  * Static methods mainly to compute dates depending on weeknum for industrial
  64.  * programs. The base standard is ISO 8601
  65.  * (e.g. for german economy time pattern)
  66.  * http://en.wikipedia.org/wiki/ISO_8601#Week_dates
  67.  *
  68.  * @static
  69.  * @package   core
  70.  * @version   0.2.11
  71.  *
  72.  * @author    Daniel Plücken <daniel@debakel.net>
  73.  *
  74.  * @license   http://www.gnu.org/copyleft/lesser.html
  75.  *             GNU Lesser General Public License
  76.  * @copyright Copyright (c) 2003 Daniel Plücken <daniel@debakel.net>
  77.  *
  78.  *  This library is free software; you can redistribute it and/or
  79.  *  modify it under the terms of the GNU Lesser General Public
  80.  *  License as published by the Free Software Foundation; either
  81.  *  version 2.1 of the License.
  82.  *
  83.  *  This library is distributed in the hope that it will be useful,
  84.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  85.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  86.  *  GNU Lesser General Public License for more details.
  87.  *
  88.  *  You should have received a copy of the GNU Lesser General
  89.  *  Public License along with this library; if not, write to the
  90.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  91.  *  Boston, MA 02111-1307 USA
  92.  */
  93. class DateFormatter extends ABSTObject
  94. {
  95.  
  96.   // Constructor
  97.   function DateFormatter()
  98.   {}
  99.  
  100.  
  101.  
  102.   /**
  103.    * Returns a timestamp from ISO date and time
  104.    *
  105.    * @static
  106.    * @version 1.0
  107.    * @since   0.2.0
  108.    * @author  Daniel Plücken <daniel@debakel.net>
  109.    * @access  public
  110.    * @param   string  $str_iso_date 
  111.    * @return  integer 
  112.    */
  113.   function getTimestampFromISODate$str_iso_date )
  114.   {
  115.     // [0] -> date
  116.     // [1] -> time
  117.     $tmp_arr explode" "$str_iso_date );
  118.  
  119.     $ymd_arr explode"-"$tmp_arr[0);
  120.     $hms_arr explode":"$tmp_arr[1);
  121.  
  122.     return mktime(
  123.               intval$hms_arr[0),
  124.               intval$hms_arr[1),
  125.               intval$hms_arr[2),
  126.               intval$ymd_arr[1),
  127.               intval$ymd_arr[2),
  128.               intval$ymd_arr[0)
  129.                  );
  130.   }
  131.  
  132.  
  133.  
  134.    /**
  135.     * Returns a timestamp from a date.
  136.     *
  137.     * @todo    am and pm is unaccounted yet
  138.     * @static
  139.     * @version 1.0
  140.     * @since   0.2.1
  141.     * @see     http://www.php.net/manual/en/function.mktime.php#67996
  142.     * @see     http://php.net/date#AEN21898
  143.     * @author  nicky
  144.     * @author  Daniel Plücken <daniel@debakel.net> (only placed here)
  145.     * @access  public
  146.     * @param   string  $strStr     The date to konvert to unix timestamp.
  147.     * @param   string  $strPattern The pattern how interpret the date to konvert
  148.     *                               it to unix timestamp.
  149.     * @return  integer 
  150.     */
  151.     function str2time$strStr$strPattern null )
  152.     {
  153.         // an array of the valide date characters,
  154.         // see: http://php.net/date#AEN21898
  155.         $arrCharacters array(
  156.             'd'// day
  157.             'm'// month
  158.             'y'// year, 2 digits
  159.             'Y'// year, 4 digits
  160.             'H'// hours
  161.             'i'// minutes
  162.             's'  // seconds
  163.         );
  164.         // transform the characters array to a string
  165.         $strCharacters implode(''$arrCharacters);
  166.  
  167.         // splits up the pattern by the date characters to get an array of the
  168.         // delimiters between the date characters
  169.         $arrDelimiters preg_split('~['.$strCharacters.']~'$strPattern);
  170.         // transform the delimiters array to a string
  171.         $strDelimiters quotemeta(implode(''array_unique($arrDelimiters)));
  172.  
  173.         // splits up the date by the delimiters to get an array of the
  174.         // declaration
  175.         $arrStr     preg_split('~['.$strDelimiters.']~'$strStr);
  176.         // splits up the pattern by the delimiters to get an array of the used
  177.         // characters
  178.         $arrPattern preg_split('~['.$strDelimiters.']~'$strPattern);
  179.  
  180.         // if the numbers of the two array are not the same, return false,
  181.         // because the cannot belong together
  182.         if (count($arrStr!== count($arrPattern)) {
  183.             return false;
  184.         }
  185.  
  186.         // creates a new array which has the keys from the $arrPattern array and
  187.         // the values from the $arrStr array
  188.         $arrTime array();
  189.         for ($i 0;$i count($arrStr);$i++{
  190.             $arrTime[$arrPattern[$i]] $arrStr[$i];
  191.         }
  192.  
  193.         // gernerates a 4 digit year declaration of a 2 digit one by using the
  194.         // current year
  195.         if (isset($arrTime['y']&& !isset($arrTime['Y'])) {
  196.             $arrTime['Y'substr(date('Y')02$arrTime['y'];
  197.         }
  198.  
  199.         // if a declaration is empty, it will be filled with the current date
  200.         // declaration
  201.         foreach ($arrCharacters as $strCharacter{
  202.             if (empty($arrTime[$strCharacter])) {
  203.                 $arrTime[$strCharacterdate($strCharacter);
  204.             }
  205.         }
  206.  
  207.         // checks if the date is a valide date
  208.         if (!checkdate($arrTime['m']$arrTime['d']$arrTime['Y'])) {
  209.             return false;
  210.         }
  211.  
  212.         // returns the timestamp
  213.         return mktime(
  214.                        $arrTime['H'],
  215.                        $arrTime['i'],
  216.                        $arrTime['s'],
  217.                        $arrTime['m'],
  218.                        $arrTime['d'],
  219.                        $arrTime['Y']
  220.                      );
  221.     }
  222.  
  223.  
  224.  
  225.  
  226.   /**
  227.    * Returns a language specified date based on the constant LANG with the rules
  228.    * of a date()-function.
  229.    *
  230.    * @static
  231.    * @version 1.0
  232.    * @since   0.1.9
  233.    * @author  Daniel Plücken <daniel@debakel.net>
  234.    * @access  public
  235.    * @param   string  $string 
  236.    * @param   integer $timestamp_or_isodate The unix-timestamp or ISO-8601 date
  237.    *                                          that should be transformed.
  238.    * @return  string 
  239.    */
  240.   function getTranslatedDate$string$timestamp_or_isodate )
  241.   {
  242.     $out "";
  243.     if preg_match"!^(?:\d|[1-9]\d+)$!"$timestamp_or_isodate ) )
  244.     {
  245.         for $i 0$i strlen$string )$i++ )
  246.         {
  247.            $char substr$string$i);
  248.            if preg_match"![aAbdgGhHiIjLmnOrsStTUyYzZ]!"$char ) )
  249.               $out .= date$char$timestamp );
  250.            else
  251.            {
  252.               switch$char )
  253.               {
  254.                    // isodate
  255.                    case "c":
  256.                         // TODO: isodate from timestamp
  257.                         break;
  258.                    // short dayname of the week
  259.                    case "D":
  260.                         $out .= DateFormatter
  261.                               ::getWeekdaynameFromTimestamp$timestamp );
  262.                         break;
  263.                    // monthname
  264.                    case "F";
  265.                         $tmp  intvaldate"n"$timestamp ) );
  266.                         if LANG == "de" )
  267.                            $out .= utf8_decode$GLOBALS["monthNames"][$tmp-1);
  268.                         else
  269.                            $out .= $GLOBALS["monthNames"][$tmp-1];
  270.                         break;
  271.                    // monthname in short form
  272.                    case "M":
  273.                         $tmp  intvaldate"n"$timestamp ) );
  274.                         if LANG == "de" )
  275.                            $out .= utf8_decode$GLOBALS["monthNamesShort"][$tmp-1);
  276.                         else
  277.                            $out .= $GLOBALS["monthNamesShort"][$tmp-1];
  278.                         break;
  279.                    /*
  280.                    // suffix day numbers ( st, nd, rd, th )
  281.                    case "S":
  282.                         $out .= "";
  283.                         break;
  284.                    */
  285.                    // number of day of the week ( ISO 8601 )
  286.                    case "w":
  287.                         $out .= DateFormatter
  288.                               ::extractWeekDayFromTimestamp$timestamp );
  289.                         break;
  290.                    // number of weeknum of the year ( ISO 8601 )
  291.                    case "W":
  292.                         $out .= DateFormatter
  293.                               ::extractWeeknumFromTimestamp$timestamp );
  294.                         break;
  295.  
  296.                    default:
  297.                          $out .= $char;
  298.                    break;
  299.               }
  300.            }
  301.         // for
  302.     }
  303.     # Transforming ISODATE
  304.     else
  305.     {
  306.         $datetime_arr explode" "$timestamp_or_isodate );
  307.         $date_arr explode"-"$datetime_arr[0);
  308.         $time_arr explode":"$datetime_arr[1);
  309.  
  310.         for $i 0$i strlen$string )$i++ )
  311.         {
  312.             $char substr$string$i);
  313.             switch $char )
  314.             {
  315.                 // ante meridiem and post meridiem from isodate in lower case
  316.                 case "a":
  317.                      $tmp_int intval$time_arr[0);
  318.                      if $tmp_int && $tmp_int 13 )
  319.                         return "am";
  320.                      else
  321.                         return "pm";
  322.                      break;
  323.                 // ante meridiem and post meridiem from isodate in upper case
  324.                 case "A":
  325.                      $tmp_int intval$time_arr[0);
  326.                      if $tmp_int && $tmp_int 13 )
  327.                         return "AM";
  328.                      else
  329.                         return "PM";
  330.                      break;
  331.                 case "B":
  332.                      // TODO: Swatch internet time from isodate
  333.                      break;
  334.                 case "c":
  335.                      // TODO: isodate from isodate
  336.                      break;
  337.                 case "d":
  338.                      $out .= $date_arr[2];
  339.                      break;
  340.                 // short dayname of the week
  341.                 case "D":
  342.                      // TODO: short weekday name from isodate
  343.                      break;
  344.                 // monthname
  345.                 case "F":
  346.                      // TODO: monthname from isodate
  347.                      break;
  348.                 // twelve hour format without leading zero
  349.                 case "g":
  350.                      $tmp_arr array(
  351.                                         121234567891011,
  352.                                         121234567891011
  353.                                       );
  354.                      $out .= $tmp_arrintval($time_arr[0]];
  355.                      break;
  356.                 // twenty four hour format without leading zero
  357.                 case "G":
  358.                      $out .= intval$time_arr[0);
  359.                      break;
  360.                 // twelve hour format with leading zero
  361.                 case "h":
  362.                      $tmp_arr array(
  363.                                         121234567891011,
  364.                                         121234567891011
  365.                                       );
  366.                      $tmp_int intval($time_arr[0]);
  367.                      if $tmp_int 10 )
  368.                         $out .= "0".$tmp_int;
  369.                      else
  370.                         $out .= $tmp_int;
  371.                      break;
  372.                 // twenty four hour format with leading zero
  373.                 case "H":
  374.                      $out .= $time_arr[0];
  375.                      break;
  376.                 // minute with leading zero
  377.                 case "i":
  378.                      $out .= $time_arr[1];
  379.                      break;
  380.                 // whether date is in summertime
  381.                 case "I":
  382.                      // TODO: whether date is in summertime from isodate
  383.                      break;
  384.                 // is leap year
  385.                 case "L":
  386.                      $out .= intvalDateFormatter::isLeapYear$date_arr[0) );
  387.                      break;
  388.                 // month with leading zero
  389.                 case "m":
  390.                      $out .= $date_arr[1];
  391.                      break;
  392.                 // monthname in short form
  393.                 case "M":
  394.                      // TODO: monthname in shortform from isodate
  395.                      break;
  396.                 // month without leading zero
  397.                 case "n":
  398.                      $out .= intval$date_arr[1);
  399.                      break;
  400.                 //
  401.                 case "O":
  402.                      break;
  403.                 //
  404.                 case "r":
  405.                      break;
  406.                 //
  407.                 case "s":
  408.                      $out .= $time_arr[2];
  409.                      break;
  410.                 //
  411.                 case "S";
  412.                      break;
  413.                 // days count of the month an year from isodate
  414.                 case "t":
  415.                      $out .= DateFormatter::getDaysCountOfMonthOfYear(
  416.                                                  intval($date_arr[1]),
  417.                                                  $date_arr[0]
  418.                                                                       );
  419.                      break;
  420.                 //
  421.                 case "T";
  422.                      break;
  423.                 //
  424.                 case "U";
  425.                      break;
  426.                 /*
  427.                 // suffix day numbers ( st, nd, rd, th )
  428.                 case "S":
  429.                      $out .= "";
  430.                      break;
  431.                 */
  432.                 // number of day of the week ( ISO 8601 )
  433.                 case "w":
  434.                      // TODO: number of day of the week ( ISO 8601 )
  435.                      break;
  436.                 // number of weeknum of the year ( ISO 8601 )
  437.                 case "W":
  438.                      // TODO: number of weeknum of the year ( ISO 8601 )
  439.                      break;
  440.                 //
  441.                 case "y";
  442.                      $out .= substr$date_arr[0]);
  443.                      break;
  444.                 //
  445.                 case "Y";
  446.                      $out .= $date_arr[0];
  447.                      break;
  448.                 //
  449.                 case "z";
  450.                      break;
  451.                 //
  452.                 case "Z";
  453.                      break;
  454.  
  455.                 default:
  456.                       $out .= $char;
  457.                 break;
  458.             }
  459.         }
  460.     }
  461.  
  462.     return $out;
  463.   }
  464.  
  465.  
  466.  
  467.   /**
  468.    * Returns the weekday as number of the week from given unix-timestamp.
  469.    * Monday will be returned as zero. Sunday will returned as six.
  470.    *
  471.    * @static
  472.    * @version 1.0
  473.    * @since   0.1.2
  474.    * @author  Daniel Plücken <daniel@debakel.net>
  475.    * @access  public
  476.    * @param   integer $timestamp 
  477.    * @return  integer 
  478.    */
  479.   function extractWeekDayFromTimestamp$timestamp )
  480.   {
  481.     $temp date"w"$timestamp );
  482.     return $temp == $temp 1;
  483.   }
  484.  
  485.  
  486.  
  487.   /**
  488.    * Returns the extracted weeknum from a given timestamp.
  489.    *
  490.    * @static
  491.    * @version 1.0
  492.    * @since   0.1.2
  493.    * @author  Daniel Plücken <daniel@debakel.net>
  494.    * @access  public
  495.    * @param   integer $timestamp 
  496.    * @return  integer 
  497.    */
  498.   function extractWeeknumFromTimestamp$timestamp )
  499.   {
  500.     $wn   date"W"$timestamp );
  501.     $year date"Y"$timestamp );
  502.     ifDateFormatter::getWeeknumCountOfYear$year $wn )
  503.       $wn 1;
  504.  
  505.     return $wn;
  506.   }
  507.  
  508.  
  509.  
  510.   /**
  511.    * Returns the extracted year that depends on a weeknum of a unix-timestamp.
  512.    *
  513.    * @static
  514.    * @version 1.0
  515.    * @since   0.1.2
  516.    * @author  Daniel Plücken <daniel@debakel.net>
  517.    * @access  public
  518.    * @param   integer $timestamp 
  519.    * @return  integer 
  520.    */
  521.   function extractYearFromTimestampDependingOnWeeknum$timestamp )
  522.   {
  523.     $wn   date"W"$timestamp );
  524.     $year date"Y"$timestamp );
  525.     ifDateFormatter::getWeeknumCountOfYear$year $wn )
  526.       $year++;
  527.  
  528.     return $year;
  529.   }
  530.  
  531.  
  532.  
  533.   /**
  534.    * Returns the first second of a day from a unix-timestamp.
  535.    *
  536.    * @static
  537.    * @version 1.0
  538.    * @since   0.1.8
  539.    * @author  Daniel Plücken <daniel@debakel.net>
  540.    * @access  public
  541.    * @param   integer $timestamp 
  542.    * @return  integer 
  543.    */
  544.   function getFirstSecondOfDayFromTimestamp$timestamp )
  545.   {
  546.     $day   date"d"$timestamp );
  547.     $month date"m"$timestamp );
  548.     $year  date"Y"$timestamp );
  549.  
  550.     return mktime000$month$day$year );
  551.   }
  552.  
  553.  
  554.  
  555.   /**
  556.    * Returns the number of days from given month and year.
  557.    *
  558.    * @static
  559.    * @version 1.1
  560.    * @since   0.1.1
  561.    * @author  Daniel Plücken <daniel@debakel.net>
  562.    * @access  public
  563.    * @param   integer $timestamp 
  564.    * @return  integer 
  565.    */
  566.   function getDaysCountOfMonthOfYear$month$year )
  567.   {
  568.     // Computig the surplus of the month into the year.
  569.     if$month 12 )
  570.     {
  571.       $year  $year floor( ($month-112 );
  572.       $month $month 12;
  573.       $month $month == 12 $month;
  574.     }
  575.     else
  576.     if$month )
  577.     {
  578.       $year  $year floor( ($month-112 );
  579.       $month 12 abs$month 12;
  580.     }
  581.     // Computig the surplus of the month into the year.
  582.  
  583.     if$month != )
  584.       return $GLOBALS["daysPerMonth"]$month ];
  585.     else
  586.     ifDateFormatter::isLeapYear$year ) )
  587.       return 29;
  588.     else
  589.       return 28;
  590.   }
  591.  
  592.  
  593.  
  594.   /**
  595.    * Returns the timestamp of the week's first second from a given calendar week
  596.    * and year.
  597.    *
  598.    * @static
  599.    * @version 1.0
  600.    * @since   0.1.1
  601.    * @author  Daniel Plücken <daniel@debakel.net>
  602.    * @access  public
  603.    * @param   integer $timestamp 
  604.    * @return  integer 
  605.    */
  606.   function getTimestampFromWeeknumAndYear$weeknum$year )
  607.   {
  608.     $temp  DateFormatter::getMondayDateOfWeeknumOfYear$weeknum$year );
  609.  
  610.     $day   $temp[0];
  611.     $month $temp[1];
  612.     $year  $temp[2];
  613.  
  614.     return mktime000$month$day$year );
  615.   }
  616.  
  617.  
  618.  
  619.   /**
  620.    * Returns the monday date of the first calendar week of a given year
  621.    * according to ISO 8601:
  622.    * "The first week of a year is the first week which includes at least four
  623.    * days in the new year. Another way of putting this is that the first week
  624.    * of a year is the week which includes the first Thursday of January.
  625.    * It will also include January 4. This means that week 01 could include days
  626.    * from the previous year, or that week 53 could include days from the next
  627.    * year. For example, 2004-01-01 occurs on a Thursday.
  628.    * This means that 2004-W01 consists of 2003-12-29 through 2004-01-04.
  629.    * 2005-01-01 occurs on a Saturday, meaning that 2004-W53 is 2004-12-27
  630.    * through 2005-01-02, and 2005-W01 starts on 2005-01-03."
  631.    * (http://en.wikipedia.org/wiki/ISO_8601#Week_dates)
  632.    *
  633.    * @static
  634.    * @version 1.0
  635.    * @since   0.1.1
  636.    * @author  Daniel Plücken <daniel@debakel.net>
  637.    * @access  public
  638.    * @param   integer $year 
  639.    * @return  integer 
  640.    */
  641.   function getMondayDateOfFirstWeekOfYear$year )
  642.   {
  643.     $firstDayOfYearUNIX mktime(  0,  0,  0,  1,  1intval$year ) );
  644.     $firstWeekDayOfYear date"w"$firstDayOfYearUNIX );
  645.  
  646.     $MonthDayArr array213130294);
  647.  
  648.     return $MonthDayArr$firstWeekDayOfYear ];
  649.   }
  650.  
  651.  
  652.  
  653.   /**
  654.    * Returns the date of the monday associated with the given calendar week and
  655.    * year as an array. The first entry of the returned array carries the day
  656.    * of the month and the second entry carries the month of the given year.
  657.    *
  658.    * @static
  659.    * @version 1.0
  660.    * @since   0.1.1
  661.    * @author  Daniel Plücken <daniel@debakel.net>
  662.    * @access  public
  663.    * @param   integer $weeknum 
  664.    * @param   integer $year 
  665.    * @return  integer 
  666.    */
  667.   function getMondayDateOfWeeknumOfYear$weeknum$year )
  668.   {
  669.     $mondayDate DateFormatter::getMondayDateOfFirstWeekOfYear$year );
  670.  
  671.     if$weeknum == )
  672.     {
  673.       if$mondayDate )
  674.         return array$mondayDate12$year );
  675.       else
  676.         return array$mondayDate1$year );
  677.     }
  678.     else
  679.     {
  680.         $leapyear DateFormatter::isLeapYear$year );
  681.         // setting right february
  682.         $GLOBALS["daysPerMonth"][1]  $leapyear 29 28;
  683.  
  684.         if$mondayDate )
  685.           $mondayDate $mondayDate 31;
  686.  
  687.         $month 0;
  688.         for $i 2$i <= $weeknum $i++ )
  689.         {
  690.           if$mondayDate <= $GLOBALS["daysPerMonth"][$month)
  691.             $mondayDate += 7;
  692.           else
  693.           {
  694.             $mondayDate $mondayDate $GLOBALS["daysPerMonth"][$month];
  695.             $month++;
  696.           }
  697.         }
  698.  
  699.         if$month 12 )
  700.           return array$mondayDate1$year );
  701.         else
  702.           return array$mondayDate$month 1$year );
  703.     }
  704.   }
  705.  
  706.  
  707.  
  708.   /**
  709.    * Returns the date of the given weekday associated with the given calendar
  710.    * week and year as an array. The first entry of the returned array carries
  711.    * the day of the month and the second entry carries the month of the given
  712.    * year.
  713.    *
  714.    * @static
  715.    * @version 1.0
  716.    * @since   0.1.1
  717.    * @author  Daniel Plücken <daniel@debakel.net>
  718.    * @access  public
  719.    * @param   integer $weekday 
  720.    * @param   integer $weeknum 
  721.    * @param   integer $year 
  722.    * @return  integer 
  723.    */
  724.   function getDateOfWeekDayOfWeeknumOfYear$weekday$weeknum$year )
  725.   {
  726.      $leapyear DateFormatter::isLeapYear$year );
  727.  
  728.      // setting right february
  729.      $GLOBALS["daysPerMonth"][1]  $leapyear 29 28;
  730.  
  731.      $monday DateFormatter::getMondayDateOfWeeknumOfYear$weeknum$year );
  732.  
  733.      // change of December to January
  734.      if(
  735.          $monday[0]+$weekday <= $GLOBALS["daysPerMonth"][11]
  736.       && $monday[2== $year-1
  737.        )
  738.        return array$monday[0]+$weekday12$year-);
  739.      else
  740.      if$monday[2== $year-)
  741.        return array$monday[0]+$weekday-$GLOBALS["daysPerMonth"][11]1$year );
  742.      else
  743.      if$monday[0]+$weekday <= $GLOBALS["daysPerMonth"][$monday[1]-1)
  744.        return array$monday[0]+$weekday$monday[1]$year );
  745.      else
  746.      {
  747.         $dayDate $monday[0]+$weekday-$GLOBALS["daysPerMonth"][$monday[1]-1];
  748.         if$monday[1>= 12 )
  749.           return array$dayDate1$year+);
  750.         else
  751.           return array$dayDate$monday[1]+1$year );
  752.      }
  753.   }
  754.  
  755.  
  756.  
  757.   /**
  758.    * Returns the date of the tuesday associated with the given calendar week and
  759.    * year as an array. The first entry of the returned array carries the day
  760.    * of the month and the second entry carries the month of the given year.
  761.    *
  762.    * @static
  763.    * @version 1.0
  764.    * @since   0.1.1
  765.    * @author  Daniel Plücken <daniel@debakel.net>
  766.    * @access  public
  767.    * @param   integer $weeknum 
  768.    * @param   integer $year 
  769.    * @return  integer 
  770.    */
  771.   function getTuesdayDateOfWeeknumOfYear$weeknum$year )
  772.   {
  773.      return DateFormatter
  774.           ::getDateOfWeekDayOfWeeknumOfYear1$weeknum$year );
  775.   }
  776.  
  777.  
  778.  
  779.   /**
  780.    * Returns the date of the wednesday associated with the given calendar week
  781.    * and year as an array. The first entry of the returned array carries the day
  782.    * of the month and the second entry carries the month of the given year.
  783.    *
  784.    * @static
  785.    * @version 1.0
  786.    * @since   0.1.1
  787.    * @author  Daniel Plücken <daniel@debakel.net>
  788.    * @access  public
  789.    * @param   integer $weeknum 
  790.    * @param   integer $year 
  791.    * @return  integer 
  792.    */
  793.   function getWednesdayDateOfWeeknumOfYear$weeknum$year )
  794.   {
  795.      return DateFormatter
  796.           ::getDateOfWeekDayOfWeeknumOfYear2$weeknum$year );
  797.   }
  798.  
  799.  
  800.  
  801.   /**
  802.    * Returns the date of the thursday associated with the given calendar week
  803.    * and year as an array. The first entry of the returned array carries the day
  804.    * of the month and the second entry carries the month of the given year.
  805.    *
  806.    * @static
  807.    * @version 1.0
  808.    * @since   0.1.1
  809.    * @author  Daniel Plücken <daniel@debakel.net>
  810.    * @access  public
  811.    * @param   integer $weeknum 
  812.    * @param   integer $year 
  813.    * @return  integer 
  814.    */
  815.   function getThursdayDateOfWeeknumOfYear$weeknum$year )
  816.   {
  817.      return DateFormatter
  818.           ::getDateOfWeekDayOfWeeknumOfYear3$weeknum$year );
  819.   }
  820.  
  821.  
  822.  
  823.   /**
  824.    * Returns the date of the friday associated with the given calendar week and
  825.    * year as an array. The first entry of the returned array carries the day
  826.    * of the month and the second entry carries the month of the given year.
  827.    *
  828.    * @static
  829.    * @version 1.0
  830.    * @since   0.1.1
  831.    * @author  Daniel Plücken <daniel@debakel.net>
  832.    * @access  public
  833.    * @param   integer $weeknum 
  834.    * @param   integer $year 
  835.    * @return  integer 
  836.    */
  837.   function getFridayDateOfWeeknumOfYear$weeknum$year )
  838.   {
  839.      return DateFormatter
  840.           ::getDateOfWeekDayOfWeeknumOfYear4$weeknum$year );
  841.   }
  842.  
  843.  
  844.  
  845.   /**
  846.    * Returns the date of the saturday associated with the given calendar week
  847.    * and year as an array. The first entry of the returned array carries the day
  848.    * of the month and the second entry carries the month of the given year.
  849.    *
  850.    * @static
  851.    * @version 1.0
  852.    * @since   0.1.1
  853.    * @author  Daniel Plücken <daniel@debakel.net>
  854.    * @access  public
  855.    * @param   integer $weeknum 
  856.    * @param   integer $year 
  857.    * @return  integer 
  858.    */
  859.   function getSaturdayDateOfWeeknumOfYear$weeknum$year )
  860.   {
  861.      return DateFormatter
  862.           ::getDateOfWeekDayOfWeeknumOfYear5$weeknum$year );
  863.   }
  864.  
  865.  
  866.  
  867.   /**
  868.    * Returns the date of the sunday associated with the given calendar week and
  869.    * year as an array. The first entry of the returned array carries the day
  870.    * of the month and the second entry carries the month of the given year.
  871.    *
  872.    * @static
  873.    * @version 1.0
  874.    * @since   0.1.1
  875.    * @author  Daniel Plücken <daniel@debakel.net>
  876.    * @access  public
  877.    * @param   integer $weeknum 
  878.    * @param   integer $year 
  879.    * @return  integer 
  880.    */
  881.   function getSundayDateOfWeeknumOfYear$weeknum$year )
  882.   {
  883.      return DateFormatter
  884.           ::getDateOfWeekDayOfWeeknumOfYear6$weeknum$year );
  885.   }
  886.  
  887.  
  888.  
  889.   /**
  890.    * Returns weekday name associated with the given timestamp.
  891.    *
  892.    * @static
  893.    * @version 1.0
  894.    * @since   0.1.1
  895.    * @author  Daniel Plücken <daniel@debakel.net>
  896.    * @access  public
  897.    * @param   integer $timestamp 
  898.    * @return  string 
  899.    */
  900.   function getWeekdaynameFromTimestamp$timestamp )
  901.   {
  902.     $tmp DateFormatter::extractWeekDayFromTimestamp$timestamp );
  903.     return $GLOBALS["dayNames"][$tmp];
  904.   }
  905.  
  906.  
  907.  
  908.   /**
  909.    * Returns the number of month associated with the given calendar week and
  910.    * year. Beware! This function will not return the values between 1 and 12,
  911.    * because it could be that a given calendar week is a part of two month.
  912.    * <code>
  913.    * Here is the list of the definition:
  914.    *
  915.    *        0 January
  916.    *        1 January / February
  917.    *        2 February
  918.    *        3 February / March
  919.    *        4 March
  920.    *        5 March / April
  921.    *        6 April
  922.    *        7 April / May
  923.    *        8 May
  924.    *        9 May / June
  925.    *       10 June
  926.    *       11 June / July
  927.    *       12 July
  928.    *       13 July / August
  929.    *       14 August
  930.    *       15 August / September
  931.    *       16 September
  932.    *       17 September / October
  933.    *       18 October
  934.    *       19 October / November
  935.    *       20 November
  936.    *       21 November / December
  937.    *       22 December
  938.    *       23 December / January
  939.    *
  940.    * </code>
  941.    *
  942.    * @version 1.0
  943.    * @since   0.1.1
  944.    * @author  Daniel Plücken <daniel@debakel.net>
  945.    * @access  public
  946.    * @static
  947.    * @param   integer $weeknum 
  948.    * @param   integer $year 
  949.    * @return  integer 
  950.    */
  951.   function getMonthFromWeeknumAndYear$weeknum$year )
  952.   {
  953.     $monday DateFormatter::getMondayDateOfWeeknumOfYear$weeknum$year );
  954.     $sunday DateFormatter::getSundayDateOfWeeknumOfYear$weeknum$year );
  955.  
  956.     if$sunday[1$monday[1)
  957.       return 23;
  958.     else
  959.       return ($sunday[1]-$monday[1]$monday[12;
  960.   }
  961.  
  962.  
  963.  
  964.   /**
  965.    * Returns the name of month associated with the given calendar week and year.
  966.    *
  967.    * @static
  968.    * @version 1.0
  969.    * @since   0.1.0
  970.    * @author  Daniel Plücken <daniel@debakel.net>
  971.    * @access  public
  972.    * @param   integer $weeknum 
  973.    * @param   integer $year 
  974.    * @return  string 
  975.    */
  976.   function getMonthNameFromWeeknumAndYear$weeknum$year )
  977.   {
  978.     return $GLOBALS["interMonthNames"][
  979.                               DateFormatter
  980.                             ::getMonthFromWeeknumAndYear(
  981.                                                      $weeknum,
  982.                                                      $year
  983.                                                         )
  984.                                       ];
  985.   }
  986.  
  987.  
  988.  
  989.   /**
  990.    * Returns the number of weeks in a given year.
  991.    *
  992.    * @static
  993.    * @version 1.0
  994.    * @since   0.1.1
  995.    * @author  Daniel Plücken <daniel@debakel.net>
  996.    * @access  public
  997.    * @param   integer $year 
  998.    * @return  integer 
  999.    */
  1000.   function getWeeknumCountOfYear$year )
  1001.   {
  1002.     $thisYear_DateOfSundayArr DateFormatter
  1003.                               ::getSundayDateOfWeeknumOfYear53$year );
  1004.     $nextYear_DateOfSundayArr DateFormatter
  1005.                               ::getSundayDateOfWeeknumOfYear(  1$year );
  1006.  
  1007.     if(
  1008.         $thisYear_DateOfSundayArr[0== $nextYear_DateOfSundayArr[0]
  1009.      && $thisYear_DateOfSundayArr[1== $nextYear_DateOfSundayArr[1]
  1010.      && $thisYear_DateOfSundayArr[2== $nextYear_DateOfSundayArr[2]
  1011.       )
  1012.       $int 52;
  1013.     else
  1014.       $int 53;
  1015.  
  1016.     return $int;
  1017.   }
  1018.  
  1019.  
  1020.  
  1021.   /**
  1022.    * Returns whether the given year is a leap year.
  1023.    *
  1024.    * @static
  1025.    * @version 1.0
  1026.    * @since   0.1.2
  1027.    * @author  Daniel Plücken <daniel@debakel.net>
  1028.    * @access  public
  1029.    * @param   integer $year 
  1030.    * @return  boolean 
  1031.    */
  1032.   function isLeapYear$year )
  1033.   {
  1034.     ifstrlen$year == )
  1035.       if$year 69 )
  1036.         $year "19".$year;
  1037.       else
  1038.         $year "20".$year;
  1039.  
  1040.     return $year == 0
  1041.         && (
  1042.              $year 100 != 0
  1043.           || $year 400 == 0
  1044.            );
  1045.   }
  1046. // END of class DateFormatter
  1047. ?>

Documentation generated on Thu, 05 Jun 2008 19:10:42 +0200 by phpDocumentor 1.4.1