Пример #1
0
 /**
  * Get the dates corresponding to one week, month and year from the start date
  *
  * @return array ('week'=>$week,'month'=>$month,'year'=>$year)
  *
  * @todo When support is dropped for php 5.1, switch to simpler code
  */
 public function calculate_dates_out()
 {
     list($year, $month, $day) = explode('-', $this->start_date);
     $year_out = carl_mktime(0, 0, 0, $month, $day, $year + 1);
     $month_out = carl_mktime(0, 0, 0, $month + 1, $day, $year);
     $week_out = carl_mktime(0, 0, 0, $month, $day + 7, $year);
     /* 
     		// Note: this is simpler code, but it won't support dates outside
     		// the Unix era until support for 5.1- is dropped.
     		
     		$u_start = prettify_mysql_datetime($this->start_date,'U');
     		
     		$year_out = strtotime('+1 year',$u_start);
     		$month_out = strtotime('+1 month',$u_start);
     		$week_out = strtotime('+1 week',$u_start); */
     $week = carl_date('Y-m-d', $week_out);
     $month = carl_date('Y-m-d', $month_out);
     $year = carl_date('Y-m-d', $year_out);
     return array('week' => $week, 'month' => $month, 'year' => $year);
 }
Пример #2
0
function mysql_date_to_unix($md)
{
    preg_match('/^([0-9]{4})-([0-9]{1,2})-([0-9][0-9]{1,2})$/', $md, $matches);
    return carl_mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]);
}
Пример #3
0
 /**
  * Convert a MySQL DATETIME field to a UNIX timestamp.
  * @param string
  * @return int or false if conversion fails
  * @see carl_mktime
  * @author Eric Naeseth
  */
 function mysql_datetime_to_unix($dt)
 {
     $year = $month = $day = $hour = $minute = $second = '';
     // y/m/d: if zero, subsequent values must be empty
     if ($year = substr($dt, 0, 4)) {
         if ($month = substr($dt, 5, 2)) {
             if ($day = substr($dt, 8, 2)) {
                 // h/m/s: can be zero with subsequent items being nonzero integers
                 $hour = substr($dt, 11, 2);
                 $minute = substr($dt, 14, 2);
                 $second = substr($dt, 17, 2);
             }
         }
     }
     // check for all 0s (an empty date)
     return (int) $year && (int) $month && (int) $day ? carl_mktime($hour, $minute, $second, $month, $day, $year) : false;
 }
Пример #4
0
 function get()
 {
     $all_fields_empty = true;
     foreach ($this->use_fields as $field_name) {
         if (!empty($this->{$field_name}) && $field_name != 'ampm') {
             $all_fields_empty = false;
             break;
         }
     }
     if ($all_fields_empty) {
         $date = false;
         //used to be 0; changed so that disco notices if this has no value.
     } else {
         if (in_array('hour', $this->use_fields)) {
             if ($this->hour == 12) {
                 if ($this->ampm == 'am') {
                     $this->hour = 0;
                 } else {
                     $this->hour = 12;
                 }
             } else {
                 // if PM is chosen, make sure to add 12 hours
                 if ($this->ampm == 'pm' and $this->hour < 12) {
                     $this->hour = $this->hour + 12;
                 }
             }
         }
         $date_format = $this->date_format;
         //if the day isn't set, give it a value while making the timestamp so that carl_maketime() doesn't increment back.
         //just make sure that it's not part of the date format when we're formatting the date from the timestamp.
         if (empty($this->day)) {
             $this->day = 1;
             $date_format = str_replace('-d', '', $date_format);
         }
         //if the month isn't set, give it a value while making the timestamp so that carl_maketime() doesn't increment back.
         //just make sure that it's not part of the date format when we're formatting the date from the timestamp.
         if (empty($this->month)) {
             $this->month = 1;
             $date_format = str_replace('-m', '', $date_format);
         }
         $timestamp = carl_mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
         $date = carl_date($date_format, $timestamp);
     }
     return $date;
 }