Download the PHP package pwm/datetime-period without Composer

On this page you can find all versions of the php package pwm/datetime-period. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package datetime-period

DateTimePeriod

Build Status codecov Maintainability Test Coverage License: MIT

An implementation of the datetime period type for working with temporal intervals. The library includes the full set of relations on intervals defined by Allen's Interval Algebra. For further information see the "Usage" and "How it works" paragraphs.

Table of Contents

Requirements

PHP 7.1+

Installation

$ composer require pwm/datetime-period

Usage

Creation:
Restrictions:
The full set of relations between 2 periods:
Extensibility:

The DateTimePeriod object itself is immutable, meaning that once created you can't change the state of the object, ie. the values of its properties. However the properties have been defined as protected so that you can subclass the type in your project if the need arises.

Working with different granularities:

The 2 periods below meet on a timeline with hour granularity but does not meet on a more fine-grained timeline with minute granularity.

Miscellaneous:

This is a list of small helper methods that can save you time when you need their specific functionality.

  1. Get the number of days in a period:

How it works

In order to be able to talk about periods first let's agree on the following definitions:

Definitions

1. Instant

An anchor, ie. discrete point, on the timeline. The most basic temporal type. A "true" time instant is theoretical like a point on a continuous geometrical line. A representation of an instant, however, always has a duration, called a granule. We can thus represent the same instant using various discreet timelines of different granularities. Eg. "2017-10-10" and "2017-10-10 10:10:10" could represent the same instant.

2. Interval

An unanchored, directed portion of the timeline. Unanchored means it has no absolute relation to the timeline. Examples are "2 weeks" or "1 day, 2 hours and 3 minutes". Directed means it is perfectly valid to say "-3 days".

3. Period

An anchored interval on the timeline. There are several possible representations, the most common being a pair of ordered instants of identical granularity. Depending on the representation the interval of a period can be open or closed on both its start and end. A common way is to use a closed-open interval, ie. [start, end), which helps simplifying calculations. Eg. the period ["2017-10-10", "2017-11-11") includes the instant "2017-10-10" but excludes the instant "2017-11-11".

We arrived to the definition of a period. Now on to...

Relations

Defining relations on periods is somewhat complex as there is no total order. In 1983 James F. Allen wrote a paper in which he defined 13 jointly exhaustive and pairwise disjoint binary relations on intervals, meaning that any 2 intervals are related exactly one way. You can see each of the 13 relations above, in the "Usage" section. These relations and the operations on them form what is referred to as Allen's interval algebra.

Complexities

Dealing with calendrical time is difficult with many peculiarities. This, in turn, means that dealing with derivative entities, like DateTimePeriod is complex as well.

Here is an example involving timezones:

If you try to create a one year DateTimePeriod starting from 2018-03-26T08:00:00 and ending at 2019-03-26T08:00:00 for the timezone Europe/London it would fail with a UTCOffsetMismatch exception. This is because for the start instant the timezone Europe/London equals to BST (which equals to UTC+01:00) while for the end instant Europe/London equals to GMT (which equals to UTC+00:00). This is because daylight saving time happens on different days in different years.

If you create the above period using UTC offsets, ie. from 2018-03-26T08:00:00+01:00 to 2019-03-26T08:00:00+01:00 that would not throw a UTCOffsetMismatch, however the end instant will not be a valid Europe/London datetime so you would have to calculate the correct time for Europe/London from your UTC+01:00 offset.

The supplied DateTimePeriod::getUtcOffset() function can help ease this problem by mapping your current timezone to its UTC offset.

Tests

$ vendor/bin/phpunit
$ composer phpcs
$ composer phpstan
$ composer infection

Changelog

Click here

Todo

Licence

MIT


All versions of datetime-period with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pwm/datetime-period contains the following files

Loading the files please wait ....