Example #1
0
 /**
  * Add a selection drop down for the month and date to be selected.
  * @param string $name The name of the selection element
  * @param I2CE_Date $default The default I2CE_Date object to use to preset the value.
  * @param boolean $showError A flag if this field is currently invalid to mark it as such.
  * @param DOMNode $node The node to append the element to.
  * @param boolean $hidden Set to true if the form element should be hidden. Defaults to false
  * @param boolean $blank Set to true if this element should have a blank entry option. Defaults to false.
  */
 public static function addMonthDayElement($template, $name, $default, $showError, $node, $hidden = false, $blank = false)
 {
     if ($hidden) {
         $day = $template->createElement("input", array("name" => $name . "[day]", "type" => "hidden", "value" => $default->day()));
         $month = $template->createElement("input", array("name" => $name . "[month]", "type" => "hidden", "value" => $default->month()));
     } else {
         $day = $template->createElement("select", array("name" => $name . "[day]", "class" => "date_day" . ($showError ? "_error" : "")));
         if ($blank) {
             $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "Select");
             $day->appendChild($blank_opt);
         }
         for ($i = 1; $i <= 31; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isDay($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $day->appendChild($opt);
         }
         $month = $template->createElement("select", array("name" => $name . "[month]", "id" => $name, "class" => "date_month" . ($showError ? "_error" : "")));
         if ($blank) {
             $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "Select");
             $month->appendChild($blank_opt);
         }
         foreach (I2CE_Date::$months as $mon => $def_name) {
             $mon_name = $default->getMonthName($mon);
             $opt = $template->createElement("option", array("value" => $mon, "class" => $mon == "" ? "blank_opt" : ""), $mon_name);
             if ($default->isMonth($mon)) {
                 $opt->setAttribute("selected", "selected");
             }
             $month->appendChild($opt);
         }
     }
     $node->appendChild($day);
     $node->appendChild($month);
 }
Example #2
0
 /**
  * Compares a date to this one and returns -1 if it is before, 0 if the same and 1 if after
  * this date.
  * @param I2CE_Date $date
  * @return integer
  */
 public function compare($date)
 {
     if (!$date instanceof I2CE_Date) {
         I2CE::raiseError("Invalid date comparison");
         return null;
     }
     switch ($this->type) {
         case self::YEAR_ONLY:
             return bccomp($date->year(), $this->year);
             break;
         case self::YEAR_MONTH:
             $year_cmp = bccomp($date->year(), $this->year);
             if ($year_cmp == 0) {
                 return bccomp($date->month(), $this->month);
             } else {
                 return $year_cmp;
             }
             break;
         case self::MONTH_DAY:
             $month_cmp = bccomp($date->month(), $this->month);
             if ($month_cmp == 0) {
                 return bccomp($date->day(), $this->day);
             } else {
                 return $month_cmp;
             }
             break;
         case self::DATE:
             $year_cmp = bccomp($date->year(), $this->year);
             if ($year_cmp == 0) {
                 $month_cmp = bccomp($date->month(), $this->month);
                 if ($month_cmp == 0) {
                     return bccomp($date->day(), $this->day);
                 } else {
                     return $month_cmp;
                 }
             } else {
                 return $year_cmp;
             }
             break;
         case self::DATE_TIME:
             $year_cmp = bccomp($date->year(), $this->year);
             if ($year_cmp == 0) {
                 $month_cmp = bccomp($date->month(), $this->month);
                 if ($month_cmp == 0) {
                     $day_cmp = bccomp($date->day(), $this->day);
                     if ($day_cmp == 0) {
                         $hour_cmp = bccomp($date->hour(), $this->hour);
                         if ($hour_cmp == 0) {
                             $min_cmp = bccomp($date->minute(), $this->minute);
                             if ($min_cmp == 0) {
                                 return bccomp($date->second, $this->second);
                             } else {
                                 return $min_cmp;
                             }
                         } else {
                             return $hour_cmp;
                         }
                     } else {
                         return $day_cmp;
                     }
                 } else {
                     return $month_cmp;
                 }
             } else {
                 return $year_cmp;
             }
             break;
         case self::TIME_ONLY:
             $hour_cmp = bccomp($date->hour(), $this->hour);
             if ($hour_cmp == 0) {
                 $min_cmp = bccomp($date->minute(), $this->minute);
                 if ($min_cmp == 0) {
                     return bccomp($date->second, $this->second);
                 } else {
                     return $min_cmp;
                 }
             } else {
                 return $hour_cmp;
             }
             break;
         default:
             I2CE::raiseError("An invalid date type was used for I2CE_Date::compare.", E_USER_WARNING);
             return 0;
             break;
     }
 }