[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/data/Date/ -> Calc.class.php (source)

   1  <?php
   2  
   3  // The constant telling us what day starts the week. Monday (1) is the
   4  // international standard. Redefine this to 0 if you want weeks to
   5  // begin on Sunday.
   6  if (!defined('DATE_CALC_BEGIN_WEEKDAY')) {
   7      define('DATE_CALC_BEGIN_WEEKDAY', 1);
   8  }
   9  
  10  /**
  11   * \ingroup Data
  12   *
  13   * Date_Calc is a calendar class used to calculate and
  14   * manipulate calendar dates and retrieve dates in a calendar
  15   * format. It does not rely on 32-bit system date stamps, so
  16   * you can display calendars and compare dates that date
  17   * pre 1970 and post 2038.
  18   *
  19   * This source file is subject to version 2.02 of the PHP license,
  20   * that is bundled with this package in the file LICENSE, and is
  21   * available at through the world-wide-web at
  22   * http://www.php.net/license/2_02.txt.
  23   * If you did not receive a copy of the PHP license and are unable to
  24   * obtain it through the world-wide-web, please send a note to
  25   * license@php.net so we can mail you a copy immediately.
  26   *
  27   * Copyright (c) 1999, 2002, 2003 ispi
  28   *
  29   * @access public
  30   *
  31   * @version 1.2.6
  32   * @author Monte Ohrt <monte@ispi.net>
  33   */
  34  class Date_Calc
  35  {
  36      /**
  37       * Returns the current local date. NOTE: This function
  38       * retrieves the local date using strftime(), which may
  39       * or may not be 32-bit safe on your system.
  40       *
  41       * @param string the strftime() format to return the date
  42       *
  43       * @access public
  44       *
  45       * @return string the current date in specified format
  46       */
  47  
  48      function dateNow($format='%Y%m%d')
  49      {
  50          return(strftime($format,time()));
  51  
  52      } // end func dateNow
  53  
  54      /**
  55       * Returns true for valid date, false for invalid date.
  56       *
  57       * @param string year in format CCYY
  58       * @param string month in format MM
  59       * @param string day in format DD
  60       *
  61       * @access public
  62       *
  63       * @return boolean true/false
  64       */
  65  
  66      function isValidDate($day, $month, $year)
  67      {
  68          if ($year < 0 || $year > 9999) {
  69              return false;
  70          }
  71        if (!checkdate($month,$day,$year)) {
  72              return false;
  73          }
  74  
  75          return true;
  76      }
  77  
  78  //     /**
  79  //     * Returns true for a leap year, else false
  80  //     *
  81  //     * @param string year in format CCYY
  82  //     *
  83  //     * @access public
  84  //     *
  85  //     * @return boolean true/false
  86  //     */
  87  //
  88      function isLeapYear($year='')
  89      {
  90          if (empty($year)) {
  91              $year = Date_Calc::dateNow('%Y');
  92          }
  93  
  94          if (preg_match('/\D/',$year)) {
  95              return false;
  96          }
  97  
  98          if ($year < 1000) {
  99              return false;
 100          }
 101  
 102          if ($year < 1582) {
 103              // pre Gregorio XIII - 1582
 104              return ($year % 4 == 0);
 105          } else {
 106              // post Gregorio XIII - 1582
 107              return ( (($year % 4 == 0) and ($year % 100 != 0)) or ($year % 400 == 0) );
 108          }
 109      } // end func isLeapYear
 110  //
 111  //    /**
 112  //     * Determines if given date is a future date from now.
 113  //     *
 114  //     * @param string day in format DD
 115  //     * @param string month in format MM
 116  //     * @param string year in format CCYY
 117  //     *
 118  //     * @access public
 119  //     *
 120  //     * @return boolean true/false
 121  //     */
 122  //
 123  //    function isFutureDate($day,$month,$year)
 124  //    {
 125  //        $this_year = Date_Calc::dateNow('%Y');
 126  //        $this_month = Date_Calc::dateNow('%m');
 127  //        $this_day = Date_Calc::dateNow('%d');
 128  //
 129  //        if ($year > $this_year) {
 130  //            return true;
 131  //        } elseif ($year == $this_year) {
 132  //            if ($month > $this_month) {
 133  //                return true;
 134  //            } elseif ($month == $this_month) {
 135  //                if ($day > $this_day) {
 136  //                    return true;
 137  //                }
 138  //            }
 139  //        }
 140  //
 141  //        return false;
 142  //    } // end func isFutureDate
 143  //
 144  //    /**
 145  //     * Determines if given date is a past date from now.
 146  //     *
 147  //     * @param string day in format DD
 148  //     * @param string month in format MM
 149  //     * @param string year in format CCYY
 150  //     *
 151  //     * @access public
 152  //     *
 153  //     * @return boolean true/false
 154  //     */
 155  //
 156  //    function isPastDate($day,$month,$year)
 157  //    {
 158  //        $this_year = Date_Calc::dateNow('%Y');
 159  //        $this_month = Date_Calc::dateNow('%m');
 160  //        $this_day = Date_Calc::dateNow('%d');
 161  //
 162  //        if ($year < $this_year) {
 163  //            return true;
 164  //        } elseif ($year == $this_year) {
 165  //            if ($month < $this_month) {
 166  //                return true;
 167  //            } elseif ($month == $this_month) {
 168  //                if ($day < $this_day) {
 169  //                    return true;
 170  //                }
 171  //            }
 172  //        }
 173  //
 174  //        return false;
 175  //    } // end func isPastDate
 176  //
 177      /**
 178       * Returns day of week for given date, 0=Sunday
 179       *
 180       * @param string day in format DD, default is current local day
 181       * @param string month in format MM, default is current local month
 182       * @param string year in format CCYY, default is current local year
 183       *
 184       * @access public
 185       *
 186       * @return int $weekday_number
 187       */
 188  
 189      function dayOfWeek($day='',$month='',$year='')
 190      {
 191          if (empty($year)) {
 192              $year = Date_Calc::dateNow('%Y');
 193          }
 194          if (empty($month)) {
 195              $month = Date_Calc::dateNow('%m');
 196          }
 197          if (empty($day)) {
 198              $day = Date_Calc::dateNow('%d');
 199          }
 200  
 201          if ($month > 2) {
 202              $month -= 2;
 203          } else {
 204              $month += 10;
 205              $year--;
 206          }
 207  
 208          $day = ( floor((13 * $month - 1) / 5) +
 209              $day + ($year % 100) +
 210              floor(($year % 100) / 4) +
 211              floor(($year / 100) / 4) - 2 *
 212              floor($year / 100) + 77);
 213  
 214          $weekday_number = (($day - 7 * floor($day / 7)));
 215  
 216          return $weekday_number;
 217      }
 218  
 219  //    /**
 220  //     * Returns week of the year, first Sunday is first day of first week
 221  //     *
 222  //     * @param string day in format DD, default is current local day
 223  //     * @param string month in format MM, default is current local month
 224  //     * @param string year in format CCYY, default is current local year
 225  //     *
 226  //     * @access public
 227  //     *
 228  //     * @return integer $week_number
 229  //     */
 230  //
 231  //    function weekOfYear($day='',$month='',$year='')
 232  //    {
 233  //        if (empty($year)) {
 234  //            $year = Date_Calc::dateNow('%Y');
 235  //        }
 236  //        if (empty($month)) {
 237  //            $month = Date_Calc::dateNow('%m');
 238  //        }
 239  //        if (empty($day)) {
 240  //            $day = Date_Calc::dateNow('%d');
 241  //        }
 242  //        $iso    = Date_Calc::gregorianToISO($day, $month, $year);
 243  //        $parts  = explode('-',$iso);
 244  //        $week_number = intval($parts[1]);
 245  //        return $week_number;
 246  //    } // end func weekOfYear
 247  //
 248  //    /**
 249  //     * Returns number of days since 31 December of year before given date.
 250  //     *
 251  //     * @param string day in format DD, default is current local day
 252  //     * @param string month in format MM, default is current local month
 253  //     * @param string year in format CCYY, default is current local year
 254  //     *
 255  //     * @access public
 256  //     *
 257  //     * @return int $julian
 258  //     */
 259  //
 260  //    function julianDate($day='',$month='',$year='')
 261  //    {
 262  //        if (empty($year)) {
 263  //            $year = Date_Calc::dateNow('%Y');
 264  //        }
 265  //        if (empty($month)) {
 266  //            $month = Date_Calc::dateNow('%m');
 267  //        }
 268  //        if (empty($day)) {
 269  //            $day = Date_Calc::dateNow('%d');
 270  //        }
 271  //
 272  //        $days = array(0,31,59,90,120,151,181,212,243,273,304,334);
 273  //
 274  //        $julian = ($days[$month - 1] + $day);
 275  //
 276  //        if ($month > 2 && Date_Calc::isLeapYear($year)) {
 277  //            $julian++;
 278  //        }
 279  //
 280  //        return($julian);
 281  //    } // end func julianDate
 282  //
 283  //    /**
 284  //     * Returns quarter of the year for given date
 285  //     *
 286  //     * @param string day in format DD, default is current local day
 287  //     * @param string month in format MM, default is current local month
 288  //     * @param string year in format CCYY, default is current local year
 289  //     *
 290  //     * @access public
 291  //     *
 292  //     * @return int $year_quarter
 293  //     */
 294  //
 295  //    function quarterOfYear($day='',$month='',$year='')
 296  //    {
 297  //        if (empty($year)) {
 298  //            $year = Date_Calc::dateNow('%Y');
 299  //        }
 300  //        if (empty($month)) {
 301  //            $month = Date_Calc::dateNow('%m');
 302  //        }
 303  //        if (empty($day)) {
 304  //            $day = Date_Calc::dateNow('%d');
 305  //        }
 306  //
 307  //        $year_quarter = (intval(($month - 1) / 3 + 1));
 308  //
 309  //        return $year_quarter;
 310  //    } // end func quarterOfYear
 311  //
 312  //    /**
 313  //     * Returns date of begin of next month of given date.
 314  //     *
 315  //     * @param string day in format DD, default is current local day
 316  //     * @param string month in format MM, default is current local month
 317  //     * @param string year in format CCYY, default is current local year
 318  //     * @param string format for returned date
 319  //     *
 320  //     * @access public
 321  //     *
 322  //     * @return string date in given format
 323  //     */
 324  //
 325  //    function beginOfNextMonth($day='',$month='',$year='',$format='%Y%m%d')
 326  //    {
 327  //        if (empty($year)) {
 328  //            $year = Date_Calc::dateNow('%Y');
 329  //        }
 330  //        if (empty($month)) {
 331  //            $month = Date_Calc::dateNow('%m');
 332  //        }
 333  //        if (empty($day)) {
 334  //            $day = Date_Calc::dateNow('%d');
 335  //        }
 336  //
 337  //        if ($month < 12) {
 338  //            $month++;
 339  //            $day=1;
 340  //        } else {
 341  //            $year++;
 342  //            $month=1;
 343  //            $day=1;
 344  //        }
 345  //
 346  //        return Date_Calc::dateFormat($day,$month,$year,$format);
 347  //    } // end func beginOfNextMonth
 348  //
 349  //    /**
 350  //     * Returns date of the last day of next month of given date.
 351  //     *
 352  //     * @param string day in format DD, default is current local day
 353  //     * @param string month in format MM, default is current local month
 354  //     * @param string year in format CCYY, default is current local year
 355  //     * @param string format for returned date
 356  //     *
 357  //     * @access public
 358  //     *
 359  //     * @return string date in given format
 360  //     */
 361  //
 362  //    function endOfNextMonth($day='',$month='',$year='',$format='%Y%m%d')
 363  //    {
 364  //        if (empty($year)) {
 365  //            $year = Date_Calc::dateNow('%Y');
 366  //        }
 367  //        if (empty($month)) {
 368  //            $month = Date_Calc::dateNow('%m');
 369  //        }
 370  //        if (empty($day)) {
 371  //            $day = Date_Calc::dateNow('%d');
 372  //        }
 373  //
 374  //        if ($month < 12) {
 375  //            $month++;
 376  //        } else {
 377  //            $year++;
 378  //            $month=1;
 379  //        }
 380  //
 381  //        $day = Date_Calc::daysInMonth($month,$year);
 382  //
 383  //        return Date_Calc::dateFormat($day,$month,$year,$format);
 384  //    } // end func endOfNextMonth
 385  //
 386  //    /**
 387  //     * Returns date of the first day of previous month of given date.
 388  //     *
 389  //     * @param string day in format DD, default is current local day
 390  //     * @param string month in format MM, default is current local month
 391  //     * @param string year in format CCYY, default is current local year
 392  //     * @param string format for returned date
 393  //     *
 394  //     * @access public
 395  //     *
 396  //     * @return string date in given format
 397  //     */
 398  //
 399  //    function beginOfPrevMonth($day='',$month='',$year='',$format='%Y%m%d')
 400  //    {
 401  //        if (empty($year)) {
 402  //            $year = Date_Calc::dateNow('%Y');
 403  //        }
 404  //        if (empty($month)) {
 405  //            $month = Date_Calc::dateNow('%m');
 406  //        }
 407  //        if (empty($day)) {
 408  //            $day = Date_Calc::dateNow('%d');
 409  //        }
 410  //
 411  //        if ($month > 1) {
 412  //            $month--;
 413  //            $day=1;
 414  //        } else {
 415  //            $year--;
 416  //            $month=12;
 417  //            $day=1;
 418  //        }
 419  //
 420  //        return Date_Calc::dateFormat($day,$month,$year,$format);
 421  //    } // end func beginOfPrevMonth
 422  //
 423  //    /**
 424  //     * Returns date of the last day of previous month for given date.
 425  //     *
 426  //     * @param string day in format DD, default is current local day
 427  //     * @param string month in format MM, default is current local month
 428  //     * @param string year in format CCYY, default is current local year
 429  //     * @param string format for returned date
 430  //     *
 431  //     * @access public
 432  //     *
 433  //     * @return string date in given format
 434  //     */
 435  //
 436  //    function endOfPrevMonth($day='',$month='',$year='',$format='%Y%m%d')
 437  //    {
 438  //        if (empty($year)) {
 439  //            $year = Date_Calc::dateNow('%Y');
 440  //        }
 441  //        if (empty($month)) {
 442  //            $month = Date_Calc::dateNow('%m');
 443  //        }
 444  //        if (empty($day)) {
 445  //            $day = Date_Calc::dateNow('%d');
 446  //        }
 447  //
 448  //        if ($month > 1) {
 449  //            $month--;
 450  //        } else {
 451  //            $year--;
 452  //            $month=12;
 453  //        }
 454  //
 455  //        $day = Date_Calc::daysInMonth($month,$year);
 456  //
 457  //        return Date_Calc::dateFormat($day,$month,$year,$format);
 458  //    } // end func endOfPrevMonth
 459  //
 460  //    /**
 461  //     * Returns date of the next weekday of given date,
 462  //     * skipping from Friday to Monday.
 463  //     *
 464  //     * @param string day in format DD, default is current local day
 465  //     * @param string month in format MM, default is current local month
 466  //     * @param string year in format CCYY, default is current local year
 467  //     * @param string format for returned date
 468  //     *
 469  //     * @access public
 470  //     *
 471  //     * @return string date in given format
 472  //     */
 473  //
 474  //    function nextWeekday($day='',$month='',$year='',$format='%Y%m%d')
 475  //    {
 476  //        if (empty($year)) {
 477  //            $year = Date_Calc::dateNow('%Y');
 478  //        }
 479  //        if (empty($month)) {
 480  //            $month = Date_Calc::dateNow('%m');
 481  //        }
 482  //        if (empty($day)) {
 483  //            $day = Date_Calc::dateNow('%d');
 484  //        }
 485  //
 486  //        $days = Date_Calc::dateToDays($day,$month,$year);
 487  //
 488  //        if (Date_Calc::dayOfWeek($day,$month,$year) == 5) {
 489  //            $days += 3;
 490  //        } elseif (Date_Calc::dayOfWeek($day,$month,$year) == 6) {
 491  //            $days += 2;
 492  //        } else {
 493  //            $days += 1;
 494  //        }
 495  //
 496  //        return(Date_Calc::daysToDate($days,$format));
 497  //    } // end func nextWeekday
 498  //
 499  //    /**
 500  //     * Returns date of the previous weekday,
 501  //     * skipping from Monday to Friday.
 502  //     *
 503  //     * @param string day in format DD, default is current local day
 504  //     * @param string month in format MM, default is current local month
 505  //     * @param string year in format CCYY, default is current local year
 506  //     * @param string format for returned date
 507  //     *
 508  //     * @access public
 509  //     *
 510  //     * @return string date in given format
 511  //     */
 512  //
 513  //    function prevWeekday($day='',$month='',$year='',$format='%Y%m%d')
 514  //    {
 515  //        if (empty($year)) {
 516  //            $year = Date_Calc::dateNow('%Y');
 517  //        }
 518  //        if (empty($month)) {
 519  //            $month = Date_Calc::dateNow('%m');
 520  //        }
 521  //        if (empty($day)) {
 522  //            $day = Date_Calc::dateNow('%d');
 523  //        }
 524  //
 525  //        $days = Date_Calc::dateToDays($day,$month,$year);
 526  //
 527  //        if (Date_Calc::dayOfWeek($day,$month,$year) == 1) {
 528  //            $days -= 3;
 529  //        } elseif (Date_Calc::dayOfWeek($day,$month,$year) == 0) {
 530  //            $days -= 2;
 531  //        } else {
 532  //            $days -= 1;
 533  //        }
 534  //
 535  //        return(Date_Calc::daysToDate($days,$format));
 536  //    } // end func prevWeekday
 537  //
 538  //    /**
 539  //     * Returns date of the next specific day of the week
 540  //     * from the given date.
 541  //     *
 542  //     * @param int day of week, 0=Sunday
 543  //     * @param string day in format DD, default is current local day
 544  //     * @param string month in format MM, default is current local month
 545  //     * @param string year in format CCYY, default is current local year
 546  //     * @param boolean onOrAfter if true and days are same, returns current day
 547  //     * @param string format for returned date
 548  //     *
 549  //     * @access public
 550  //     *
 551  //     * @return string date in given format
 552  //     */
 553  //
 554  //    function nextDayOfWeek($dow,$day='',$month='',$year='',$format='%Y%m%d',$onOrAfter=false)
 555  //    {
 556  //        if (empty($year)) {
 557  //            $year = Date_Calc::dateNow('%Y');
 558  //        }
 559  //        if (empty($month)) {
 560  //            $month = Date_Calc::dateNow('%m');
 561  //        }
 562  //        if (empty($day)) {
 563  //            $day = Date_Calc::dateNow('%d');
 564  //        }
 565  //
 566  //        $days = Date_Calc::dateToDays($day,$month,$year);
 567  //        $curr_weekday = Date_Calc::dayOfWeek($day,$month,$year);
 568  //
 569  //        if ($curr_weekday == $dow) {
 570  //            if (!$onOrAfter) {
 571  //                $days += 7;
 572  //            }
 573  //        }
 574  //        elseif ($curr_weekday > $dow) {
 575  //            $days += 7 - ( $curr_weekday - $dow );
 576  //        } else {
 577  //            $days += $dow - $curr_weekday;
 578  //        }
 579  //
 580  //        return(Date_Calc::daysToDate($days,$format));
 581  //    } // end func nextDayOfWeek
 582  //
 583  //    /**
 584  //     * Returns date of the previous specific day of the week
 585  //     * from the given date.
 586  //     *
 587  //     * @param int day of week, 0=Sunday
 588  //     * @param string day in format DD, default is current local day
 589  //     * @param string month in format MM, default is current local month
 590  //     * @param string year in format CCYY, default is current local year
 591  //     * @param boolean onOrBefore if true and days are same, returns current day
 592  //     * @param string format for returned date
 593  //     *
 594  //     * @access public
 595  //     *
 596  //     * @return string date in given format
 597  //     */
 598  //
 599  //    function prevDayOfWeek($dow,$day='',$month='',$year='',$format='%Y%m%d',$onOrBefore=false)
 600  //    {
 601  //        if (empty($year)) {
 602  //            $year = Date_Calc::dateNow('%Y');
 603  //        }
 604  //        if (empty($month)) {
 605  //            $month = Date_Calc::dateNow('%m');
 606  //        }
 607  //        if (empty($day)) {
 608  //            $day = Date_Calc::dateNow('%d');
 609  //        }
 610  //
 611  //        $days = Date_Calc::dateToDays($day,$month,$year);
 612  //        $curr_weekday = Date_Calc::dayOfWeek($day,$month,$year);
 613  //
 614  //        if ($curr_weekday == $dow) {
 615  //            if (!$onOrBefore) {
 616  //                $days -= 7;
 617  //            }
 618  //        }
 619  //        elseif ($curr_weekday < $dow) {
 620  //            $days -= 7 - ( $dow - $curr_weekday );
 621  //        } else {
 622  //            $days -= $curr_weekday - $dow;
 623  //        }
 624  //
 625  //        return(Date_Calc::daysToDate($days,$format));
 626  //    } // end func prevDayOfWeek
 627  //
 628  //    /**
 629  //     * Returns date of the next specific day of the week
 630  //     * on or after the given date.
 631  //     *
 632  //     * @param int day of week, 0=Sunday
 633  //     * @param string day in format DD, default is current local day
 634  //     * @param string month in format MM, default is current local month
 635  //     * @param string year in format CCYY, default is current local year
 636  //     * @param string format for returned date
 637  //     *
 638  //     * @access public
 639  //     *
 640  //     * @return string date in given format
 641  //     */
 642  //
 643  //    function nextDayOfWeekOnOrAfter($dow,$day='',$month='',$year='',$format='%Y%m%d')
 644  //    {
 645  //        return(Date_Calc::nextDayOfWeek($dow,$day,$month,$year,$format,true));
 646  //    } // end func nextDayOfWeekOnOrAfter
 647  //
 648  //    /**
 649  //     * Returns date of the previous specific day of the week
 650  //     * on or before the given date.
 651  //     *
 652  //     * @param int day of week, 0=Sunday
 653  //     * @param string day in format DD, default is current local day
 654  //     * @param string month in format MM, default is current local month
 655  //     * @param string year in format CCYY, default is current local year
 656  //     * @param string format for returned date
 657  //     *
 658  //     * @access public
 659  //     *
 660  //     * @return string date in given format
 661  //     */
 662  //
 663  //    function prevDayOfWeekOnOrBefore($dow,$day='',$month='',$year='',$format='%Y%m%d')
 664  //    {
 665  //        return(Date_Calc::prevDayOfWeek($dow,$day,$month,$year,$format,true));
 666  //    } // end func prevDayOfWeekOnOrAfter
 667  //
 668      /**
 669       * Returns date of day after given date.
 670       *
 671       * @param string day in format DD, default is current local day
 672       * @param string month in format MM, default is current local month
 673       * @param string year in format CCYY, default is current local year
 674       * @param string format for returned date
 675       *
 676       * @access public
 677       *
 678       * @return string date in given format
 679       */
 680  
 681      function nextDay($day='',$month='',$year='',$format='%Y%m%d')
 682      {
 683          if (empty($year)) {
 684              $year = Date_Calc::dateNow('%Y');
 685          }
 686          if (empty($month)) {
 687              $month = Date_Calc::dateNow('%m');
 688          }
 689          if (empty($day)) {
 690              $day = Date_Calc::dateNow('%d');
 691          }
 692  
 693          $days = Date_Calc::dateToDays($day,$month,$year);
 694  
 695          return(Date_Calc::daysToDate($days + 1,$format));
 696      }
 697  
 698  //    /**
 699  //     * Returns date of day before given date.
 700  //     *
 701  //     * @param string day in format DD, default is current local day
 702  //     * @param string month in format MM, default is current local month
 703  //     * @param string year in format CCYY, default is current local year
 704  //     * @param string format for returned date
 705  //     *
 706  //     * @access public
 707  //     *
 708  //     * @return string date in given format
 709  //     */
 710  //
 711      function prevDay($day='',$month='',$year='',$format='%Y%m%d')
 712      {
 713          if (empty($year)) {
 714              $year = Date_Calc::dateNow('%Y');
 715          }
 716          if (empty($month)) {
 717              $month = Date_Calc::dateNow('%m');
 718          }
 719          if (empty($day)) {
 720              $day = Date_Calc::dateNow('%d');
 721          }
 722  
 723          $days = Date_Calc::dateToDays($day,$month,$year);
 724  
 725          return(Date_Calc::daysToDate($days - 1,$format));
 726      } // end func prevDay
 727  //
 728  //    /**
 729  //     * Sets century for 2 digit year.
 730  //     * 51-99 is 19, else 20
 731  //     *
 732  //     * @param string 2 digit year
 733  //     *
 734  //     * @access public
 735  //     *
 736  //     * @return string 4 digit year
 737  //     */
 738  //
 739  //    function defaultCentury($year)
 740  //    {
 741  //        if (strlen($year) == 1) {
 742  //            $year = "0$year";
 743  //        }
 744  //        if ($year > 50) {
 745  //            return( "19$year" );
 746  //        } else {
 747  //            return( "20$year" );
 748  //        }
 749  //    } // end func defaultCentury
 750  //
 751  //    /**
 752  //     * Returns number of days between two given dates.
 753  //     *
 754  //    * @param string $day1   day in format DD
 755  //    * @param string $month1 month in format MM
 756  //    * @param string $year1  year in format CCYY
 757  //    * @param string $day2   day in format DD
 758  //    * @param string $month2 month in format MM
 759  //    * @param string $year2  year in format CCYY
 760  //     *
 761  //     * @access public
 762  //     *
 763  //     * @return int absolute number of days between dates,
 764  //     *      -1 if there is an error.
 765  //     */
 766  //
 767  //    function dateDiff($day1,$month1,$year1,$day2,$month2,$year2)
 768  //    {
 769  //        if (!Date_Calc::isValidDate($day1,$month1,$year1)) {
 770  //            return -1;
 771  //        }
 772  //        if (!Date_Calc::isValidDate($day2,$month2,$year2)) {
 773  //            return -1;
 774  //        }
 775  //
 776  //        return(abs((Date_Calc::dateToDays($day1,$month1,$year1))
 777  //                    - (Date_Calc::dateToDays($day2,$month2,$year2))));
 778  //    } // end func dateDiff
 779  //
 780  //    /**
 781  //    * Compares two dates
 782  //    *
 783  //    * @param string $day1   day in format DD
 784  //    * @param string $month1 month in format MM
 785  //    * @param string $year1  year in format CCYY
 786  //    * @param string $day2   day in format DD
 787  //    * @param string $month2 month in format MM
 788  //    * @param string $year2  year in format CCYY
 789  //    *
 790  //    * @access public
 791  //    * @return int 0 on equality, 1 if date 1 is greater, -1 if smaller
 792  //    */
 793  //    function compareDates($day1,$month1,$year1,$day2,$month2,$year2)
 794  //    {
 795  //        $ndays1 = Date_Calc::dateToDays($day1, $month1, $year1);
 796  //        $ndays2 = Date_Calc::dateToDays($day2, $month2, $year2);
 797  //        if ($ndays1 == $ndays2) {
 798  //            return 0;
 799  //        }
 800  //        return ($ndays1 > $ndays2) ? 1 : -1;
 801  //    } // end func compareDates
 802  //
 803  //    /**
 804  //     * Find the number of days in the given month.
 805  //     *
 806  //     * @param string month in format MM, default is current local month
 807  //     * @param string year in format CCYY, default is current local year
 808  //     *
 809  //     * @access public
 810  //     *
 811  //     * @return int number of days
 812  //     */
 813  //
 814      function daysInMonth($month='',$year='')
 815      {
 816          if (empty($year)) {
 817              $year = Date_Calc::dateNow('%Y');
 818          }
 819          if (empty($month)) {
 820              $month = Date_Calc::dateNow('%m');
 821          }
 822  
 823          if ($year == 1582 && $month == 10) {
 824              return 21;  // October 1582 only had 1st-4th and 15th-31st
 825          }
 826  
 827          if ($month == 2) {
 828              if (Date_Calc::isLeapYear($year)) {
 829                  return 29;
 830               } else {
 831                  return 28;
 832              }
 833          } elseif ($month == 4 or $month == 6 or $month == 9 or $month == 11) {
 834              return 30;
 835          } else {
 836              return 31;
 837          }
 838      } // end func daysInMonth
 839  //
 840  //    /**
 841  //     * Returns the number of rows on a calendar month. Useful for
 842  //     * determining the number of rows when displaying a typical
 843  //     * month calendar.
 844  //     *
 845  //     * @param string month in format MM, default is current local month
 846  //     * @param string year in format CCYY, default is current local year
 847  //     *
 848  //     * @access public
 849  //     *
 850  //     * @return int number of weeks
 851  //     */
 852  //
 853  //    function weeksInMonth($month='',$year='')
 854  //    {
 855  //        if (empty($year)) {
 856  //            $year = Date_Calc::dateNow('%Y');
 857  //        }
 858  //        if (empty($month)) {
 859  //            $month = Date_Calc::dateNow('%m');
 860  //        }
 861  //        $FDOM = Date_Calc::firstOfMonthWeekday($month, $year);
 862  //        if (DATE_CALC_BEGIN_WEEKDAY==1 && $FDOM==0) {
 863  //            $first_week_days = 7 - $FDOM + DATE_CALC_BEGIN_WEEKDAY;
 864  //            $weeks = 1;
 865  //        } elseif (DATE_CALC_BEGIN_WEEKDAY==0 && $FDOM == 6) {
 866  //            $first_week_days = 7 - $FDOM + DATE_CALC_BEGIN_WEEKDAY;
 867  //            $weeks = 1;
 868  //        } else {
 869  //            $first_week_days = DATE_CALC_BEGIN_WEEKDAY - $FDOM;
 870  //            $weeks = 0;
 871  //        }
 872  //        $first_week_days %= 7;
 873  //        return (ceil((Date_Calc::daysInMonth($month, $year) - $first_week_days) / 7) + $weeks);
 874  //    } // end func weeksInMonth
 875  //
 876  //    /**
 877  //     * Find the day of the week for the first of the month of given date.
 878  //     *
 879  //     * @param string month in format MM, default is current local month
 880  //     * @param string year in format CCYY, default is current local year
 881  //     *
 882  //     * @access public
 883  //     *
 884  //     * @return int number of weekday for the first day, 0=Sunday
 885  //     */
 886  //
 887  //    function firstOfMonthWeekday($month='',$year='')
 888  //    {
 889  //        if (empty($year)) {
 890  //            $year = Date_Calc::dateNow('%Y');
 891  //        }
 892  //        if (empty($month)) {
 893  //            $month = Date_Calc::dateNow('%m');
 894  //        }
 895  //
 896  //        return(Date_Calc::dayOfWeek('01',$month,$year));
 897  //    } // end func firstOfMonthWeekday
 898  //
 899  //    /**
 900  //     * Return date of first day of month of given date.
 901  //     *
 902  //     * @param string month in format MM, default is current local month
 903  //     * @param string year in format CCYY, default is current local year
 904  //     * @param string format for returned date
 905  //     *
 906  //     * @access public
 907  //     *
 908  //     * @return string date in given format
 909  //     */
 910  //
 911  //    function beginOfMonth($month='',$year='',$format='%Y%m%d')
 912  //    {
 913  //        if (empty($year)) {
 914  //            $year = Date_Calc::dateNow('%Y');
 915  //        }
 916  //        if (empty($month)) {
 917  //            $month = Date_Calc::dateNow('%m');
 918  //        }
 919  //
 920  //        return(Date_Calc::dateFormat('01',$month,$year,$format));
 921  //    } // end of func beginOfMonth
 922  //
 923  //    /**
 924  //     * Find the month day of the beginning of week for given date,
 925  //     * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)
 926  //     *
 927  //     * @param string day in format DD, default is current local day
 928  //     * @param string month in format MM, default is current local month
 929  //     * @param string year in format CCYY, default is current local year
 930  //     * @param string format for returned date
 931  //     *
 932  //     * @access public
 933  //     *
 934  //     * @return string date in given format
 935  //     */
 936  //
 937  //    function beginOfWeek($day='',$month='',$year='',$format='%Y%m%d')
 938  //    {
 939  //        if (empty($year)) {
 940  //            $year = Date_Calc::dateNow('%Y');
 941  //        }
 942  //        if (empty($month)) {
 943  //            $month = Date_Calc::dateNow('%m');
 944  //        }
 945  //        if (empty($day)) {
 946  //            $day = Date_Calc::dateNow('%d');
 947  //        }
 948  //
 949  //        $this_weekday = Date_Calc::dayOfWeek($day,$month,$year);
 950  //
 951  //        $interval = (7 - DATE_CALC_BEGIN_WEEKDAY + $this_weekday) % 7;
 952  //
 953  //        return(Date_Calc::daysToDate(Date_Calc::dateToDays($day,$month,$year) - $interval,$format));
 954  //    } // end of func beginOfWeek
 955  //
 956  //    /**
 957  //     * Find the month day of the end of week for given date,
 958  //     * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday
 959  //     * of following month.)
 960  //     *
 961  //     * @param string day in format DD, default is current local day
 962  //     * @param string month in format MM, default is current local month
 963  //     * @param string year in format CCYY, default is current local year
 964  //     * @param string format for returned date
 965  //     *
 966  //     * @access public
 967  //     *
 968  //     * @return string date in given format
 969  //     */
 970  //
 971  //    function endOfWeek($day='',$month='',$year='',$format='%Y%m%d')
 972  //    {
 973  //        if (empty($year)) {
 974  //            $year = Date_Calc::dateNow('%Y');
 975  //        }
 976  //        if (empty($month)) {
 977  //            $month = Date_Calc::dateNow('%m');
 978  //        }
 979  //        if (empty($day)) {
 980  //            $day = Date_Calc::dateNow('%d');
 981  //        }
 982  //
 983  //
 984  //        $this_weekday = Date_Calc::dayOfWeek($day,$month,$year);
 985  //
 986  //        $interval = (6 + DATE_CALC_BEGIN_WEEKDAY - $this_weekday) % 7;
 987  //
 988  //        return(Date_Calc::daysToDate(Date_Calc::dateToDays($day,$month,$year) + $interval,$format));
 989  //    } // end func endOfWeek
 990  //
 991  //    /**
 992  //     * Find the month day of the beginning of week after given date,
 993  //     * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)
 994  //     *
 995  //     * @param string day in format DD, default is current local day
 996  //     * @param string month in format MM, default is current local month
 997  //     * @param string year in format CCYY, default is current local year
 998  //     * @param string format for returned date
 999  //     *
1000  //     * @access public
1001  //     *
1002  //     * @return string date in given format
1003  //     */
1004  //
1005  //    function beginOfNextWeek($day='',$month='',$year='',$format='%Y%m%d')
1006  //    {
1007  //        if (empty($year)) {
1008  //            $year = Date_Calc::dateNow("%Y");
1009  //        }
1010  //        if (empty($month)) {
1011  //            $month = Date_Calc::dateNow("%m");
1012  //        }
1013  //        if (empty($day)) {
1014  //            $day = Date_Calc::dateNow("%d");
1015  //        }
1016  //
1017  //        $date = Date_Calc::daysToDate(
1018  //                    Date_Calc::dateToDays($day+7,$month,$year),"%Y%m%d"
1019  //                );
1020  //
1021  //        $next_week_year = substr($date,0,4);
1022  //        $next_week_month = substr($date,4,2);
1023  //        $next_week_day = substr($date,6,2);
1024  //
1025  //        return Date_Calc::beginOfWeek(
1026  //                            $next_week_day,$next_week_month,$next_week_year,
1027  //                            $format
1028  //                        );
1029  //
1030  //        $date = Date_Calc::daysToDate(Date_Calc::dateToDays($day+7,$month,$year),"%Y%m%d");
1031  //    } // end func beginOfNextWeek
1032  //
1033  //    /**
1034  //     * Find the month day of the beginning of week before given date,
1035  //     * using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)
1036  //     *
1037  //     * @param string day in format DD, default is current local day
1038  //     * @param string month in format MM, default is current local month
1039  //     * @param string year in format CCYY, default is current local year
1040  //     * @param string format for returned date
1041  //     *
1042  //     * @access public
1043  //     *
1044  //     * @return string date in given format
1045  //     */
1046  //
1047  //    function beginOfPrevWeek($day='',$month='',$year='',$format='%Y%m%d')
1048  //    {
1049  //        if (empty($year)) {
1050  //            $year = Date_Calc::dateNow("%Y");
1051  //        }
1052  //        if (empty($month)) {
1053  //            $month = Date_Calc::dateNow("%m");
1054  //        }
1055  //        if (empty($day)) {
1056  //            $day = Date_Calc::dateNow("%d");
1057  //        }
1058  //
1059  //        $date = Date_Calc::daysToDate(
1060  //                        Date_Calc::dateToDays($day-7,$month,$year),"%Y%m%d"
1061  //                    );
1062  //
1063  //        $prev_week_year = substr($date,0,4);
1064  //        $prev_week_month = substr($date,4,2);
1065  //        $prev_week_day = substr($date,6,2);
1066  //
1067  //        return Date_Calc::beginOfWeek($prev_week_day,$prev_week_month,$prev_week_year,$format);
1068  //
1069  //
1070  //        $date = Date_Calc::daysToDate(Date_Calc::dateToDays($day-7,$month,$year),"%Y%m%d");
1071  //    } // end func beginOfPrevWeek
1072  //
1073  //    /**
1074  //     * Return an array with days in week
1075  //     *
1076  //     * @param string day in format DD, default is current local day
1077  //     * @param string month in format MM, default is current local month
1078  //     * @param string year in format CCYY, default is current local year
1079  //     * @param string format for returned date
1080  //     *
1081  //     * @access public
1082  //     *
1083  //     * @return array $week[$weekday]
1084  //     */
1085  //
1086  //    function getCalendarWeek($day='',$month='',$year='',$format='%Y%m%d')
1087  //    {
1088  //        if (empty($year)) {
1089  //            $year = Date_Calc::dateNow('%Y');
1090  //        }
1091  //        if (empty($month)) {
1092  //            $month = Date_Calc::dateNow('%m');
1093  //        }
1094  //        if (empty($day)) {
1095  //            $day = Date_Calc::dateNow('%d');
1096  //        }
1097  //
1098  //        $week_array = array();
1099  //
1100  //        // date for the column of week
1101  //
1102  //        $curr_day = Date_Calc::beginOfWeek($day,$month,$year,'%E');
1103  //
1104  //        for($counter=0; $counter <= 6; $counter++) {
1105  //            $week_array[$counter] = Date_Calc::daysToDate($curr_day,$format);
1106  //            $curr_day++;
1107  //        }
1108  //
1109  //        return $week_array;
1110  //    } // end func getCalendarWeek
1111  //
1112  //    /**
1113  //     * Return a set of arrays to construct a calendar month for
1114  //     * the given date.
1115  //     *
1116  //     * @param string month in format MM, default is current local month
1117  //     * @param string year in format CCYY, default is current local year
1118  //     * @param string format for returned date
1119  //     *
1120  //     * @access public
1121  //     *
1122  //     * @return array $month[$row][$col]
1123  //     */
1124  //
1125  //    function getCalendarMonth($month='',$year='',$format='%Y%m%d')
1126  //    {
1127  //        if (empty($year)) {
1128  //            $year = Date_Calc::dateNow('%Y');
1129  //        }
1130  //        if (empty($month)) {
1131  //            $month = Date_Calc::dateNow('%m');
1132  //        }
1133  //
1134  //        $month_array = array();
1135  //
1136  //        // date for the first row, first column of calendar month
1137  //        if (DATE_CALC_BEGIN_WEEKDAY == 1) {
1138  //            if (Date_Calc::firstOfMonthWeekday($month,$year) == 0) {
1139  //                $curr_day = Date_Calc::dateToDays('01',$month,$year) - 6;
1140  //            } else {
1141  //                $curr_day = Date_Calc::dateToDays('01',$month,$year)
1142  //                    - Date_Calc::firstOfMonthWeekday($month,$year) + 1;
1143  //            }
1144  //        } else {
1145  //            $curr_day = (Date_Calc::dateToDays('01',$month,$year)
1146  //                - Date_Calc::firstOfMonthWeekday($month,$year));
1147  //        }
1148  //
1149  //        // number of days in this month
1150  //        $daysInMonth = Date_Calc::daysInMonth($month,$year);
1151  //
1152  //        $weeksInMonth = Date_Calc::weeksInMonth($month,$year);
1153  //        for($row_counter=0; $row_counter < $weeksInMonth; $row_counter++) {
1154  //            for($column_counter=0; $column_counter <= 6; $column_counter++) {
1155  //                $month_array[$row_counter][$column_counter] =
1156  //                    Date_Calc::daysToDate($curr_day,$format);
1157  //                $curr_day++;
1158  //            }
1159  //        }
1160  //
1161  //        return $month_array;
1162  //    } // end func getCalendarMonth
1163  //
1164  //    /**
1165  //     * Return a set of arrays to construct a calendar year for
1166  //     * the given date.
1167  //     *
1168  //     * @param string year in format CCYY, default current local year
1169  //     * @param string format for returned date
1170  //     *
1171  //     * @access public
1172  //     *
1173  //     * @return array $year[$month][$row][$col]
1174  //     */
1175  //
1176  //    function getCalendarYear($year='',$format='%Y%m%d')
1177  //    {
1178  //        if (empty($year)) {
1179  //            $year = Date_Calc::dateNow('%Y');
1180  //        }
1181  //
1182  //        $year_array = array();
1183  //
1184  //        for($curr_month=0; $curr_month <=11; $curr_month++) {
1185  //            $year_array[$curr_month] =
1186  //                Date_Calc::getCalendarMonth(sprintf('%02d',$curr_month+1),$year,$format);
1187  //        }
1188  //
1189  //        return $year_array;
1190  //    } // end func getCalendarYear
1191  //
1192      /**
1193       * Converts a date to number of days since a
1194       * distant unspecified epoch.
1195       *
1196       * @param string day in format DD
1197       * @param string month in format MM
1198       * @param string year in format CCYY
1199       *
1200       * @access public
1201       *
1202       * @return integer number of days
1203       */
1204  
1205      function dateToDays($day,$month,$year)
1206      {
1207  
1208          $century = (int) substr($year,0,2);
1209          $year = (int) substr($year,2,2);
1210  
1211          if ($month > 2) {
1212              $month -= 3;
1213          } else {
1214              $month += 9;
1215              if ($year) {
1216                  $year--;
1217              } else {
1218                  $year = 99;
1219                  $century --;
1220              }
1221          }
1222  
1223          return (floor(( 146097 * $century) / 4 ) +
1224              floor(( 1461 * $year) / 4 ) +
1225              floor(( 153 * $month + 2) / 5 ) +
1226              $day + 1721119);
1227      } 
1228  
1229      /**
1230       * Converts number of days to a distant unspecified epoch.
1231       *
1232       * @param int number of days
1233       * @param string format for returned date
1234       *
1235       * @access public
1236       *
1237       * @return string date in specified format
1238       */
1239  
1240      function daysToDate($days,$format='%Y%m%d')
1241      {
1242  
1243          $days       -=  1721119;
1244          $century    =   floor(( 4 * $days - 1) / 146097);
1245          $days       =   floor(4 * $days - 1 - 146097 * $century);
1246          $day        =   floor($days / 4);
1247  
1248          $year       =   floor(( 4 * $day +  3) / 1461);
1249          $day        =   floor(4 * $day +  3 - 1461 * $year);
1250          $day        =   floor(($day +  4) / 4);
1251  
1252          $month      =   floor(( 5 * $day - 3) / 153);
1253          $day        =   floor(5 * $day - 3 - 153 * $month);
1254          $day        =   floor(($day +  5) /  5);
1255  
1256          if ($month < 10) {
1257              $month +=3;
1258          } else {
1259              $month -=9;
1260              if ($year++ == 99) {
1261                  $year = 0;
1262                  $century++;
1263              }
1264          }
1265  
1266          $century = sprintf('%02d',$century);
1267          $year = sprintf('%02d',$year);
1268          return(Date_Calc::dateFormat($day,$month,$century.$year,$format));
1269      }
1270  
1271  //    /**
1272  //     * Calculates the date of the Nth weekday of the month,
1273  //     * such as the second Saturday of January 2000.
1274  //     *
1275  //     * @param string occurance: 1=first, 2=second, 3=third, etc.
1276  //     * @param string dayOfWeek: 0=Sunday, 1=Monday, etc.
1277  //     * @param string month in format MM
1278  //     * @param string year in format CCYY
1279  //     * @param string format for returned date
1280  //     *
1281  //     * @access public
1282  //     *
1283  //     * @return string date in given format
1284  //     */
1285  //
1286  //    function NWeekdayOfMonth($occurance,$dayOfWeek,$month,$year,$format='%Y%m%d')
1287  //    {
1288  //        $year = sprintf('%04d',$year);
1289  //        $month = sprintf('%02d',$month);
1290  //
1291  //        $DOW1day = sprintf('%02d',(($occurance - 1) * 7 + 1));
1292  //        $DOW1 = Date_Calc::dayOfWeek($DOW1day,$month,$year);
1293  //
1294  //        $wdate = ($occurance - 1) * 7 + 1 +
1295  //                (7 + $dayOfWeek - $DOW1) % 7;
1296  //
1297  //        if ( $wdate > Date_Calc::daysInMonth($month,$year)) {
1298  //            return -1;
1299  //        } else {
1300  //            return(Date_Calc::dateFormat($wdate,$month,$year,$format));
1301  //        }
1302  //    } // end func NWeekdayOfMonth
1303  //
1304      /**
1305       *  Formats the date in the given format, much like
1306       *  strfmt(). This function is used to alleviate the
1307       *  problem with 32-bit numbers for dates pre 1970
1308       *  or post 2038, as strfmt() has on most systems.
1309       *  Most of the formatting options are compatible.
1310       *
1311       *  formatting options:
1312       *
1313       *  %a        abbreviated weekday name (Sun, Mon, Tue)
1314       *  %A        full weekday name (Sunday, Monday, Tuesday)
1315       *  %b        abbreviated month name (Jan, Feb, Mar)
1316       *  %B        full month name (January, February, March)
1317       *  %d        day of month (range 00 to 31)
1318       *  %e        day of month, single digit (range 0 to 31)
1319       *  %E        number of days since unspecified epoch (integer)
1320       *             (%E is useful for passing a date in a URL as
1321       *             an integer value. Then simply use
1322       *             daysToDate() to convert back to a date.)
1323       *  %j        day of year (range 001 to 366)
1324       *  %m        month as decimal number (range 1 to 12)
1325       *  %n        newline character (\n)
1326       *  %t        tab character (\t)
1327       *  %w        weekday as decimal (0 = Sunday)
1328       *  %U        week number of current year, first sunday as first week
1329       *  %y        year as decimal (range 00 to 99)
1330       *  %Y        year as decimal including century (range 0000 to 9999)
1331       *  %%        literal '%'
1332       *
1333       * @param string day in format DD
1334       * @param string month in format MM
1335       * @param string year in format CCYY
1336       * @param string format for returned date
1337       *
1338       * @access public
1339       *
1340       * @return string date in given format
1341       */
1342  
1343      function dateFormat($day,$month,$year,$format)
1344      {
1345          if (!Date_Calc::isValidDate($day,$month,$year)) {
1346              $year = Date_Calc::dateNow('%Y');
1347              $month = Date_Calc::dateNow('%m');
1348              $day = Date_Calc::dateNow('%d');
1349          }
1350  
1351          $output = '';
1352  
1353          for($strpos = 0; $strpos < strlen($format); $strpos++) {
1354              $char = substr($format,$strpos,1);
1355              if ($char == '%') {
1356                  $nextchar = substr($format,$strpos + 1,1);
1357                  switch($nextchar) {
1358                      case 'a':
1359                          $output .= Date_Calc::getWeekdayAbbrname($day,$month,$year);
1360                          break;
1361                      case 'A':
1362                          $output .= Date_Calc::getWeekdayFullname($day,$month,$year);
1363                          break;
1364                      case 'b':
1365                          $output .= Date_Calc::getMonthAbbrname($month);
1366                          break;
1367                      case 'B':
1368                          $output .= Date_Calc::getMonthFullname($month);
1369                          break;
1370                      case 'd':
1371                          $output .= sprintf('%02d',$day);
1372                          break;
1373                      case 'e':
1374                          $output .= $day;
1375                          break;
1376                      case 'E':
1377                          $output .= Date_Calc::dateToDays($day,$month,$year);
1378                          break;
1379                      case 'j':
1380                          $output .= Date_Calc::julianDate($day,$month,$year);
1381                          break;
1382                      case 'm':
1383                          $output .= sprintf('%02d',$month);
1384                          break;
1385                      case 'n':
1386                          $output .= "\n";
1387                          break;
1388                      case "t":
1389                          $output .= "\t";
1390                          break;
1391                      case 'w':
1392                          $output .= Date_Calc::dayOfWeek($day,$month,$year);
1393                          break;
1394                      case 'U':
1395                          $output .= Date_Calc::weekOfYear($day,$month,$year);
1396                          break;
1397                      case 'y':
1398                          $output .= substr($year,2,2);
1399                          break;
1400                      case 'Y':
1401                          $output .= $year;
1402                          break;
1403                      case '%':
1404                          $output .= '%';
1405                          break;
1406                      default:
1407                          $output .= $char.$nextchar;
1408                  }
1409                  $strpos++;
1410              } else {
1411                  $output .= $char;
1412              }
1413          }
1414          return $output;
1415      }
1416  
1417  //    /**
1418  //     * Returns the current local year in format CCYY
1419  //     *
1420  //     * @access public
1421  //     *
1422  //     * @return string year in format CCYY
1423  //     */
1424  //
1425  //    function getYear()
1426  //    {
1427  //        return Date_Calc::dateNow('%Y');
1428  //    } // end func getYear
1429  //
1430  //    /**
1431  //     * Returns the current local month in format MM
1432  //     *
1433  //     * @access public
1434  //     *
1435  //     * @return string month in format MM
1436  //     */
1437  //
1438  //    function getMonth()
1439  //    {
1440  //        return Date_Calc::dateNow('%m');
1441  //    } // end func getMonth
1442  //
1443  //    /**
1444  //     * Returns the current local day in format DD
1445  //     *
1446  //     * @access public
1447  //     *
1448  //     * @return string day in format DD
1449  //     */
1450  //
1451  //    function getDay()
1452  //    {
1453  //        return Date_Calc::dateNow('%d');
1454  //    } // end func getDay
1455  //
1456  //    /**
1457  //     * Returns the full month name for the given month
1458  //     *
1459  //     * @param string month in format MM
1460  //     *
1461  //     * @access public
1462  //     *
1463  //     * @return string full month name
1464  //     */
1465  //
1466  //    function getMonthFullname($month)
1467  //    {
1468  //        $month = (int)$month;
1469  //
1470  //        if (empty($month)) {
1471  //            $month = (int) Date_Calc::dateNow('%m');
1472  //        }
1473  //
1474  //        $month_names = Date_Calc::getMonthNames();
1475  //
1476  //        return $month_names[$month];
1477  //        // getMonthNames returns months with correct indexes
1478  //        //return $month_names[($month - 1)];
1479  //    } // end func getMonthFullname
1480  //
1481  //    /**
1482  //     * Returns the abbreviated month name for the given month
1483  //     *
1484  //     * @param string month in format MM
1485  //     * @param int optional length of abbreviation, default is 3
1486  //     *
1487  //     * @access public
1488  //     *
1489  //     * @return string abbreviated month name
1490  //     * @see Date_Calc::getMonthFullname
1491  //     */
1492  //
1493  //    function getMonthAbbrname($month,$length=3)
1494  //    {
1495  //        $month = (int)$month;
1496  //
1497  //        if (empty($month)) {
1498  //            $month = Date_Calc::dateNow('%m');
1499  //        }
1500  //
1501  //        return substr(Date_Calc::getMonthFullname($month), 0, $length);
1502  //    } // end func getMonthAbbrname
1503  //
1504  //    /**
1505  //     * Returns the full weekday name for the given date
1506  //     *
1507  //     * @param string day in format DD, default is current local day
1508  //     * @param string month in format MM, default is current local month
1509  //     * @param string year in format CCYY, default is current local year
1510  //     *
1511  //     * @access public
1512  //     *
1513  //     * @return string full month name
1514  //     */
1515  //
1516  //    function getWeekdayFullname($day='',$month='',$year='')
1517  //    {
1518  //        if (empty($year)) {
1519  //            $year = Date_Calc::dateNow('%Y');
1520  //        }
1521  //        if (empty($month)) {
1522  //            $month = Date_Calc::dateNow('%m');
1523  //        }
1524  //        if (empty($day)) {
1525  //            $day = Date_Calc::dateNow('%d');
1526  //        }
1527  //
1528  //        $weekday_names = Date_Calc::getWeekDays();
1529  //        $weekday = Date_Calc::dayOfWeek($day,$month,$year);
1530  //
1531  //        return $weekday_names[$weekday];
1532  //    } // end func getWeekdayFullname
1533  //
1534  //    /**
1535  //     * Returns the abbreviated weekday name for the given date
1536  //     *
1537  //     * @param string day in format DD, default is current local day
1538  //     * @param string month in format MM, default is current local month
1539  //     * @param string year in format CCYY, default is current local year
1540  //     * @param int optional length of abbreviation, default is 3
1541  //     *
1542  //     * @access public
1543  //     *
1544  //     * @return string full month name
1545  //     * @see Date_Calc::getWeekdayFullname
1546  //     */
1547  //
1548  //    function getWeekdayAbbrname($day='',$month='',$year='',$length=3)
1549  //    {
1550  //        if (empty($year)) {
1551  //            $year = Date_Calc::dateNow('%Y');
1552  //        }
1553  //        if (empty($month)) {
1554  //            $month = Date_Calc::dateNow('%m');
1555  //        }
1556  //        if (empty($day)) {
1557  //            $day = Date_Calc::dateNow('%d');
1558  //        }
1559  //
1560  //        return substr(Date_Calc::getWeekdayFullname($day,$month,$year),0,$length);
1561  //    } // end func getWeekdayFullname
1562  //
1563  //    /**
1564  //    * Returns the numeric month from the month name or an abreviation
1565  //    *
1566  //    * Both August and Aug would return 8.
1567  //    * Month name is case insensitive.
1568  //    *
1569  //    * @param    string  month name
1570  //    * @return   integer month number
1571  //    */
1572  //    function getMonthFromFullName($month)
1573  //    {
1574  //        $month = strtolower($month);
1575  //        $months = Date_Calc::getMonthNames();
1576  //        while(list($id, $name) = each($months)) {
1577  //            if (ereg($month, strtolower($name))) {
1578  //                return($id);
1579  //            }
1580  //        }
1581  //
1582  //        return(0);
1583  //    } // end func getMonthFromFullName
1584  //
1585  //    /**
1586  //    * Returns an array of month names
1587  //    *
1588  //    * Used to take advantage of the setlocale function to return
1589  //    * language specific month names.
1590  //    * XXX cache values to some global array to avoid preformace
1591  //    * hits when called more than once.
1592  //    *
1593  //    * @returns array An array of month names
1594  //    */
1595  //    function getMonthNames()
1596  //    {
1597  //        for($i=1;$i<13;$i++) {
1598  //            $months[$i] = strftime('%B', mktime(0, 0, 0, $i, 1, 2001));
1599  //        }
1600  //        return($months);
1601  //    } // end func getMonthNames
1602  //
1603  //    /**
1604  //    * Returns an array of week days
1605  //    *
1606  //    * Used to take advantage of the setlocale function to
1607  //    * return language specific week days
1608  //    * XXX cache values to some global array to avoid preformace
1609  //    * hits when called more than once.
1610  //    *
1611  //    * @returns array An array of week day names
1612  //    */
1613  //    function getWeekDays()
1614  //    {
1615  //        for($i=0;$i<7;$i++) {
1616  //            $weekdays[$i] = strftime('%A', mktime(0, 0, 0, 1, $i, 2001));
1617  //        }
1618  //        return($weekdays);
1619  //    } // end func getWeekDays
1620  //
1621  //    /**
1622  //     * Converts from Gregorian Year-Month-Day to
1623  //     * ISO YearNumber-WeekNumber-WeekDay
1624  //     *
1625  //     * Uses ISO 8601 definitions.
1626  //     * Algorithm from Rick McCarty, 1999 at
1627  //     * http://personal.ecu.edu/mccartyr/ISOwdALG.txt
1628  //     *
1629  //     * @param string day in format DD
1630  //     * @param string month in format MM
1631  //     * @param string year in format CCYY
1632  //     * @return string
1633  //     * @access public
1634  //     */
1635  //    // Transcribed to PHP by Jesus M. Castagnetto (blame him if it is fubared ;-)
1636  //    function gregorianToISO($day,$month,$year) {
1637  //        $mnth = array (0,31,59,90,120,151,181,212,243,273,304,334);
1638  //        $y_isleap = Date_Calc::isLeapYear($year);
1639  //        $y_1_isleap = Date_Calc::isLeapYear($year - 1);
1640  //        $day_of_year_number = $day + $mnth[$month - 1];
1641  //        if ($y_isleap && $month > 2) {
1642  //            $day_of_year_number++;
1643  //        }
1644  //        // find Jan 1 weekday (monday = 1, sunday = 7)
1645  //        $yy = ($year - 1) % 100;
1646  //        $c = ($year - 1) - $yy;
1647  //        $g = $yy + intval($yy/4);
1648  //        $jan1_weekday = 1 + intval((((($c / 100) % 4) * 5) + $g) % 7);
1649  //        // weekday for year-month-day
1650  //        $h = $day_of_year_number + ($jan1_weekday - 1);
1651  //        $weekday = 1 + intval(($h - 1) % 7);
1652  //        // find if Y M D falls in YearNumber Y-1, WeekNumber 52 or
1653  //        if ($day_of_year_number <= (8 - $jan1_weekday) && $jan1_weekday > 4){
1654  //            $yearnumber = $year - 1;
1655  //            if ($jan1_weekday == 5 || ($jan1_weekday == 6 && $y_1_isleap)) {
1656  //                $weeknumber = 53;
1657  //            } else {
1658  //                $weeknumber = 52;
1659  //            }
1660  //        } else {
1661  //            $yearnumber = $year;
1662  //        }
1663  //        // find if Y M D falls in YearNumber Y+1, WeekNumber 1
1664  //        if ($yearnumber == $year) {
1665  //            if ($y_isleap) {
1666  //                $i = 366;
1667  //            } else {
1668  //                $i = 365;
1669  //            }
1670  //            if (($i - $day_of_year_number) < (4 - $weekday)) {
1671  //                $yearnumber++;
1672  //                $weeknumber = 1;
1673  //            }
1674  //        }
1675  //        // find if Y M D falls in YearNumber Y, WeekNumber 1 through 53
1676  //        if ($yearnumber == $year) {
1677  //            $j = $day_of_year_number + (7 - $weekday) + ($jan1_weekday - 1);
1678  //            $weeknumber = intval($j / 7);
1679  //            if ($jan1_weekday > 4) {
1680  //                $weeknumber--;
1681  //            }
1682  //        }
1683  //        // put it all together
1684  //        if ($weeknumber < 10)
1685  //            $weeknumber = '0'.$weeknumber;
1686  //        return "{$yearnumber}-{$weeknumber}-{$weekday}";
1687  //    }
1688  //
1689  //    /**
1690  //    * Determines julian date of the given season
1691  //    * Adapted from previous work in Java by James Mark Hamilton, mhamilton@qwest.net
1692  //    *
1693  //    * @author Robert Butler <rob@maxwellcreek.org>
1694  //    *
1695  //    * @param string is VERNALEQUINOX, SUMMERSOLSTICE, AUTUMNALEQUINOX, or WINTERSOLSTICE.
1696  //    * @param string year in format CCYY, must be a calendar year between -1000BC and 3000AD.
1697  //    *
1698  //    * @access public
1699  //    *
1700  //    * @return float $juliandate
1701  //    */
1702  //
1703  //    function dateSeason ($season, $year = '') {
1704  //            if ($year == '') {
1705  //                    $year = Date_Calc::dateNow('%Y');
1706  //            }
1707  //
1708  //            if (($year >= -1000) && ($year <= 1000)) {
1709  //                    $y = $year / 1000.0;
1710  //                    if ($season == 'VERNALEQUINOX') {
1711  //                            $juliandate = (((((((-0.00071 * $y) - 0.00111) * $y) + 0.06134) * $y) + 365242.1374) * $y) + 1721139.29189;
1712  //                    } else if ($season == 'SUMMERSOLSTICE') {
1713  //                            $juliandate = ((((((( 0.00025 * $y) + 0.00907) * $y) - 0.05323) * $y) + 365241.72562) * $y) + 1721233.25401;
1714  //                    } else if ($season == 'AUTUMNALEQUINOX') {
1715  //                            $juliandate = ((((((( 0.00074 * $y) - 0.00297) * $y) - 0.11677) * $y) + 365242.49558) * $y) + 1721325.70455;
1716  //                    } else if ($season == 'WINTERSOLSTICE') {
1717  //                            $juliandate = (((((((-0.00006 * $y) - 0.00933) * $y) - 0.00769) * $y) + 365242.88257) * $y) + 1721414.39987;
1718  //                    }
1719  //            } elseif (($year > 1000) && ($year <= 3000)) {
1720  //                    $y = ($year - 2000) / 1000;
1721  //                    if ($season == 'VERNALEQUINOX') {
1722  //                            $juliandate = (((((((-0.00057 * $y) - 0.00411) * $y) + 0.05169) * $y) + 365242.37404) * $y) + 2451623.80984;
1723  //                    } else if ($season == 'SUMMERSOLSTICE') {
1724  //                            $juliandate = (((((((-0.0003 * $y) + 0.00888) * $y) + 0.00325) * $y) + 365241.62603) * $y) + 2451716.56767;
1725  //                    } else if ($season == 'AUTUMNALEQUINOX') {
1726  //                            $juliandate = ((((((( 0.00078 * $y) + 0.00337) * $y) - 0.11575) * $y) + 365242.01767) * $y) + 2451810.21715;
1727  //                    } else if ($season == 'WINTERSOLSTICE') {
1728  //                            $juliandate = ((((((( 0.00032 * $y) - 0.00823) * $y) - 0.06223) * $y) + 365242.74049) * $y) + 2451900.05952;
1729  //                    }
1730  //            }
1731  //
1732  //            return ($juliandate);
1733  //    } // end func dateSeason
1734  //
1735  } // end class Date_Calc
1736  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics