Beispiel #1
0
 /**
  * Gets the full name or abbriviated name of this month
  *
  * Gets the full name or abbriviated name of this month
  *
  * @access public
  * @param boolean $abbr abbrivate the name
  * @return string name of this month
  */
 function getMonthName($abbr = false)
 {
     if ($abbr) {
         return Date_Calc::getMonthAbbrname($this->month);
     } else {
         return Date_Calc::getMonthFullname($this->month);
     }
 }
Beispiel #2
0
 /**
  * Formats the date in the given format, much like strfmt()
  *
  * This function is used to alleviate the problem with 32-bit numbers for
  * dates pre 1970 or post 2038, as strfmt() has on most systems.
  * Most of the formatting options are compatible.
  *
  * Formatting options:
  * <pre>
  * %a   abbreviated weekday name (Sun, Mon, Tue)
  * %A   full weekday name (Sunday, Monday, Tuesday)
  * %b   abbreviated month name (Jan, Feb, Mar)
  * %B   full month name (January, February, March)
  * %d   day of month (range 00 to 31)
  * %e   day of month, single digit (range 0 to 31)
  * %E   number of days since unspecified epoch (integer)
  *        (%E is useful for passing a date in a URL as
  *        an integer value. Then simply use
  *        daysToDate() to convert back to a date.)
  * %j   day of year (range 001 to 366)
  * %m   month as decimal number (range 1 to 12)
  * %n   newline character (\n)
  * %t   tab character (\t)
  * %w   weekday as decimal (0 = Sunday)
  * %U   week number of current year, first sunday as first week
  * %y   year as decimal (range 00 to 99)
  * %Y   year as decimal including century (range 0000 to 9999)
  * %%   literal '%'
  * </pre>
  *
  * @param int    $day    the day of the month
  * @param int    $month  the month
  * @param int    $year   the year.  Use the complete year instead of the
  *                        abbreviated version.  E.g. use 2005, not 05.
  * @param string $format the format string
  *
  * @return   string     the date in the desired format
  * @access   public
  * @static
  */
 function dateFormat($day, $month, $year, $format)
 {
     if (!Date_Calc::isValidDate($day, $month, $year)) {
         $year = Date_Calc::dateNow('%Y');
         $month = Date_Calc::dateNow('%m');
         $day = Date_Calc::dateNow('%d');
     }
     $output = '';
     for ($strpos = 0; $strpos < strlen($format); $strpos++) {
         $char = substr($format, $strpos, 1);
         if ($char == '%') {
             $nextchar = substr($format, $strpos + 1, 1);
             switch ($nextchar) {
                 case 'a':
                     $output .= Date_Calc::getWeekdayAbbrname($day, $month, $year);
                     break;
                 case 'A':
                     $output .= Date_Calc::getWeekdayFullname($day, $month, $year);
                     break;
                 case 'b':
                     $output .= Date_Calc::getMonthAbbrname($month);
                     break;
                 case 'B':
                     $output .= Date_Calc::getMonthFullname($month);
                     break;
                 case 'd':
                     $output .= sprintf('%02d', $day);
                     break;
                 case 'e':
                     $output .= $day;
                     break;
                 case 'E':
                     $output .= Date_Calc::dateToDays($day, $month, $year);
                     break;
                 case 'j':
                     $output .= Date_Calc::dayOfYear($day, $month, $year);
                     break;
                 case 'm':
                     $output .= sprintf('%02d', $month);
                     break;
                 case 'n':
                     $output .= "\n";
                     break;
                 case 't':
                     $output .= "\t";
                     break;
                 case 'w':
                     $output .= Date_Calc::dayOfWeek($day, $month, $year);
                     break;
                 case 'U':
                     $output .= Date_Calc::weekOfYear($day, $month, $year);
                     break;
                 case 'y':
                     $output .= sprintf('%0' . ($year < 0 ? '3' : '2') . 'd', $year % 100);
                     break;
                 case "Y":
                     $output .= sprintf('%0' . ($year < 0 ? '5' : '4') . 'd', $year);
                     break;
                 case '%':
                     $output .= '%';
                     break;
                 default:
                     $output .= $char . $nextchar;
             }
             $strpos++;
         } else {
             $output .= $char;
         }
     }
     return $output;
 }
Beispiel #3
0
 /**
  *  Formats the date in the given format, much like
  *  strfmt(). This function is used to alleviate the
  *  problem with 32-bit numbers for dates pre 1970
  *  or post 2038, as strfmt() has on most systems.
  *  Most of the formatting options are compatible.
  *
  *  formatting options:
  *
  *  %a        abbreviated weekday name (Sun, Mon, Tue)
  *  %A        full weekday name (Sunday, Monday, Tuesday)
  *  %b        abbreviated month name (Jan, Feb, Mar)
  *  %B        full month name (January, February, March)
  *  %d        day of month (range 00 to 31)
  *  %e        day of month, single digit (range 0 to 31)
  *  %E        number of days since unspecified epoch (integer)
  *             (%E is useful for passing a date in a URL as
  *             an integer value. Then simply use
  *             daysToDate() to convert back to a date.)
  *  %j        day of year (range 001 to 366)
  *  %m        month as decimal number (range 1 to 12)
  *  %n        newline character (\n)
  *  %t        tab character (\t)
  *  %w        weekday as decimal (0 = Sunday)
  *  %U        week number of current year, first sunday as first week
  *  %y        year as decimal (range 00 to 99)
  *  %Y        year as decimal including century (range 0000 to 9999)
  *  %%        literal '%'
  *
  * @param string year in format CCYY
  * @param string month in format MM
  * @param string day in format DD
  * @param string format for returned date
  *
  * @access public
  *
  * @return string date in given format
  */
 function dateFormat($day, $month, $year, $format)
 {
     if (!Date_Calc::isValidDate($day, $month, $year)) {
         $year = Date_Calc::dateNow("%Y");
         $month = Date_Calc::dateNow("%m");
         $day = Date_Calc::dateNow("%d");
     }
     $output = "";
     for ($strpos = 0; $strpos < strlen($format); $strpos++) {
         $char = substr($format, $strpos, 1);
         if ($char == "%") {
             $nextchar = substr($format, $strpos + 1, 1);
             switch ($nextchar) {
                 case "a":
                     $output .= Date_Calc::getWeekdayAbbrname($day, $month, $year);
                     break;
                 case "A":
                     $output .= Date_Calc::getWeekdayFullname($day, $month, $year);
                     break;
                 case "b":
                     $output .= Date_Calc::getMonthAbbrname($month);
                     break;
                 case "B":
                     $output .= Date_Calc::getMonthFullname($month);
                     break;
                 case "d":
                     $output .= sprintf("%02d", $day);
                     break;
                 case "e":
                     $output .= $day;
                     break;
                 case "E":
                     $output .= Date_Calc::dateToDays($day, $month, $year);
                     break;
                 case "j":
                     $output .= Date_Calc::julianDate($day, $month, $year);
                     break;
                 case "m":
                     $output .= sprintf("%02d", $month);
                     break;
                 case "n":
                     $output .= "\n";
                     break;
                 case "t":
                     $output .= "\t";
                     break;
                 case "w":
                     $output .= Date_Calc::dayOfWeek($day, $month, $year);
                     break;
                 case "U":
                     $output .= Date_Calc::weekOfYear($day, $month, $year);
                     break;
                 case "y":
                     $output .= substr($year, 2, 2);
                     break;
                 case "Y":
                     $output .= $year;
                     break;
                 case "%":
                     $output .= "%";
                     break;
                 default:
                     $output .= $char . $nextchar;
             }
             $strpos++;
         } else {
             $output .= $char;
         }
     }
     return $output;
 }
Beispiel #4
0
compare('2000-47-3', Date_Calc::gregorianToISO('22', '11', '2000'), 'gregorianToISO str');
compare('2000-47-3', Date_Calc::gregorianToISO(22, 11, 2000), 'gregorianToISO');
compare(2451716.56767, Date_Calc::dateSeason('SUMMERSOLSTICE', 2000), 'dateSeason');
compare(date('Ymd'), Date_Calc::dateNow(), 'dateNow');
compare(date('Y'), Date_Calc::getYear(), 'getYear');
compare(date('m'), Date_Calc::getMonth(), 'getMonth');
compare(date('d'), Date_Calc::getDay(), 'getDay');
compare(327, Date_Calc::dayOfYear(22, 11, 2000), 'dayOfYear');
compare('November', Date_Calc::getMonthFullname(11), 'getMonthFullname');
compare('Nov', Date_Calc::getMonthAbbrname(11), 'getMonthAbbrname');
compare('Saturday', Date_Calc::getWeekdayFullname(1, 1, 2005), 'getWeekdayFullname');
compare('Sat', Date_Calc::getWeekdayAbbrname(1, 1, 2005), 'getWeekdayAbbrname');
compare(11, Date_Calc::getMonthFromFullName('November'), 'getMonthFromFullName');
compare(327, Date_Calc::dayOfYear('22', '11', '2000'), 'dayOfYear str');
compare('November', Date_Calc::getMonthFullname('11'), 'getMonthFullname str');
compare('Nov', Date_Calc::getMonthAbbrname('11'), 'getMonthAbbrname str');
compare('Saturday', Date_Calc::getWeekdayFullname('01', '01', '2005'), 'getWeekdayFullname str');
compare('Sat', Date_Calc::getWeekdayAbbrname('01', '01', '2005'), 'getWeekdayAbbrname str');
$exp = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
compare($exp, Date_Calc::getMonthNames(), 'getMonthNames');
$exp = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
compare($exp, Date_Calc::getWeekDays(), 'getWeekDays');
compare(3, Date_Calc::dayOfWeek(22, 11, 2000), 'dayOfWeek');
compare(47, Date_Calc::weekOfYear(22, 11, 2000), 'weekOfYear');
compare(4, Date_Calc::quarterOfYear(22, 11, 2000), 'quarterOfYear');
compare(3, Date_Calc::dayOfWeek('22', '11', '2000'), 'dayOfWeek str');
compare(47, Date_Calc::weekOfYear('22', '11', '2000'), 'weekOfYear str');
compare(4, Date_Calc::quarterOfYear('22', '11', '2000'), 'quarterOfYear str');
compare(28, Date_Calc::daysInMonth(2, 1900), 'daysInMonth 1');
compare(29, Date_Calc::daysInMonth(2, 1996), 'daysInMonth 2');
compare(29, Date_Calc::daysInMonth(2, 2000), 'daysInMonth 3');