Download the PHP package quillstack/datetime without Composer

On this page you can find all versions of the php package quillstack/datetime. 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

Quillstack Datetime

Tests Latest Version Downloads PHP Version StyleCI CodeFactor Quality Gate Coverage Maintainability Reliability Security Maintainability License

A date and time, written the way people read it. Full documentation: https://quillstack.org/datetime

PHP's own DateTime throws Exception for a string it cannot read, which is the one class a catch cannot be specific about. This wraps it: the same parsing, an exception of its own, and one format everything in the stack agrees on.

Why this exists

It is a thin wrapper over PHP's own DateTime, and it exists for two small reasons.

One is a consistent string: (string) new Datetime() is always Y-m-d H:i:s, so a date reaching a log, a response or a database looks the same everywhere without anybody passing a format around.

The other was a typed exception — and that reason has largely expired. When this was written, new DateTime('nonsense') threw the base Exception, so catching a bad date meant catching everything. PHP 8.3 introduced DateMalformedStringException, which can be caught on its own. On PHP 8.3 and later this package's exception adds nothing you could not get from the language; on 8.1 and 8.2, which it still supports, it does.

Read that as it is meant: if you are on a current PHP and want dates, use DateTimeImmutable, or Carbon if you want the fluent kind.

Requirements

Installation

Usage

Anything DateTime understands works, because it is what does the reading.

When the string is not a date

It extends DatetimeException, as anything else this package ever throws will.

On PHP 8.1 and 8.2 this is worth having: new DateTime('nonsense') throws the base Exception there, so catching a bad date means catching everything. From PHP 8.3 the language throws DateMalformedStringException, which can be caught on its own — and this adds nothing to it.

Technical documentation

Class What it is
Datetime the date and time; __toString() formats it
FormatInterface the format everything agrees on: HUMAN_DATE_TIME is Y-m-d H:i:s
DatetimeException what everything here extends
Exceptions\InvalidDatetimeFormatOrKeyException the string was not a date

Datetime::NOW is 'now', which is also the default — so new Datetime() is this moment.

Benchmark

Measured with quillstack/benchmark on a thousand dates parsed from a string and formatted back to one. Runs are interleaved and unconcurrent, each figure is the median of five, and PHP is 8.5.7.

Version
quillstack/datetime 0.6.0
nesbot/carbon 3.13.2
brick/date-time 0.7.1
Per date Relative
PHP's own DateTime 0.52 µs 0.87×
quillstack/datetime 0.60 µs —
nesbot/carbon 1.23 µs 2.1×
brick/date-time 2.15 µs 3.6×

The first row is the one to read. This package is DateTime plus eighty nanoseconds, because that is all it is: a constructor that catches, and a __toString with a fixed format.

Carbon at twice the cost gives you a fluent API, human-readable differences, localisation, testing helpers and immutability; brick/date-time gives you separate types for a date, a time and an instant, which is a genuinely better model of the problem than PHP's single class. Neither number is a reason to avoid them.

All four reject a string that is not a date. Carbon throws InvalidFormatException, Brick throws DateTimeParseException, PHP throws DateMalformedStringException, and this throws InvalidDatetimeFormatOrKeyException — which on PHP 8.3 and later is the same service the language now provides.

Tests

The rest of Quillstack

This is one component of Quillstack, a PHP framework which is as simple to use as it is strict about what it does.

License

MIT. See LICENSE.


All versions of datetime with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 quillstack/datetime contains the following files

Loading the files please wait ...