Period by The PHP League

website·Indexed 37 days ago

https://period.thephpleague.com/

A PHP library for handling bounded datetime intervals. It provides a Period value object, DatePoint and Duration classes, and a Sequence class for managing multiple Period instances. Documentation covers versions 3.0, 4.0, and 5.0, including features for comparing periods, drawing intervals, and managing period collections.

Tokens
35.1K
Snippets
240
Records
273
Agent score
64%

What's inside Period

  1. Overview of the Duration class

    The Duration class (introduced in version 4.2) extends PHP's DateInterval class. It represents a continuous portion of time between two datepoints and cannot be negative.
  2. Overview of League Period (v3.0)

    League Period is a PHP API for handling time ranges. It is implemented as an immutable value object. Because it is an immutable value object, you must typehint against the League\Period\Period class directly as it does not provide a separate interface.

  3. Overview of the Period value object

    A Period instance is a PHP implementation of a bounded datetime interval. It consists of two date endpoints (datepoints) expressed as DateTimeImmutable objects, where the starting datepoint must be less than or equal to the ending datepoint.

    It supports four boundary configurations:

    • Included start, excluded end: [start, end)
    • Included start, included end: [start, end]
    • Excluded start, included end: (start, end]
    • Excluded start, excluded end: (start, end)

    Infinite or unbounded intervals are not supported. The duration between datepoints is expressed as a DateInterval and cannot be negative.

  4. Overview of the DatePoint class

    The DatePoint class is a decorator for PHP's DateTimeImmutable object. It provides named constructors for easy instantiation, factory methods to create Period classes, and methods to determine the relationship between a specific point in time and a Period instance.
  5. Overview of the Sequence class

    The Sequence class is designed to manage and gather information about multiple Period instances. Because Period is a value object, comparisons within a Sequence are performed using Period::equals rather than standard equality operators (== or ===).
  6. Overview of the Sequence class

    The Sequence class is a container designed to manage and gather information about multiple Period instances. Because Period is a value object, the Sequence class uses Period::equals for comparisons rather than standard identity operators (== or ===).
  7. Overview of League Period

    League Period is a time range API for PHP (minimum version 8.1.0). It provides an immutable value object for handling time intervals. Because the League\Period\Period class is marked as final and has no interface, you should always typehint against the class directly.

  8. Overview of the League Period library

    The League eadthedocs eadthedocs package provides a time range API for PHP. The League eadthedocs eadthedocs class is an immutable value object marked as final; therefore, developers must typehint against the class directly as no interface is provided. For managing collections of Period objects, the library provides the League eadthedocs eadthedocs class.
  9. Understand Period object immutability

    In league/period version 3.0, the Period class is an immutable value object. Any modification method does not change the existing object but instead returns a new Period object. If a valid Period cannot be created during a modification, a LogicException is thrown.
  10. Understand Period library core concepts (v3.0)

    In the Period library (v3.0), time is managed using two primary concepts:

    1. Datepoint: A position in time. A period is the continuous portion of time between two datepoints. The starting datepoint is inclusive, while the ending datepoint is exclusive. Datepoints are represented as DateTimeImmutable objects, and the start must be less than or equal to the end.
    2. Duration: The continuous portion of time between two datepoints, represented as a DateInterval object. Durations cannot be negative.
  11. Manage multiple Period instances using the Sequence class

    The Sequence class allows you to manage multiple Period instances. It behaves as a List, similar to an array that uses incremental integer keys. Once instantiated, a Sequence object can be used as a Period-aware Container or a Period Collection.
  12. Understand the Bounds enumeration for Period intervals

    The Bounds enumeration defines whether the boundary datepoints of a Period instance are included or excluded. An included datepoint means the boundary itself is part of the interval; an excluded datepoint means it is not.
    enum Bounds
    {
        case IncludeStartExcludeEnd;
        case IncludeAll;
        case ExcludeStartIncludeEnd;
        case ExcludeAll;
    }