File/datetime-defs.php

Description
Classes
Class Description
 class timeslot Classes to handle a 24-hr time schedule. Covers the setting of * any number of slots, and testing whether a given time is in one of * the slots. The timeslot class. Holds details of a single slot.
 class schedule Classes to handle a 24-hr time schedule. Covers the setting of * any number of slots, and testing whether a given time is in one of * the slots. The schedule class. Holds multiple timeslots.
Constants
BACKWARDS_DATE_ONLY = "Y/m/d" (line 39)

Example: 1999/12/31

DAY_AND_DATE = "l, jS F Y" (line 57)

Example: Friday, 20th July 2001

DISPLAY_DATE_FORMAT = "d/m/Y H:i" (line 30)

Example: 31/12/1999 23:59

DISPLAY_DATE_ONLY = "d/m/Y" (line 36)

Example: 31/12/1999

DISPLAY_TIMESTAMP_FORMAT = "d/m/Y H:i:s" (line 33)

Example: 31/12/1999 23:59:59

DISPLAY_TIME_ONLY = "H:i" (line 60)

Example: 23:59

DOW_HHMM = "D H:i" (line 81)

Example: Sun 23:59

ISO_8601 = "Ymd\THisO" (line 84)

ISO 8601 Example: YYYYMMDDTHHMMSS-HHMM

ISO_DATABASE_FORMAT = "Y-m-d H:i:s" (line 72)

Example: 1999-07-17 23:59:59

NICE_DATE = "M jS Y" (line 51)

Example: Mar 3rd 1999

NICE_DATETIME = "M jS g:ia" (line 45)

Example: Mar 3rd 1:30pm

NICE_DATE_NOYEAR = "M jS" (line 42)

Example: Mar 3rd

NICE_FULLDATETIME = "M jS Y g:ia" (line 54)

Example: Mar 3rd 1999 1:30pm

NICE_TIME_ONLY = "g:ia" (line 63)

Example: 1:30pm

POSTGRES_DATE_FORMAT = "m/d/Y H:i:s" (line 66)

Example: 12-31-1999 23:59:59

POSTGRES_STD_FORMAT = "Y-m-d H:i:s" (line 69)

Example: 1999-07-17 23:59:59

SHORT_DATETIME = "M j H:i" (line 48)

Example: Mar 3 21:30

SQL_FORMAT = "m/d/Y H:i:s" (line 78)

Example: 12/31/1999 23:59:59

STD_DMY = "d/m/Y" (line 75)

Example: 23/5/2001

Functions
datetime_to_displaydate (line 368)

Conversion: datetime to descriptive Convert a database-compatible datetime string into a descriptive date/time format for the user display, using the given displayformat string.

  • return: The formatted descriptive datetime string
string datetime_to_displaydate (string $displayformat, string $datetime)
  • string $displayformat: See defined formats.
  • string $datetime: Database datetime string
datetime_to_timestamp (line 314)

Conversion: datetime to descriptive Returns a timestamp from a database-formatted datetime string.

We are assuming the datetime is formatted in the ISO format of "1999-07-17 23:59:59+12" - POSTGRES_STD_FORMAT (ISO) This is set up by the standard application via an SQL query with the "SET DATESTYLE ISO" command (see query-defs.php).

  • return: Unix timestamp (earliest = 1970-1-1)
integer datetime_to_timestamp (string $datetime)
  • string $datetime: Database-compatible ISO date string
dayNameNow (line 515)

Day of Week now as string Returns the day name (eg. "Monday") as it is now.

  • return: Day of week name
string dayNameNow ()
dayNow (line 504)

Day of Month now as integer Returns the day of the month (1-31) as it is now.

  • return: Day of Month now
integer dayNow ()
daysinmonth (line 114)

Return the days in a month Given an integer month number 1-12, and an optional year (defaults to current) this function returns the number of days in the given month.

  • return: Number of days in month
integer daysinmonth (integer $monthno, [integer $year = 0])
  • integer $monthno: Month no. 1 - 12
  • integer $year: Year
displaydate_to_date (line 295)

Conversion: descriptive to datetime without the time element.

Converts a descriptive date/time string into a database compatible 'date' field as per Postgres ISO spec.

  • return: Date string in Postgres YYYY-MM-DD format
string displaydate_to_date (string $displaydate)
  • string $displaydate: Date in any 'descriptive' format
displaydate_to_datetime (line 283)

Conversion: descriptive to datetime.

Converts a descriptive date/time string into a database compatible 'datetime' field as per Postgres ISO spec.

  • return: Datetime string in Postgres YYYY-MM-DD HH:MM:SS format
string displaydate_to_datetime (string $displaydate)
  • string $displaydate: Date in any 'descriptive' format
displaydate_to_timestamp (line 235)

Conversion: descriptive to timestamp.

Converts a descriptive date/time string into a timestamp.

  • return: Unix timestamp (earliest = 1970-1-1)
integer displaydate_to_timestamp (string $displaydate)
  • string $displaydate: Date in any 'descriptive' format
format_DMY (line 388)

Format date as DD/MM/YYYY

Take a date string as entered in a form and reformat it to DD/MM/YYYY. Obviously it as to be more or less in this format to begin with, but we cope with a few foibles here like two-digit year, different delimiters and also strip off any time component added to the end.

  • return: The formatted DD/MM/YYYY date
string format_DMY ([string $dtstr = ""])
  • string $dtstr: Date string to format
get_DMY (line 534)

Get date components of datetime string Returns the date components of a formatted date string.

We start by assuming DD/MM/YYYY ordering, but can alter this if it looks wrong. Note that the date string we are looking at must be in vaguely standard format, ie. with "/" or "-" or "." as delimiter etc. We return an array as: ["day"] - Day of month (1 - 31) ["month"] - Month number (1 - 12) ["year"] - Year eg. 1982

  • return: Date components
array get_DMY (string $displaydate)
  • string $displaydate: Descriptive display date string
get_HMS (line 601)

Get time components of datetime string Extract the HH:MM[:SS] from datetime string Returns the time components of a formatted date string.

We return an array as: ["hours"] - Hours (0 - 23) ["minutes"] - Minutes (0 - 59) ["seconds"] - Seconds (0 - 59)

  • return: Time components
array get_HMS ([string $displaydate = ""])
  • string $displaydate: Descriptive display date string
isLeapYear (line 140)

Check if year is a leap year.

Determines whether the given year is a leap year.

  • return: True if year is a leap year, else false
boolean isLeapYear (integer $year)
  • integer $year: Year
mins_diff (line 212)

Tell minutes difference between too datetimes Returns the minutes difference between the two given datetimes.

  • return: The number of minutes difference
integer mins_diff (string $dfrom, string $dto)
  • string $dfrom: From date in 'descriptive' format
  • string $dto: To date in 'descriptive' format
monthNameNow (line 493)

Month now as string Returns the month name (eg. "January") as it is now..

  • return: Month name now
string monthNameNow ()
monthno (line 405)

Return month number Return the number of the named month, default to Jan if problems arise.

  • return: The number of the month 1 - 12
integer monthno (string $monthname)
  • string $monthname: Name of the month
monthNow (line 482)

Month now as integer Returns the month (1-12) as it is now.

  • return: Month number now
integer monthNow ()
prose_diff (line 155)

Tell nice difference between too datetimes

Returns a nice expression of the difference between the two given datetimes written in a nice English sentence

  • return: Nice sentence describing difference
string prose_diff (string $dfrom, string $dto)
  • string $dfrom: From date in Postgres datetime format
  • string $dto: To date in Postgres datetime format
prose_diff_ts (line 175)

Tell nice difference between too Unix timestamps

Returns a nice expression of the difference between the two given timestamps, written in a nice English sentence

  • return: Nice sentence describing the time interval
string prose_diff_ts (integer $fromts, integer $tots)
  • integer $fromts: From datetime as Unix timestamp
  • integer $tots: To datetime as Unix timestamp
timeNow (line 446)

Time now as array

Returns the current time as an associative array: ["hours"] - Hours since midnight ["minutes"] - Minute of the curent hour ["seconds"] - Seconds of the current minute

  • return: Containing the time components
array timeNow ()
timeNowAsStr (line 460)

Time now as string

Returns the current time as a string 'hr:min:sec'

  • return: Time now in hh:mm:ss format.
string timeNowAsStr ()
timestamp_to_datetime (line 266)

Conversion: timestamp to datetime.

Returns a string in the correct format for populating a database 'datetime' field, as per ISO 8601 spec.

  • return: Datetime string in ISO YYYY-MM-DD HH:MM:SS format
string timestamp_to_datetime ([integer $timestamp = false])
  • integer $timestamp: Unix timestamp
timestamp_to_displaydate (line 351)

Conversion: timestamp to descriptive Convert a Unix timestamp into a descriptive date/time format for the user display, using the given displayformat string.

  • return: The formatted descriptive datetime string
string timestamp_to_displaydate (string $displayformat, [integer $timestamp = ""])
  • string $displayformat: See defined formats.
  • integer $timestamp: Unix timestamp
todaysDate_DMY (line 433)

Today as DD/MM/YYYY Returns the given datetime as a date, and in EUROPEAN 'd/m/Y' format.

  • return: The formatted DD/MM/YYYY date
string todaysDate_DMY ()
todaysDate_MDY (line 422)

Today as MM/DD/YYYY Returns the given datetime as a date, and in SQL 'm/d/Y' format.

  • return: The formatted MM/DD/YYYY SQL date
string todaysDate_MDY ()
yearNow (line 471)

Year now as integer Returns the year as it is now.

  • return: Year now in 9999 format
integer yearNow ()

Documentation generated by phpDocumentor 1.3.0RC3