Download the PHP package stubbles/date without Composer

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

stubbles/date

Handling dates and date spans in a immutable way, using a beautiful API.

Build status

Tests

Latest Stable Version

Installation

stubbles/date is distributed as Composer package. To install it as a dependency of your package use the following command:

composer require "stubbles/date": "^9.0"

Requirements

stubbles/date requires at least PHP 8.2.

Introduction

The origin of the classes in this library are from the days when PHP's object- oriented date/time handling classes were not immutable. In the meantime immutable versions of them have been added to PHP, but we like the API of the classes here more, as they lead to a better grammar in the code in which they are used.

The underlaying implementation makes use of PHP's object-oriented date/time handling classes, but abstracts them such that the stubbles/date instances are immutable. Every change to a date will result in a new instance. Although the date class exposes the underlaying handle, the user will only receive a clone of that, so modifying such a handle will not mutate the date instance from which the handle was obtained.

stubbles\date\Date

Please note that this class not only covers a date, but an exact point in time. Each instance also has a time part. If you are interested in a concrete day only please use stubbles\date\span\Day (see below).

Create a new instance

When creating a new date instance there are different ways to set the actual date:

The second argument to the constructor is an optional timezone. Timezone assignment works through these rules:

Liberal type hinting

If you have a method which accepts an instance of stubbles\date\Date you can choose to be liberal in what you accept. Instead of type hinting against the concrete type your method can cast the provided value into an instance:

The Date::castFrom(); accepts four different value types:

An instance of stubbles\date\Date will always be returned as is, the other allowed values will result in the creation of a stubbles\date\Date instance. Passing any other value will result in a \InvalidArgumentException.

Change a date

To change a date the Date::change() method can be called. This will return an instance of stubbles\date\DateModifier which provides several different methods to change the date and/or time. All changes will result in a new stubbles\date\Date instance, the instance on which Date::change() is originally called remains unchanged:

Here's a list of methods offered by stubbles\date\DateModifier:

Comparing dates

Instances of stubbles\date\Date can be compared with each other:

Comparison is done based on the unix timestamp.

Both isBefore() and isAfter() accept all values that are accepted by Date::castFrom(), see above.

Date formatting

The date can be displayed as a string by formatting:

When an instances is casted to a string, the output format will be Y-m-d H:i:sO.

Date spans

Sometimes it is necessary to not cover a specific date only, but a span between two points in time. Most notably these are things like a single day, months, weeks or even a year. As it is impractical to always carry the starting and ending point of such a span, stubbles/date provides the stubbles\date\span\Datespan interface and various implementations.

Default methods of each date span

All methods which have a $date parameter accept all values that are accepted by Date::castFrom(), see above.

List of provided date span implementations

stubbles\dates\span\Day

Covers a whole day, starting at 00:00:00 and ending at 23:59:59.

Additional methods:

stubbles\dates\span\Week

Covers a whole week, starting on the given date at 00:00:00 and ending at seven days later at 23:59:59.

Additional methods:

stubbles\dates\span\Month

Covers a month, starting at the first of the month at 00:00:00 and ending at the last day of the month at 23:59:59.

Additional methods:

stubbles\dates\span\Year

Covers a year, starting at January 01 00:00:00 and ending at December 31 23:59:59.

Additional methods:

stubbles\dates\span\CustomDatespan

Covers a custom date span starting at the given date at 00:00:00 and ending at the given date at 23:59:59.

Constructor parameters accept all values that are accepted by Date::castFrom(), see above. Please note that the time for the start is always set to 00:00:00 and for the end is always set to 23:59:59. It is not possible to change this to another time.

Integration with bovigo/assert

In case you want to unit test your code and need to test for date equality you can use bovigo/assert for the assertions. stubbles/date provides the predicate stubbles\date\assert\equalsDate() which can be used to check for equality of dates. It can take any argument that stubbles\date\Date accepts, and compares the unix timestamp with the actual value. In case they don't refer to the same point in time the error message will contain a diff with both dates in human readable form.


All versions of date with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-ctype Version *
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 stubbles/date contains the following files

Loading the files please wait ....