Longhorn PHP 2023 - Call for Papers

A classe DatePeriod

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Introdução

Representa um período entre datas.

O período entre datas permite a iteração entre um conjunto de datas e horários recorrentes a intervalos regulares, durante um determinado período.

Sinopse da classe

class DatePeriod implements Traversable {
/* Constantes */
const integer EXCLUDE_START_DATE = 1;
/* Propriedades */
public integer $recurrences;
public boolean $include_start_date;
/* Métodos */
public __construct(
    DateTimeInterface $start,
    DateInterval $interval,
    int $recurrences,
    int $options = ?
)
public __construct(
    DateTimeInterface $start,
    DateInterval $interval,
    DateTimeInterface $end,
    int $options = ?
)
public __construct(string $isostr, int $options = ?)
public getRecurrences(): ?int
}

Constantes pré-definidas

DatePeriod::EXCLUDE_START_DATE

Exclui a data inicial, utilizada em DatePeriod::__construct().

Propriedades

recurrences

O número de recorrências, se a instância DatePeriod foi criada com o argumento $recurrences. Veja também DatePeriod::getRecurrences().

include_start_date

Se inclui a data inicial na recorrências.

start

A data inicial do período.

current

Contém a data atual dentro do período.

end

Data final do período.

interval

Uma especificação ISO 8601 do intervalo repetidor.

Changelog

Versão Descrição
5.3.27, 5.4.17 As propriedades recurrences, include_start_date, start, current, end e interval foram expostas.

Índice

add a note

User Contributed Notes 1 note

up
22
mail at pascalhofmann dot de
6 years ago
When looping over a DatePeriod object, the returned objects always implement DateTimeInterface. The exact type returned depends on how the DatePeriod was created. If $start was a DateTimeImmutable, the objects returned will be of type DateTimeImmutable. If a DateTime object was used, the objects returned will be of type DateTime.
To Top