Download the PHP package tiny-blocks/time without Composer

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

Time

License

Overview

Models time as immutable value objects for PHP, including instants, durations, periods, timezones, time-of-day, local dates, and day-of-week. All instants are normalized to UTC with microsecond precision, with strict parsing, formatting, and arithmetic operations. Declared as final readonly class for language-level immutability, with structural equality provided by the tiny-blocks value-object contract.

Installation

How to use

The library provides immutable value objects for representing points in time, quantities of time, and time intervals. All instants are normalized to UTC internally.

Instant

An Instant represents a single point on the timeline, always stored in UTC with microsecond precision.

Creating from the current moment

Captures the current moment with microsecond precision, normalized to UTC.

Creating from a string

Parses a date-time string with an explicit UTC offset. The value is normalized to UTC regardless of the original offset.

Creating from a database timestamp

Parses a database date-time string as UTC, with or without microsecond precision (e.g. MySQL DATETIME or DATETIME(6)).

Also supports timestamps without fractional seconds:

Creating from Unix seconds

Creates an Instant from a Unix timestamp in seconds.

Adding and subtracting time

Returns a new Instant shifted forward or backward by a Duration.

Measuring distance between instants

Returns the absolute Duration between two Instant objects.

The result is always non-negative regardless of direction:

Comparing instants

Provides strict temporal ordering between two Instant instances.

Emitting with sub-second precision

By default toIso8601() emits seconds only. Pass a Precision value to include fractional seconds in the output. Existing callers that omit the argument are unaffected.

Duration

A Duration represents an immutable, unsigned quantity of time measured in seconds. It has no reference point on the timeline. It expresses only "how much" time.

Creating durations

All factories reject negative values:

Arithmetic

Subtraction that would produce a negative result throws an exception:

Division

Returns the number of times one Duration fits wholly into another. The result is truncated toward zero:

Division by a zero Duration throws an exception:

Comparing durations

Converting to other units

Conversions truncate toward zero when the duration is not an exact multiple:

Period

A Period represents a half-open time interval [from, to) between two UTC instants. The start is inclusive and the end is exclusive.

Creating from two instants

The start must be strictly before the end:

Creating from a start and duration

Getting the duration

Checking if an instant is contained

The check is inclusive at the start and exclusive at the end:

Detecting overlap

Two half-open intervals [A, B) and [C, D) overlap when A < D and C < B:

Adjacent periods do not overlap:

DayOfWeek

A DayOfWeek represents a day of the week following ISO 8601, where Monday is 1 and Sunday is 7.

Deriving from an Instant

Checking weekday or weekend

Calculating forward distance

Returns the number of days forward from one day to another, always in the range [0, 6]. The distance is measured forward through the week:

TimeOfDay

A TimeOfDay represents a time of day (hour and minute) without date or timezone context. Values range from 00:00 to 23:59.

Creating from components

Creating from a string

Parses a string in HH:MM or HH:MM:SS format. When seconds are present, they are discarded:

Also accepts the HH:MM:SS format commonly returned by databases:

Deriving from an Instant

Extracts the time of day from an Instant in UTC:

Named constructors

Comparing times

Measuring distance between times

Returns the Duration between two times. The second time must be after the first:

Converting to other representations

LocalDate

A LocalDate is a value object representing a calendar date (year, month, day) without time and without timezone. Dates are always in the proleptic Gregorian calendar and restricted to the range 0001–9999.

Creating from components

Creating from a string

Accepts only the canonical ISO 8601 date format YYYY-MM-DD. Any other format raises InvalidLocalDate.

Today in a timezone

Projecting an Instant

Comparing dates

Day arithmetic

Timezone

A Timezone is a value object representing a single valid IANA timezone identifier.

Creating from an identifier

Creating a UTC timezone

Converting to DateTimeZone

Timezones

An immutable collection of Timezone objects.

Creating from objects

Creating from strings

Getting all timezones

Returns all Timezone objects in the collection:

Finding a timezone by identifier

Searches for a specific IANA identifier within the collection. Returns null if not found.

Finding a timezone by identifier with UTC fallback

Searches for a specific IANA identifier within the collection. Returns UTC if not found.

Checking if a timezone exists in the collection

Getting all identifiers as strings

Returns all timezone identifiers as plain strings:

License

Time is licensed under MIT.

Contributing

Please follow the contributing guidelines to contribute to the project.


All versions of time with dependencies

PHP Build Version
Package Version
Requires php Version ^8.5
tiny-blocks/value-object Version ^5.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 tiny-blocks/time contains the following files

Loading the files please wait ...