You are here

public function EasyRdf_Literal_Date::__construct in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php \EasyRdf_Literal_Date::__construct()

Constructor for creating a new date literal

If the value is a DateTime object, then it will be converted to the xsd:date format. If no value is given or is is null, then the current date is used.

Parameters

mixed $value The value of the literal:

string $lang Should be null (literals with a datatype can't have a language):

string $datatype Optional datatype (default 'xsd:date'):

Return value

object EasyRdf_Literal_Date

Overrides EasyRdf_Literal::__construct

See also

DateTime

1 method overrides EasyRdf_Literal_Date::__construct()
EasyRdf_Literal_DateTime::__construct in vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/DateTime.php
Constructor for creating a new date and time literal

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php, line 60

Class

EasyRdf_Literal_Date
Class that represents an RDF Literal of datatype xsd:date

Code

public function __construct($value = null, $lang = null, $datatype = null) {

  // If $value is null, use today's date
  if (is_null($value)) {
    $value = new DateTime('today');
  }

  // Convert DateTime object into string
  if ($value instanceof DateTime) {
    $value = $value
      ->format('Y-m-d');
  }
  parent::__construct($value, null, $datatype);
}