/** * Retrieve the timestamp from a number of different formats. * * @param mixed value to use for timestamp retrieval */ public static function getTS($value = null) { if ($value === null) { return sfDateTimeToolkit::now(); } else { if ($value instanceof sfDate) { return $value->get(); } else { if (!is_numeric($value)) { return strtotime($value); } else { if (is_numeric($value)) { return $value; } } } } throw new sfDateTimeException(sprintf('A timestamp could not be retrieved from the value: %s', $value)); }
/** * Returns the timestamp for the most recent (previous) occurance of [month]. * * @param timestamp * @param int the month of year * @return timestamp */ public static function previousMonth($ts = null, $month = sfTime::JANUARY) { // default to now if ($ts === null) { $ts = sfDateTimeToolkit::now(); } // get offsets from january $offset1 = date('m', $ts); $offset2 = $month; // adjust if date wraps into last year $offset1 += $offset1 > $offset2 ? 0 : 12; return sfTime::subtractMonth($ts, $offset1 - $offset2); }