\
   |
   --DateTime

Class Details

An extension of PHP's DateTime class to provide dirty flagging and easier formatting options.

All date and datetime fields from your database will be created as instances of this class.

Example of formatting and changing the default format:

 $now = new ActiveRecord\DateTime('2010-01-02 03:04:05');
 ActiveRecord\DateTime::$DEFAULT_FORMAT = 'short';

 echo $now->format();         # 02 Jan 03:04
 echo $now->format('atom');   # 2010-01-02T03:04:05-05:00
 echo $now->format('Y-m-d');  # 2010-01-02

 # __toString() uses the default formatter
 echo (string)$now;           # 02 Jan 03:04

	

You can also add your own pre-defined friendly formatters:

 ActiveRecord\DateTime::$FORMATS['awesome_format'] = 'H:i:s m/d/Y';
 echo $now->format('awesome_format')  # 03:04:05 01/02/2010

	


Class Variables

public static mixed $DEFAULT_FORMAT = 'rfc2822'

Default format used for format() and __toString()

public static mixed $FORMATS = array( 'db' => 'Y-m-d H:i:s', 'number' => 'YmdHis', 'time' => 'H:i', 'short' => 'd M H:i', 'long' => 'F d, Y H:i', 'atom' => \DateTime::ATOM, 'cookie' => \DateTime::COOKIE, 'iso8601' => \DateTime::ISO8601, 'rfc822' => \DateTime::RFC822, 'rfc850' => \DateTime::RFC850, 'rfc1036' => \DateTime::RFC1036, 'rfc1123' => \DateTime::RFC1123, 'rfc2822' => \DateTime::RFC2822, 'rfc3339' => \DateTime::RFC3339, 'rss' => \DateTime::RSS, 'w3c' => \DateTime::W3C)

Pre-defined format strings.


Class Methods

public void attribute_of ( $model , $attribute_name )
  • $model -
  • $attribute_name -
public string format ( [ string $format = null] )

Formats the DateTime to the specified format.

  • string $format - A format string accepted by get_format()

 $datetime->format();         # uses the format defined in DateTime::$DEFAULT_FORMAT
 $datetime->format('short');  # d M H:i
 $datetime->format('Y-m-d');  # Y-m-d

	

public static string get_format ( [ string $format = null] )

Returns the format string.

  • string $format - A pre-defined string format or a raw format string

If $format is a pre-defined format in $FORMATS it will return that otherwise it will assume $format is a format string itself.

public void setDate ( $year , $month , $day )
  • $year -
  • $month -
  • $day -
public void setISODate ( $year , $week , [ $day = null] )
  • $year -
  • $week -
  • $day -
public void setTime ( $hour , $minute , [ $second = null] )
  • $hour -
  • $minute -
  • $second -
public void setTimestamp ( $unixtimestamp )
  • $unixtimestamp -
public void __toString ( )