Download the PHP package mindplay/datetime without Composer

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

mindplay/datetime

Build Status

Code Coverage

Scrutinizer Code Quality

This date/time helper tries to make date/time management in PHP less prickly, by providing a chainable helper that can be accessed via a global function datetime().

I wanted a convenient way to work with timestamps, which would provide the same convenience (and IDE support) as e.g. DateTime, but without the problems.

The global datetime() function takes an integer timestamp as argument, or a valid date/time string compatible with strtotime(), applies it to the helper, and returns it.

$time = datetime('1975-07-07')->time; // parse date/time string to timestamp

$str = datetime(time())->datetime; // timestamp to 'YYYY-MM-DD HH:MM:SS' format

The helper has a configuration object that defines global date/time formats and a default timezone, which is UTC by default, regardless of any environment settings - since timestamps (unlike DateTime) do not carry around timezone information, the default timezone can be changed, but you can also switch to different timezones for easy string output.

$a = datetime()->utc()->long; // system date/time in long format

$b = datetime()->timezone('EST')->short; // short date/time in EST timezone

The helper implements __toString() and will format itself using the 'default' format, which is also configurable. You can define as many formats as you want, or specify the format directly, and you can render these using ->format() at the end of a chain. Default formats like 'short', 'long', 'string' and 'date' are also supported directly as (dynamic) properties.

datetime()->config->formats['weekday'] = 'l';

echo datetime()->timezone('PST')->format('weekday'); // current weekday in PST

Basic computations can also be performed using plain english:

$today = datetime()->date()->time; // date() resets the time to 00:00:00

$this_month = datetime()->month()->time; // month() resets to start of the month

$next_week = datetime()->add('1 week')->time;

$whenever = datetime()->add('1 month')->sub('3 days 2 hours 1 minute')->time;

One word of caution: unless you echo the result (invoking __toString()) your call-chains should always end with a property rather than a method () call - the properties of the helper-class never return the helper object, always a value.

$bad = datetime(); // reference to DateTimeHelper !

$wrong = datetime()->timezone('EST')->add('1 week'); // oh noes!

There's a bunch of other features, go ahead and check out the unit-test for examples of every possible operation, or play around using auto-complete in your IDE.

Why not objects?

Nobody doesn't love objects, but DateTime is trouble - watch:

$today = new DateTime();
$yesterday = $today->modify('-1 day');

echo "today: " . $today->format('Y-m-d') . "\n";
echo "yesterday: " . $yesterday->format('Y-m-d');

If you understand how DateTime works, you might be prepared for this nonsense:

today: 2013-03-21
yesterday: 2013-03-21

Methods like modify(), add() and sub() modify the DateTime object, rather than returning a new DateTime instance.

And sure, you got DateTimeImmutable in more recent versions of PHP (and before it, dozens of third-party immutable date/time object implementations in userland) but you're still working with objects.

A timestamp is a value - when dealing with timestamps, I therefore want a value type, not an object, which is more complicated to handle when dealing with e.g. serialization, object/relational-mapping, etc.

When dealing with timezones, I don't want the timezone attached to the timestamp, because the timestamp and timezone do not actually have a meaningful relationship: timestamps are absolute, and that doesn't change when you attach it to a timezone; the only time that isn't true, is when you want the date/time as a string, but it's often more confusing to carry around the timezone information with the value for later use, since, when it finally gets turned into a string, it may not be obvious what timezone is being used - this can make programs rather confusing and difficult to read.


All versions of datetime with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.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 mindplay/datetime contains the following files

Loading the files please wait ....