All Projects → florianv → Business

florianv / Business

Licence: mit
📅 DateTime calculations in business hours

Labels

Projects that are alternatives of or similar to Business

vue-single-date-picker
A Vue project - single date picker
Stars: ✭ 16 (-95.47%)
Mutual labels:  date
Jalali Moment
Display, parse, manipulate, validate and convert jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times.
Stars: ✭ 264 (-25.21%)
Mutual labels:  date
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-16.71%)
Mutual labels:  date
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-93.2%)
Mutual labels:  date
Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (-28.05%)
Mutual labels:  date
Md Date Time Picker
An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
Stars: ✭ 272 (-22.95%)
Mutual labels:  date
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-89.8%)
Mutual labels:  date
Maya
Datetimes for Humans™
Stars: ✭ 3,298 (+834.28%)
Mutual labels:  date
React Daterange Picker
A date range picker for your React app.
Stars: ✭ 259 (-26.63%)
Mutual labels:  date
Timeago.dart
A library useful for creating fuzzy timestamps. (e.g. "5 minutes ago")
Stars: ✭ 293 (-17%)
Mutual labels:  date
edtf.js
Extended Date Time Format (ISO 8601-2 / EDTF) Parser for JavaScript
Stars: ✭ 44 (-87.54%)
Mutual labels:  date
react-ago-component
A component for React that renders the approximate time ago in words from a specific past date using an HTML5 time element.
Stars: ✭ 25 (-92.92%)
Mutual labels:  date
React Native Calendar Select
A component to select period from calendar like Airbnb
Stars: ✭ 279 (-20.96%)
Mutual labels:  date
zemen
Ethiopian to Gregorian date conversion javascript implementation - የ ኢትዮጵያ ቀን መቁጠሪያ
Stars: ✭ 20 (-94.33%)
Mutual labels:  date
Timestamp
⏰ A better macOS menu bar clock.
Stars: ✭ 296 (-16.15%)
Mutual labels:  date
date4j
Lightweight alternative to Java's built-in date-time classes. Android-friendly. Compiles under JDK 1.5.
Stars: ✭ 36 (-89.8%)
Mutual labels:  date
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (-24.08%)
Mutual labels:  date
Time
Simple time handling in Rust
Stars: ✭ 334 (-5.38%)
Mutual labels:  date
Pandas market calendars
Exchange calendars to use with pandas for trading applications
Stars: ✭ 319 (-9.63%)
Mutual labels:  date
Awesome Falsehood
😱 Falsehoods Programmers Believe in
Stars: ✭ 16,614 (+4606.52%)
Mutual labels:  date

Business Build status Version PHP Version

DateTime calculations in business hours

Installation

$ composer require florianv/business

Usage

First you need to configure your business schedule:

use Business\SpecialDay;
use Business\Day;
use Business\Days;
use Business\Business;
use Business\Holidays;
use Business\DateRange;

// Opening hours for each week day. If not specified, it is considered closed
$days = [
    // Standard days with fixed opening hours
    new Day(Days::MONDAY, [['09:00', '13:00'], ['2pm', '5 PM']]),
    new Day(Days::TUESDAY, [['9 AM', '5 PM']]),
    new Day(Days::WEDNESDAY, [['10:00', '13:00'], ['14:00', '17:00']]),
    new Day(Days::THURSDAY, [['10 AM', '5 PM']]),
    
    // Special day with dynamic opening hours depending on the date
    new SpecialDay(Days::FRIDAY, function (\DateTime $date) {
        if ('2015-05-29' === $date->format('Y-m-d')) {
            return [['9 AM', '12:00']];
        }
    
        return [['9 AM', '5 PM']];
    }),
];

// Optional holiday dates
$holidays = new Holidays([
    new \DateTime('2015-01-01'),
    new \DateTime('2015-01-02'),
    new DateRange(new \DateTime('2015-07-08'), new \DateTime('2015-07-11')),
]);

// Optional business timezone
$timezone = new \DateTimeZone('Europe/Paris');

// Create a new Business instance
$business = new Business($days, $holidays, $timezone);

Methods

within() - Tells if a date is within business hours
$bool = $business->within(new \DateTime('2015-05-11 10:00'));
timeline() - Returns a timeline of business dates
$start = new \DateTime('2015-05-11 10:00');
$end = new \DateTime('2015-05-14 10:00');
$interval = new \DateInterval('P1D');

$dates = $business->timeline($start, $end, $interval);
closest() - Returns the closest business date from a given date
// After that date (including it)
$nextDate = $business->closest(new \DateTime('2015-05-11 10:00'));

// Before that date (including it)
$lastDate = $business->closest(new \DateTime('2015-05-11 10:00'), Business::CLOSEST_LAST);

Serialization

PHP serialization

The Business class can be serialized so it can be stored for later reuse:

$serialized = serialize($business);
$business = unserialize($serialized);

If you use SpecialDay instances, you need to install the jeremeamia/superclosure library providing closure serialization:

$ composer require jeremeamia/superclosure

JSON serialization

All classes can be encoded to JSON

$json = json_encode($business);

The SpecialDay instances require a context in order extract the data from the callable. This is automatically set to new \DateTime('now') for json_encode() call only.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].