Class: I2CE Date (4.1.12)

From IHRIS Wiki
(Redirected from Class: I2CE Date)


This article describes the class I2CE_Date .

  • Location: Part of the module I2CE in the package I2CE 4.1.12-release
  • Source: Defined in the file lib/I2CE_Date.php on line 33
  • Author: Luke Duncan <lduncan@intrahealth.org>
  • Since: v1.0.0

Handles date manipulation. I2CE_Dates are used to manage date and time values for form/HTML display and for interacting with the database.

Constants

I2CE_Date::YEAR_ONLY

Constant value to signify a date only including the year. Defined as: 1

I2CE_Date::MONTH_DAY

Constant value to signify a date only including the month and day of the month. Defined as: 2

I2CE_Date::DATE

Constant value to signify a date only including the date. Defined as: 3

I2CE_Date::DATE_TIME

Constant value to signify a date only including the date and time. Defined as: 4

I2CE_Date::TIME_ONLY

Constant value to signify a date only including the time. Defined as: 5

I2CE_Date::YEAR_MONTH

Constant value to signify a date only including the month and year. Defined as: 6

Variables

$second

The second value for the time.

$minute

The minute value for the time.

$hour

The hour value for the time.

$day

The day value for the date.

$month

The month value for the date.

$year

The year value for the date.

$type

The type of I2CE_Date object based on the constant values. Possible date types are YEAR_ONLY Year, MONTH_DAY Month and Day, DATE Date, DATE_TIME Date and Time, and TIME_ONLY Time.

$months

Array of month names. This should be modified to handle internationalization. The array of month names.

$date_formats

Array of formats to use to display dates. The array of date formats by type.

$intl_formats

Array of formats to use to display dates. The array of date formats by type.

$formatters

Array of IntlDateFormatter objects per locale and display types.

$types

A list of all valid types for I2CE_Date objects.

Methods

__construct()

Constructor method to create a new I2CE_Date object.

  • Defined in i2ce/lib/I2CE_Date.php on line 171
  • Signature: private function __construct($type)
  • Parameters:
    • integer $type
      The type of date object created. It defaults to date and time.
      • Default Value: self::DATE_TIME

addMonthDayElement()

Add a selection drop down for the month and date to be selected.

  • Defined in i2ce/lib/I2CE_Date.php on line 1084
  • Signature: static public function addMonthDayElement($template,$name,$default,$showError,$node,$hidden,$blank)
  • Parameters:
    • $template
    • string $name
      The name of the selection element
    • I2CE_Date $default
      The default I2CE_Date object to use to preset the value.
    • boolean $showError
      A flag if this field is currently invalid to mark it as such.
    • DOMNode $node
      The node to append the element to.
    • boolean $hidden
      Set to true if the form element should be hidden. Defaults to false
      • Default Value: false
    • boolean $blank
      Set to true if this element should have a blank entry option. Defaults to false.
      • Default Value: false

addTimeElement()

Add a selection drop down for the hour, minute and second to be selected.

  • Defined in i2ce/lib/I2CE_Date.php on line 1130
  • Signature: static public function addTimeElement($template,$name,$default,$showError,$node,$hidden)
  • Parameters:
    • $template
    • string $name
      The name of the selection element
    • I2CE_Date $default
      The default I2CE_Date object to use to preset the value.
    • boolean $showError
      A flag if this field is currently invalid to mark it as such.
    • DOMNode $node
      The node to append the element to.
    • boolean $hidden
      Set to true if the form element should be hidden.
      • Default Value: false

addYearElement()

Add a selection drop down for the year to be selected.

  • Defined in i2ce/lib/I2CE_Date.php on line 1001
  • Signature: static public function addYearElement($template,$name,$default,$showError,$node,$year_range,$hidden,$blank)
  • Parameters:
    • $template
    • string $name
      The name of the selection element
    • I2CE_Date $default
      The default I2CE_Date object to use to preset the value.
    • boolean $showError
      A flag if this field is currently invalid to mark it as such.
    • DOMNode $node
      The node to append the element to.
    • array $year_range
      The range of years to use for the drop down.
    • boolean $hidden
      Set to true if the form element should be hidden. Defaults to false.
      • Default Value: false
    • boolean $blank
      Set to true if this element should have a blank entry option. Defaults to false.
      • Default Value: false

addYearMonthElement()

Add a selection drop down for the year and month to be selected.

  • Defined in i2ce/lib/I2CE_Date.php on line 1036
  • Signature: static public function addYearMonthElement($template,$name,$default,$showError,$node,$year_range,$hidden,$blank)
  • Parameters:
    • $template
    • string $name
      The name of the selection element
    • I2CE_Date $default
      The default I2CE_Date object to use to preset the value.
    • boolean $showError
      A flag if this field is currently invalid to mark it as such.
    • DOMNode $node
      The node to append the element to.
    • array $year_range
      The range of years to use for the drop down.
    • boolean $hidden
      Set to true if the form element should be hidden. Defaults to false.
      • Default Value: false
    • boolean $blank
      Set to true if this element should have a blank entry option. Defaults to false.
      • Default Value: false

after()

Determines if a date is before the given date.

before()

Determines if a date is before the given date.

blank()

Create a blank date object with no values set for anything.

  • Defined in i2ce/lib/I2CE_Date.php on line 394
  • Signature: static public function blank($type)
  • Parameters:
    • integer $type
      The type of date object created. It defaults to date and time.
      • Default Value: self::DATE_TIME
  • Returns: I2CE_Date

compare()

Compares a date to this one and returns -1 if it is before, 0 if the same and 1 if after this date.

day()

  • Defined in i2ce/lib/I2CE_Date.php on line 650
  • Signature: public function day()
  • Returns: integer
    The day part of the date.

dbFormat()

Formats the date to be saved to MySQL Formats the date object to a string that MySQL will recognize based on the date type.

  • Defined in i2ce/lib/I2CE_Date.php on line 692
  • Signature: public function dbFormat($allow_blank)
  • Parameters:
    • boolean $allow_blank
      Defaults to false. If true we allow blank values in which case we return "0000-00-00 00:00:00"
      • Default Value: false
  • Returns: string

displayDate()

Displays the date in a readable format.

equals()

Determines if one date is identical to another.

fromDB()

Creates a date from a MySQL database formatted string The type of this date object is determined by the string. The possible types are Month/Day ('0000-MM-DD'), Year Only ('YYYY-00-00'), Date ('YYYY-MM-DD'), Date/Time ('YYYY-MM-DD HH:MM:SS'), and Time Only ('HH:MM:SS'). If the string is blank a blank () blank date is returned. If none of thse formats match the now () current date is returned.

  • Defined in i2ce/lib/I2CE_Date.php on line 510
  • Signature: static public function fromDB($dateString,$type)
  • Parameters:
    • string $dateString
      Date formatted string from MySQL
    • int $type
      Defaults to null in which the type is guessed from the {$dateString}. Otherwise it is one of I2CE_DATE::DATE, I2CE_DATE::YEAR_ONLY, etc.
      • Default Value: null
  • Returns: I2CE_Date

getDate()

Creates a date object of the type Date.

  • Defined in i2ce/lib/I2CE_Date.php on line 455
  • Signature: static public function getDate($day,$month,$year)
  • Parameters:
    • integer $day
      Sets the day of the month to be used
      • Default Value: -1
    • integer $month
      Sets the month to be used
      • Default Value: -1
    • integer $year
      Sets the year to be used.
      • Default Value: -1
  • Returns: I2CE_Date

getDateTime()

Creates a date object of the type Date/Time.

  • Defined in i2ce/lib/I2CE_Date.php on line 472
  • Signature: static public function getDateTime($sec,$min,$hour,$day,$month,$year)
  • Parameters:
    • integer $sec
      Sets the seconds to be used
      • Default Value: -1
    • integer $min
      Sets the minutes to be used
      • Default Value: -1
    • integer $hour
      Sets the hour to be used.
      • Default Value: -1
    • integer $day
      Sets the day of the month to be used
      • Default Value: -1
    • integer $month
      Sets the month to be used
      • Default Value: -1
    • integer $year
      Sets the year to be used.
      • Default Value: -1
  • Returns: I2CE_Date

getDateTimeObj()

Return a DateTime object to use for formatting this I2CE_Date object.

getDay()

Create a date object of the type Month/Day

  • Defined in i2ce/lib/I2CE_Date.php on line 442
  • Signature: static public function getDay($day,$month)
  • Parameters:
    • integer $day
      Sets the day of the month to be used
      • Default Value: -1
    • integer $month
      Sets the month to be used
      • Default Value: -1
  • Returns: I2CE_Date

getIntlFormatter()

Return the IntlDateFormatter for the given locale and date type.

  • Defined in i2ce/lib/I2CE_Date.php on line 138
  • Signature: public function getIntlFormatter($locale,$date_type)
  • Parameters:
  • Returns: IntlDateFormatter

getMonthName()

The month name text to be displayed for the given month number.

getTime()

Creates a date object of the type Time.

  • Defined in i2ce/lib/I2CE_Date.php on line 489
  • Signature: static public function getTime($sec,$min,$hour)
  • Parameters:
    • integer $sec
      Sets the seconds to be used
      • Default Value: -1
    • integer $min
      Sets the minutes to be used
      • Default Value: -1
    • integer $hour
      Sets the hour to be used.
      • Default Value: -1
  • Returns: I2CE_Date

getType()

get the type for this Date.

  • Defined in i2ce/lib/I2CE_Date.php on line 192
  • Signature: public function getType()
  • Returns: integer
    $type The type of date object created.

getValues()

Get the array of values associated to this date.

  • Defined in i2ce/lib/I2CE_Date.php on line 369
  • Signature: public function getValues()
  • Returns: array
    The keys of which match the names for generated html elements

getYear()

Create a date object of the type Year only.

  • Defined in i2ce/lib/I2CE_Date.php on line 419
  • Signature: static public function getYear($year)
  • Parameters:
    • integer $year
      Sets the year to be used.
      • Default Value: -1
  • Returns: I2CE_Date

getYearMonth()

Create a date object of the type Month/Day @param integer $day Sets the day of the month to be used

  • Defined in i2ce/lib/I2CE_Date.php on line 430
  • Signature: static public function getYearMonth($month,$year)
  • Parameters:
    • integer $month
      Sets the month to be used
      • Default Value: -1
    • $year
      • Default Value: -1
  • Returns: I2CE_Date

hour()

  • Defined in i2ce/lib/I2CE_Date.php on line 654
  • Signature: public function hour()
  • Returns: integer
    The hour part of the time.

isBlank()

Checks to see if the I2CE_Date object is the blank value This method will check to see if the date object has blank entries based on the type.

isDay()

Checks to see if the date's day matches the given day.

isHour()

Checks to see if the date's hour matches the given hour.

isMinute()

Checks to see if the date's minute matches the given minute.

isMonth()

Checks to see if the date's month matches the given month.

isSecond()

Checks to see if the date's second matches the given second.

isValid()

Checks to see if the I2CE_Date object is valid This method will check to see if the date object has valid entries based on the type.

isYear()

Checks to see if the date's year matches the given year.

listMonths()

Adds the month values to a object.

  • Defined in i2ce/lib/I2CE_Date.php on line 963
  • Signature: static public function listMonths($template,$selectId)
  • Parameters:

listYears()

Adds a sequence of years to a object. It takes two optional arguments to limit the years to use. The initial year to start with is 1990 and it will end with the current year.

  • Defined in i2ce/lib/I2CE_Date.php on line 979
  • Signature: static public function listYears($template,$selectId,$start,$end)
  • Parameters:
    • I2CE_Template $template
    • string $selectId
      The id of the element in the page to add the selections to.
    • integer $start
      The year to start with
      • Default Value: 1990
    • integer $end
      The year to end with. @see I2CE_Template::setData()
      • Default Value: 0

minute()

  • Defined in i2ce/lib/I2CE_Date.php on line 658
  • Signature: public function minute()
  • Returns: integer
    The minute part of the time.

month()

  • Defined in i2ce/lib/I2CE_Date.php on line 646
  • Signature: public function month()
  • Returns: integer
    The month part of the date.

now()

Create a new I2CE_Date object with the current or given date and/or time.

  • Defined in i2ce/lib/I2CE_Date.php on line 205
  • Signature: static public function now($type,$time_stamp,$strict)
  • Parameters:
    • integer $type
      The type of date object created. It defaults to date and time.
      • Default Value: self::DATE_TIME
    • integer $time_stamp
      Defaults to null in which case we use the current time stamp. If it is an array then it should be the same array structture as returned by getdate() or the one returned by I2CE_Date::getValues()
      • Default Value: null
    • mixed $strict
      Defaults to false. If true, does not return now. If 'blank', returns the blank date.
      • Default Value: false
  • Returns: mixed
    I2CE_Date or false if failure on strict mode

second()

  • Defined in i2ce/lib/I2CE_Date.php on line 662
  • Signature: public function second()
  • Returns: integer
    the second part of the time.

setBlank()

Set the blank string to be used if this date is empty.

setType()

Set the type for this Date.

  • Defined in i2ce/lib/I2CE_Date.php on line 184
  • Signature: public function setType($type)
  • Parameters:
    • integer $type
      The type of date object created. It defaults to date and time.

year()

  • Defined in i2ce/lib/I2CE_Date.php on line 642
  • Signature: public function year()
  • Returns: integer
    The year part of the date.