All Projects → Kirouane → interval

Kirouane / interval

Licence: MIT license
This PHP library provides some tools to handle intervals. For instance, you can compute the union or intersection of two intervals.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to interval

planning-wiki
By the community, for everyone. Planning.wiki is the online guide to AI Planning
Stars: ✭ 54 (+116%)
Mutual labels:  scheduling, planning
chronoman
Utility class to simplify use of timers created by setTimeout
Stars: ✭ 15 (-40%)
Mutual labels:  period, interval
unikmer
Toolkit for k-mer with taxonomic information
Stars: ✭ 46 (+84%)
Mutual labels:  union, intersection
Pg timetable
pg_timetable: Advanced scheduling for PostgreSQL
Stars: ✭ 382 (+1428%)
Mutual labels:  scheduling, interval
cocktail
Elixir date recurrence library based on iCalendar events
Stars: ✭ 115 (+360%)
Mutual labels:  datetime, scheduling
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (+180%)
Mutual labels:  datetime, interval
Period
PHP's time range API
Stars: ✭ 616 (+2364%)
Mutual labels:  datetime, interval
task-bundle
Scheduling of tasks for symfony made simple
Stars: ✭ 33 (+32%)
Mutual labels:  scheduling, interval
DateTimeRange
DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncating a time range, iterate through a time range, and so forth.
Stars: ✭ 79 (+216%)
Mutual labels:  datetime
BotSmartScheduler
Enhance your planning capabilities with this smart bot!
Stars: ✭ 44 (+76%)
Mutual labels:  planning
flyxc
GPS track visualization, flight planning, live tracking, and more ...
Stars: ✭ 47 (+88%)
Mutual labels:  planning
dotvariant
A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++)
Stars: ✭ 52 (+108%)
Mutual labels:  union
isodatetime
📅 ⌚ Python ISO 8601 date time parser and data model/manipulation utilities
Stars: ✭ 32 (+28%)
Mutual labels:  datetime
union-pay
simplest union pay(银联支付)
Stars: ✭ 32 (+28%)
Mutual labels:  union
FPChecker
A dynamic analysis tool to detect floating-point errors in HPC applications.
Stars: ✭ 26 (+4%)
Mutual labels:  infinity
datetime
A Go (golang) library for parsing most ISO8601 timestamps
Stars: ✭ 24 (-4%)
Mutual labels:  datetime
libvata
VATA Tree Automata Library
Stars: ✭ 23 (-8%)
Mutual labels:  union
react-timestamp
A React component for displaying a UTC datetime in the local timezone
Stars: ✭ 45 (+80%)
Mutual labels:  datetime
scrumonline
Always up to date scrumonline docker build
Stars: ✭ 18 (-28%)
Mutual labels:  planning
sublimetext-stringutilities
Sublime Text 2/3 plugin for string manipulations
Stars: ✭ 81 (+224%)
Mutual labels:  datetime

Travis Coverage Status Codacy Badge Total Downloads Latest Stable Version

Interval

This library provides some tools to handle intervals. For instance, you can compute the union or intersection of two intervals.

Use cases

  • Availabilities calculation.
  • Scheduling/calendar/planning.
  • Mathematics interval computation with open/closed boundaries
  • etc

Features

  • It computes some operations between two intervals: union, intersection and exclusion.
  • It computes some operations between two sets of intervals: exclusion for now.
  • It handles several types of boundaries : float, \DateTime and integer.
  • It handles infinity type as boundary.
  • Ability to combine infinity with \DateTime and other types.
  • filter, sort, map.
  • Immutability.
  • Chain operations.

Quality

  • Code coverage Coverage Status
  • Mutation test : Code coverage more than 90%
  • Takes care of performance and memory usage
  • PSR1/PSR2, Code Smell

Install

composer require kirouane/interval

Basic usage

Let's assume an interval [20, 40]. We instantiate a new Interval object .

$interval = new Interval(20, 40);// [20, 40];

or

$interval = Interval::create('[20,40]');// [20, 40];

We can do some operations like :

  • Intersection :
echo $interval->intersect(new Interval(30, 60)); // [30, 40];
  • Union :
echo $interval->union(new Interval(30, 60)); // {[20, 60]};

or

echo $interval->union(new Interval(60, 100)); // {[20, 40], [60, 100]};
  • Exclusion :
echo $interval->exclude(new Interval(30, 60)); // {[20, 30[};

or

echo $interval->exclude(new Interval(30, 35)); // {[20, 30[, ]35, 40]};

We can compare two intervals as well:

  • Overlapping test :
echo $interval->overlaps(new Interval(30, 60)); // true;
  • Inclusion test :
echo $interval->includes(new Interval(30, 60)); // false;

Use DateTimeInterface as boundary

$interval = new Interval(new \DateTime('2016-01-01'), new \DateTime('2016-01-10'));
// [2016-01-01T00:00:00+01:00, 2016-01-10T00:00:00+01:00];
  • Union :
echo $interval->union(Interval::create('[2016-01-10, 2016-01-15]')); 
// {[2016-01-01T00:00:00+01:00, 2016-01-15T00:00:00+01:00]};

Use Infinity as boundary

$interval = new Interval(-INF, INF);// ]-∞, +∞[;
  • Exclusion :
echo $interval->exclude(Interval::create('[2016-01-10, 2016-01-15]')); 
// {]-∞, 2016-01-10T00:00:00+01:00[, ]2016-01-15T00:00:00+01:00, +∞[};

Operations on sets (arrays) of intervals

$intervals = Intervals::create(['[0,5]', '[8,12]']);// {[0, 5], [8, 12]};
  • Exclusion :
echo $intervals->exclude(Intervals::create(['[3,10]'])); // {[0, 3[, ]10, 12]};

Chaining

$result = Interval
    ::create('[10, 20]')
    ->intersect(new Interval(11, 30))
    ->union(new Interval(15, INF))
    ->exclude(Intervals::create(['[18, 20]', '[25, 30]', '[32, 35]', '[12, 13]']))
    ->sort(function (Interval $first, Interval $second) {
        return $first->getStart()->getValue() <=> $second->getStart()->getValue();
    })
    ->map(function (Interval $interval) {
        return new Interval(
            $interval->getStart()->getValue() ** 2,
            $interval->getEnd()->getValue() ** 2
        );
    })
    ->filter(function (Interval $interval) {
        return $interval->getEnd()->getValue() > 170;
    }); 

// {[169, 324], [400, 625], [900, 1024], [1225, +∞[};
    
echo $result;    

Advanced usage

You can create intervals with open boundaries :

$result = Intervals
    ::create([']10, +INF['])
    ->exclude(Intervals::create([']18, 20]', ']25, 30[', '[32, 35]', ']12, 13]']));

// {]10, 12], ]13, 18], ]20, 25], [30, 32[, ]35, +∞[}

Contributing

You are very welcomed to contribute to this Library!

  • Clone git clone https://github.com/Kirouane/interval.git

  • Install composer install or make install (with docker and docker-compose)

  • Test vendor/bin/phpunit

  • Build vendor/bin/grumphp run

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].