axetools/dateutil

A PHP library of date time related tools

v2.0.1 2024-10-03 17:33 UTC

This package is auto-updated.

Last update: 2024-11-03 18:13:47 UTC


README

This is a php class trait that will provide methods for performing simple bitwise operations.

Source Code PHP Programming Language Read License Build Status

This project uses Semantic Versioning.

The DateUtil gives simple methods for creating relative dates, absolute dates and utilities for creating holidays and determining if the current day is a holiday or not.

Some Examples.

<?php
// The first Monday of the Month of September for the current year
$labor_day = DateTimeUtil::RelativeDateTime(9, DayOfWeek::MONDAY, Week::FIRST);

// Get Christmas day, December 25th for the current year
$christmas_day = DateTimeUtil::AbsoluteDateTime(12, 25);

// Get the last day of April for 2022
$last_day_april = DateTimeUtil::AbsoluteDateTime(4, DateTimeUtil::RELATIVE_LAST_DAY);

// Get the last day of the current month
$last_day_this_month = DateTimeUtil::AbsoluteDateTime(null, DateTimeUtil::RELATIVE_LAST_DAY);

// Get an array of Holiday objects for the US Federal Holidays from 2001
$holidays_2001 = DateTimeUtil::usFederalHolidays(2001);

// Determine if a reference datetime is between a start and end datetime
$start = Datetime::createFromFormat('Y-m-d', '2022-01-01');
$end = Datetime::createFromFormat('Y-m-d', '2022-01-05');
$reference = Datetime::createFromFormat('Y-m-d', '2022-01-03');
$is_between = DateTimeUtil::isBetween($start, $end, $reference);

// true

Installation

The preferred method of installation is via Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require axetools/dateutil