Download the PHP package geoffreyrose/useful-dates without Composer

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

[![Latest Stable Version](https://img.shields.io/packagist/v/geoffreyrose/useful-dates?style=flat-square)](https://packagist.org/packages/geoffreyrose/useful-dates) [![Test Status](https://img.shields.io/github/actions/workflow/status/geoffreyrose/useful-dates/tests.yml?branch=main&style=flat-square&label=tests)](https://github.com/geoffreyrose/useful-dates/actions?query=branch%3Amain) [![Code Coverage](https://img.shields.io/codecov/c/gh/geoffreyrose/useful-dates/main?style=flat-square)](https://app.codecov.io/gh/geoffreyrose/useful-dates/branch/main) [![License](https://img.shields.io/github/license/geoffreyrose/useful-dates?style=flat-square)](https://github.com/geoffreyrose/useful-dates/blob/main/LICENSE)

Useful Dates: A PHP Holiday Date Package

A simple and elegant PHP library for working with commonly used or desired dates in your applications. UsefulDates helps you quickly identify and retrieve important dates like holidays, birthdays, paydays, and other significant calendar events.

This is an evolution of geoffreyrose/us-holidays.

Features

On its own, UsefulDates comes with no predefined dates. It provides a clean base that you can extend with your own dates and methods.

Requirements

Installation

Quick Start

Laravel Facade

Laravel uses Package Auto-Discovery, so no manual registration is needed:


Table of Contents


Creating Custom Dates

You can create custom date definitions by extending UsefulDateAbstract. Each custom date class must implement the date() method which returns the date for the current context year.

Important: The date() method should always return dates in UTC time.

Step 1: Create a Date Class

Create a new class that extends UsefulDates\Abstracts\UsefulDateAbstract:

Tip: Carbon::createFromFormat() is faster than Carbon::create() in my benchmarks.

Step 2: Register Your Date

Use the add() method to register your custom date class:


Methods

Core Methods

setDate(Carbon|DateTime|string $date): self

Set the working date/time context (normalized to UTC). Accepts Carbon, DateTime, or a string parsable by Carbon.

add(string $dateClass): self

Register a UsefulDate by class name. The class must extend UsefulDateAbstract.

addDate(string $name, Carbon $date, ...): self

Add a simple UsefulDate without creating a class. Creates an internal definition that repeats according to the provided options.

Parameters:

addExtension(string $extensionClass, mixed $options = null): self

Register an extension (must extend UsefulDatesExtensionAbstract). Adds its useful dates and any custom methods exposed by the extension.

isUsefulDate(?Carbon $date = null): bool

Returns true if any registered UsefulDate matches the given date (defaults to the current context date).

getUsefulDate(?Carbon $date = null, ?array $filters = null): array

Returns a list of matching UsefulDate objects for the given date (defaults to the current context date).

See the Filtering section for filter options.

Range & Navigation Methods

getUsefulDatesInDays(int $days, ?Carbon $startDate = null, ?array $filters = null): array

Get all matching UsefulDates occurring from $startDate (default: current context) through $startDate + $days.

getUsefulDatesInYears(int $years, ?array $filters = null): array

Get all useful dates within the next N years from the current context date.

getNextUsefulDates(int $number = 1, ?array $filters = null): array

Get the next N useful dates after the current context date.

getPreviousUsefulDates(int $number = 1, ?array $filters = null): array

Get the previous N useful dates before the current context date.

getUsefulDatesByYear(?int $year = null, ?array $filters = null): array

Get all useful dates within a given calendar year (defaults to current context year).

Business Day Methods

Default business days are Monday–Friday ([1, 2, 3, 4, 5]). Days use Carbon's constants where 0 = Sunday through 6 = Saturday.

isStandardBusinessDays(): bool

Returns true if the configured business days are Monday–Friday.

setBusinessDays(array $days): self

Define which days of week are business days (0=Sun..6=Sat). Throws InvalidDayException for invalid values.

getBusinessDays(): array

Get the configured business days array.

isBusinessDay(?Carbon $date = null): bool

Check if the given date (or current context date) is a business day.

nextBusinessDay(): ?Carbon

Get the next business day after the current context date.

prevBusinessDay(): ?Carbon

Get the previous business day before the current context date.

todayOrPreviousBusinessDay(): Carbon

Returns today if it is a business day, otherwise the previous business day.

todayOrNextBusinessDay(): Carbon

Returns today if it is a business day, otherwise the next business day.


UsefulDate Properties

When creating custom date classes by extending UsefulDateAbstract, you have access to these properties:

Property Type Default Description
$name string (required) Human-friendly name for the date
$additional_search_names array [] Alternative names for searching
$is_repeated bool false Whether the date repeats
$repeat_frequency RepeatFrequency NONE YEARLY, MONTHLY, NONE, or CUSTOM
$start_date ?Carbon null First date the event is considered
$end_date ?Carbon null Last date the event is considered

You may also add any additonal properties to your custom dates as needed

Instance Methods

These methods are available on each UsefulDate instance:

usefulDate(): ?Carbon

Returns the date if it should be considered for the current context (applies repeat frequency and start/end rules), otherwise null.

daysAway(): int

Returns the number of days from the current context to this date. Positive = future, negative = past, 0 = today.

Complete Example

Extensions

Extensions allow you to bundle groups of UsefulDates together, optionally with custom methods.

Available Extensions

Extension Description
geoffreyrose/useful-dates-us-holidays US Holidays

Using an Extension

Creating an Extension

Create a class that extends UsefulDatesExtensionAbstract:

Using the extension with custom methods:

IDE Support

For better IDE autocompletion with extension methods, create a wrapper class:

Note: The @mixin annotation is what helps IDEs understand the extension methods.

Filtering

Filter useful dates by custom properties using the $filters parameter available on most retrieval methods.

Filter Structure

Each filter is an array with three keys:

Key Description
property The property name on the UsefulDate class
operator Comparison operator: >, <, >=, <=, =, !=
value The value to compare against

Example

Multiple filters are combined with AND logic (all conditions must match).


Development

Linting

Static Analysis

Testing


License

MIT License. See LICENSE for details.


All versions of useful-dates with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
nesbot/carbon Version ^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 geoffreyrose/useful-dates contains the following files

Loading the files please wait ...