Class

Date

Package: Util Copyright: © 2005-2019 PHPBoost License: GNU/GPL-3.0 Author: Benoit SAUTEL ben.popeye@phpboost.com Version: PHPBoost 5.2 - last update: 2018 03 23 Since: PHPBoost 2.0 - 2008 06 01 Contributor: Julien BRISWALTER j1.seth@phpboost.com Contributor: Arnaud GENET elenwii@phpboost.com Contributor: mipel mipel@phpboost.com Located at: util/Date.class.php

This class allows you to handle easily some dates. A date is a day and an hour (year, month, day, hour, minutes, seconds). It supports the most common formats and manages timezones. Here are the definitions of the 3 existing timezones:

  • System timezone: it's the timezone of the server, configured by the hoster. For instance, if your server is in France, it should be GMT+1.
  • Site timezone: it's the timezone of the central place of the site. For example, if your site deals with the italian soccer championship, it will be GMT+1.
  • User timezone : each registered user can specify its timezone. It's particulary useful for people who visit some sites from a foreign country.
Methods summary
public
# __construct( $time = self::DATE_NOW, $referencial_timezone = Timezone::USER_TIMEZONE )

Builds and initializes a date. The first parameter is the date in a standardized format defined in the PHP documentation. To get the current date, use the Date::DATE_NOW The second parameter allows us to chose what time referential we use to create the date:

  • Timezone::SERVER_TIMEZONE if that date comes from for example the database (dates must be stored under this referential).
  • Timezone::SITE_TIMEZONE if it's an entry coming from the site (nearly never used).
  • Timezone::USER_TIMEZONE if it's an entry coming from the user (it's own timezone will be used)
public string
# format( integer $format = self::FORMAT_DAY_MONTH, integer $referencial_timezone = Timezone::USER_TIMEZONE )

Formats the date to a particular format.

public string
# get_date_relative( integer $timestamp, integer $referencial_timezone )

Returns the relative time associated to the date

public integer
# get_timestamp( )

Returns the timestamp associated to the date

public DateTime
# get_date_time( )

Returns DateTime

public string
# get_year( $timezone = Timezone::USER_TIMEZONE )

Returns the year of the date

public
# set_year( $year, $referential_timezone = Timezone::USER_TIMEZONE )
public string
# get_month( $timezone = Timezone::USER_TIMEZONE )

Returns the month of the date

public
# set_month( $month, $referential_timezone = Timezone::USER_TIMEZONE )
public string
# get_month_text( $characters_number = '', $timezone = Timezone::USER_TIMEZONE )

Returns first charaters (all per default) of the month name

public string
# get_week_number( $referential_timezone = Timezone::USER_TIMEZONE )

Returns the week number of the date

public
# set_week_number( $week_number )
public string
# get_day( $timezone = Timezone::USER_TIMEZONE )

Returns the day of the date

public
# get_day_two_digits( $timezone = Timezone::USER_TIMEZONE )
public
# set_day( $day, $referential_timezone = Timezone::USER_TIMEZONE )
public string
# get_day_text( $characters_number = '', $timezone = Timezone::USER_TIMEZONE )

Returns first charaters (all per default) of the day of week name

public string
# get_day_of_week( $timezone = Timezone::USER_TIMEZONE )

Returns the day of the week (0 for sunday to 6 for saturday)

public string
# get_day_of_year( $timezone = Timezone::USER_TIMEZONE )

Returns the day of the year

public
# set_day_of_year( $day_of_year )
public string
# get_hours( $timezone = Timezone::USER_TIMEZONE )

Returns the hours of the date

public
# set_hours( $hours, $referential_timezone = Timezone::USER_TIMEZONE )
public string
# get_minutes( )

Returns the minutes of the date

public
# set_minutes( $minutes, $referential_timezone = Timezone::USER_TIMEZONE )
public string
# get_seconds( )

Returns the seconds of the date

public
# set_seconds( $seconds, $referential_timezone = Timezone::USER_TIMEZONE )
public string
# to_date( )

Exports the date according to the format YYYY-mm-dd

public boolean
# is_anterior_to( Date $date )

Tells whether this date is anterior to the given one

public boolean
# is_posterior_to( Date $date )

Tells whether this date is posterior to the given one

public boolean
# equals( Date $date )

Tells whether this date equals the given one

public
# add_days( integer $number_days )

Adds the given number of days to the date

public
# add_weeks( integer $number_weeks )

Adds the given number of weeks to the date

public boolean
# is_date_year_bissextile( )

Tells whether the year of the date is bissextile

public static
# to_format( $time, $format = self::FORMAT_DAY_MONTH, $referencial_timezone = Timezone::USER_TIMEZONE )
public static
public static string[]
# get_array_tpl_vars( Date $date, string $date_label )

Calculates and return date formats to use many variables in the TPL.

Annonces