AnewtDateTime class

This class provides methods for date and time operations.

Class Overview

This class provides methods for date and time operations.

It supports both parsing and formatting.

Public Methods

__construct()

Constructor (triggers an error).

This class provides only static methods.

Construction and parsing methods

These methods can be used to obtain an AnewtDateTimeAtom instance. There are multiple methods to parse dates in various formats.

static now() [static]

Get the current date and time.

Return value

AnewtDateTimeAtom representing the current date.

static parse($date) [static]

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.

Parameters

$date

An int/string/AnewtDateTimeAtom which will be parsed.

Return value

A newly created AnewtDateTimeAtom instance or null if parsing failed.

See also

static parse_timestamp($timestamp) [static]

Converts a timestamp into a AnewtDateTimeAtom instance.

Parameters

$timestamp

Timestamp to use.

Return value

A newly created AnewtDateTimeAtom instance or null if parsing failed.

static parse_string($date) [static]

Parses a date string and returns a AnewtDateTimeAtom instance.

This method supports many common date and time formats, including SQL's DATETIME and several ISO 8601 forms.

Parameters

$date

A string specifying a date.

Return value

A newly created AnewtDateTimeAtom instance or null if parsing failed.

static parse_ymd($year, $month=1, $day=1) [static]

Parse year, month and day integers and return a AnewtDateTimeAtom instance.

This method is useful if you want to transform year, month and day values into an AnewtDateTimeAtom instance.

Parameters

$year

The year (integer)

$month

The month (integer, defaults to 1 if omitted)

$day

The day (integer, defaults to 1 if omitted)

Return value

A newly created AnewtDateTimeAtom instance or null if parsing failed.

Validating and checking methods

static is_valid_date_ymd($year, $month, $day) [static]

Check if a date (without time) is valid.

Parameters

$year

Year

$month

Month

$day

Day

Return value

True if this is a valid date, false otherwise.

static is_valid_time_hms($hour, $minute, $second) [static]

Check if a time (without date) is valid.

Parameters

$hour

Hour

$minute

Minute

$second

Second

Return value

True if this is a valid time, false otherwise.

static is_valid($date) [static]

Checks if a given date is valid.

Parameters

$date

Any date-like object; this could be a string, timestamp or a AnewtDateTimeAtom instance.

Return value

True if this is a valid date, false otherwise.

static is_current_year($date) [static]

Checks if a date is in the current year.

Parameters

$date

A date-like object.

Return value

True if the given date is in the current year, false otherwise.

static is_today($date) [static]

Checks if a date is the same date as today.

Parameters

$date

A date-like object.

Return value

True if the date is today, false otherwise.

Formatting methods

static year($date) [static]

Get the year.

Parameters

$date

A date-like object (optional).

Return value

The year of the given date.

static month($date) [static]

Get the month.

Parameters

$date

A date-like object (optional).

Return value

The month of the given date.

static day($date) [static]

Get the day.

Parameters

$date

A date-like object (optional).

Return value

The day of the given date.

static hour($date) [static]

Get the hours.

Parameters

$date

A date-like object (optional).

Return value

The hours of the given date.

static minute($date) [static]

Get the minutes.

Parameters

$date

A date-like object (optional).

Return value

The minutes of the given date.

static second($date) [static]

Get the seconds.

Parameters

$date

A date-like object (optional).

Return value

The seconds of the given date.

static timestamp($date) [static]

Get a timestamp.

Parameters

$date

A date-like object (optional).

Return value

A timestamp representing the given date.

static format($format, $date) [static]

Formats a date in strftime()-like format.

Parameters

$format

A format specifier in strftime() syntax.

$date

A date-like object (optional).

Return value

A formatted date representation.

static date($date) [static]

Get the date only.

Example: 1983-01-15.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-mm-dd format.

static time($date) [static]

Get the time only.

Example: 18:30:00.

Parameters

$date

A date-like object (optional).

Return value

A string in hh:mm:ss format.

static week($date) [static]

Get the week number.

Example: 1983-W02.

Parameters

$date

A date-like object (optional).

Return value

An integer denoting the week number of this year.

static day_of_year($date) [static]

Get the day number in the year.

Example: 15.

Parameters

$date

A date-like object (optional).

Return value

An integer denoting the day number of this year.

static iso8601($date) [static]

Format the date in standard ISO 8601 format.

Example: 1983-01-15T18:30:00.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-mm-ddThh:mm:ss format.

static iso8601_compact($date) [static]

Format the date in compact ISO 8601 format.

Example: 19830115T183000.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyymmddThhmmss format.

static iso8601_date_compact($date) [static]

Format the date in compact ISO 8601 date format.

Example: 19830115.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyymmdd format.

static iso8601_time_compact($date) [static]

Format the date in compact ISO 8601 time format.

Example: 183000.

Parameters

$date

A date-like object (optional).

Return value

A string in hhmmss format.

static iso8601_week($date) [static]

Format the date in ISO 8601 week format.

Example: 1983-W02.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-Wnn format.

static iso8601_week_day($date) [static]

Format the date in ISO 8601 week and day format.

Example: 1983-W02-6.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-Wnn-m format.

static iso8601_day_of_year($date) [static]

Format the date in ISO 8601 year-day format.

Example: 1983-015.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-nnn format.

static rfc2822($date) [static]

Format the date in RFC 2922 format.

Example: Sat, 15 Jan 1983 18:30:00 +0100. This format can be used for e-mail messages or RSS 2 feeds.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-nnn format.

static sql($date) [static]

Format the date in SQL92 DATETIME format.

Example: 1983-01-15 18:30:00. This format can be used in SQL queries.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-mm-dd hh:mm:ss format.

See also

static sql_date($date) [static]

Format the date in SQL92 DATE format.

Example: 1983-01-15. This format can be used in SQL queries.

Parameters

$date

A date-like object (optional).

Return value

A string in yyyy-mm-dd format.

See also

static sql_time($date) [static]

Format the date in SQL92 TIME format.

Example: 18:30:00. This format can be used in SQL queries.

Parameters

$date

A date-like object (optional).

Return value

A string in hh:mm:ss format.

See also

static beat($date) [static]

Get the swatch internet time beats.

Parameters

$date

A date-like object (optional).

Return value

A string in @000 format.

static format_if_current_year($format_if_current_year, $format_if_not_current_year, $date) [static]

Formats a date, using an alternative format if the given date is in the current year.

Parameters

$format_if_current_year

A format specifier in strftime() syntax, used if the date is in the current year.

$format_if_not_current_year

A format specifier in strftime() syntax, used if the date is not in the current year.

$date

A date-like object (optional).

Return value

A formatted date representation.

See also

static format_if_today($format_if_today, $format_if_not_today, $date) [static]

Formats a date, using an alternative format if the given date is the same day as today.

Parameters

$format_if_today

A format specifier in strftime() syntax, used if the date is today.

$format_if_not_today

A format specifier in strftime() syntax, used if the date is not today.

$date

A date-like object (optional).

Return value

A formatted date representation.

See also