Example #1
0
 /**
  * Parses a date into a AnewtDateTimeAtom instance. The function also accepts
  * AnewtDateTimeAtom instances. In that case the supplied instance is returned.
  * If parsing fails, null is returned.
  *
  * Note that in many cases you should just call one of the more specific
  * parsing methods instead.
  *
  * \param $date
  *   An int/string/AnewtDateTimeAtom which will be parsed.
  *
  * \return
  *   A newly created AnewtDateTimeAtom instance or null if parsing failed.
  *
  * \see AnewtDateTime::parse_timestamp
  * \see AnewtDateTime::parse_string
  * \see AnewtDateTime::parse_ymd
  */
 static function parse($date)
 {
     /* Integers are treated as unix timestamps */
     if (is_int($date)) {
         return AnewtDateTime::parse_timestamp($date);
     }
     /* Try to parse strings */
     if (is_string($date)) {
         return AnewtDateTime::parse_string($date);
     }
     /* Double parsing should be harmless */
     if ($date instanceof AnewtDateTimeAtom) {
         return $date;
     }
     /* Too bad, better luck next time... */
     return null;
 }