Skip to content

Commit

Permalink
Updated dependencies and MSI score
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Aug 7, 2020
1 parent 9787176 commit 4182664
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 298 deletions.
148 changes: 2 additions & 146 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,150 +14,6 @@ Time Management Framework for PHP
[Source: Wikipedia](https://en.wikipedia.org/wiki/Aeon)

Define working hours and check Date Time against them, exclude holidays,
define exceptions and custom working days.
Aeon is a set of libraries that makes easier to work with PHP Date & Time in elegant Object Oriented way.

Business Hours class takes 3 parameters, described below.

```php
<?php
use Aeon\Calendar\Gregorian\BusinessHours\BusinessDays;
use Aeon\Calendar\Gregorian\BusinessHours\NonBusinessDays;

final class BusinessHours
{
/**
* @param BusinessDays $regularBusinessDays - lowest priority when checking open hours, overwrites nothing
* @param BusinessDays $customBusinessDays - highest priority when checking open hours, overwrites business days and non business days
* @param NonBusinessDays $nonBusinessDays - medium priority when checking open hours, overwrites regular business days
*/
public function __construct(BusinessDays $regularBusinessDays, BusinessDays $customBusinessDays, NonBusinessDays $nonBusinessDays)
{
}
}
```

So it's all about the priority of execution, custom business days comes over non-business days,
and non-business days comes over regular business days.

Working Hours can be dined in linear way but also as a collection of shifts (if you take a break in the middle of the day).

* `\Aeon\Calendar\Gregorian\BusinessHours\WorkingHours\LinearWorkingHours();`
* `\Aeon\Calendar\Gregorian\BusinessHours\WorkingHours\ShiftsWorkingHours()`

```php
<?php
use Aeon\Calendar\Gregorian\Time;

interface WorkingHours
{
public function openFrom() : Time;

public function openTo() : Time;

public function isOpen(Time $time) : bool;
}
```

### Simple business open from Monday to Friday 6am - 6pm

```php
<?php

use Aeon\Calendar\Gregorian\BusinessHours;
use Aeon\Calendar\Gregorian\BusinessHours\WorkingHours\LinearWorkingHours;
use Aeon\Calendar\Gregorian\Time;
use \Aeon\Calendar\Gregorian\DateTime;

$businessHours = new BusinessHours(
$regularBusinessDays = BusinessHours\BusinessDays::mondayFriday(
new LinearWorkingHours(Time::fromString('6am'), Time::fromString('6pm'))
),
BusinessHours\BusinessDays::none(),
BusinessHours\NonBusinessDays::none()
);

$businessHours->isOpen(DateTime::fromString('2020-01-03 8am')); // true
```

### Monday - Friday 6am - 6pm, Weekends 11am - 6pm

```php
<?php

use Aeon\Calendar\Gregorian\BusinessHours;
use Aeon\Calendar\Gregorian\BusinessHours\WorkingHours\LinearWorkingHours;
use Aeon\Calendar\Gregorian\Time;
use \Aeon\Calendar\Gregorian\DateTime;

$businessHours = new BusinessHours(
$regularBusinessDays = BusinessHours\BusinessDays::wholeWeek(
$weekWorkingHours = new LinearWorkingHours(Time::fromString('6am'), Time::fromString('6pm')),
$weekendWorkingHours = new LinearWorkingHours(Time::fromString('11am'), Time::fromString('6pm'))
),
BusinessHours\BusinessDays::none(),
BusinessHours\NonBusinessDays::none()
);

$businessHours->isOpen(DateTime::fromString('2020-01-03 8am')); // true
```
### Closed during regional holidays in Poland

```php
<?php

use Aeon\Calendar\Gregorian\BusinessHours;
use Aeon\Calendar\Gregorian\BusinessHours\WorkingHours\LinearWorkingHours;
use Aeon\Calendar\Gregorian\Holidays\GoogleCalendar\CountryCodes;
use Aeon\Calendar\Gregorian\Holidays\GoogleCalendarRegionalHolidays;
use Aeon\Calendar\Gregorian\Time;
use \Aeon\Calendar\Gregorian\Day;

$businessHours = new BusinessHours(
$regularBusinessDays = BusinessHours\BusinessDays::wholeWeek(
$weekWorkingHours = new LinearWorkingHours(Time::fromString('6am'), Time::fromString('6pm')),
$weekendWorkingHours = new LinearWorkingHours(Time::fromString('11am'), Time::fromString('6pm'))
),
BusinessHours\BusinessDays::none(),
$nonBusinessDay = new BusinessHours\NonBusinessDays(
new BusinessHours\NonBusinessDay\Holidays(
new GoogleCalendarRegionalHolidays(CountryCodes::PL)
)
)
);

$businessHours->isOpenOn(Day::fromString('2020-06-11')); // false
```

### Closed during regional holidays in Poland but open on January first

```php
<?php

use Aeon\Calendar\Gregorian\BusinessHours;
use Aeon\Calendar\Gregorian\BusinessHours\WorkingHours\LinearWorkingHours;
use Aeon\Calendar\Gregorian\Holidays\GoogleCalendar\CountryCodes;
use Aeon\Calendar\Gregorian\Holidays\GoogleCalendarRegionalHolidays;
use Aeon\Calendar\Gregorian\Time;
use \Aeon\Calendar\Gregorian\Day;

$businessHours = new BusinessHours(
$regularBusinessDays = BusinessHours\BusinessDays::wholeWeek(
$weekWorkingHours = new LinearWorkingHours(Time::fromString('6am'), Time::fromString('6pm')),
$weekendWorkingHours = new LinearWorkingHours(Time::fromString('11am'), Time::fromString('6pm'))
),
$customBusinessDays = new BusinessHours\BusinessDays(
new BusinessHours\BusinssDay\CustomBusinessDay(
Day::fromString('2020-01-01'),
new LinearWorkingHours(Time::fromString('11am'), Time::fromString('3pm'))
)
),
$nonBusinessDay = new BusinessHours\NonBusinessDays(
new BusinessHours\NonBusinessDay\Holidays(
new GoogleCalendarRegionalHolidays(CountryCodes::PL)
)
)
);

$businessHours->isOpenOn(Day::fromString('2020-06-11')); // false
```
Please read [Official Documentation](https://aeon-php.org/docs/business-hours/).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"aeon-php/calendar": "^0.3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.1",
"phpunit/phpunit": "^9.3",
"aeon-php/calendar-holidays": "^1.0@dev"
},
"license": "MIT",
Expand Down
Loading

0 comments on commit 4182664

Please # to comment.