akifrabbani / molek
Calculate amount based on two dates and a ruleset
Installs: 4 552
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.2.0
This package is auto-updated.
Last update: 2024-06-20 03:54:43 UTC
README
Molek
Payment amount calculator based on two dates and ruleset.
Install
Via Composer
$ composer require akifrabbani/molek
Usage
$start = new DateTime("2019-07-20 08:00:00"); $end = new DateTime("2019-09-20 23:00:00"); // Rule for every hour is RM 1. $ruleset = [ 'base_price' => 0, 'operation_hours' => [ 'start' => '08:00', 'end' => '20:00' ], 'first' => [ [ 'type' => 'minute', 'duration' => 15, 'price' => 0 ], [ 'type' => 'hour', 'duration' => 1, 'price' => 4, 'days' => ['sat', 'sun'], 'dates' => [ '2019-07-11' ] ], [ 'type' => 'hour', 'duration' => 1, 'price' => 2, 'days' => ['mon', 'tue', 'wed', 'thu', 'fri'] ] ], 'normal' => [ [ 'type' => 'hour', 'interval' => 1, 'price' => 1, 'days' => ['mon', 'tue', 'wed', 'thu', 'fri'] ], [ 'type' => 'hour', 'interval' => 1, 'price' => 1.5, 'days' => ['sat', 'sun'], 'dates' => [ '2019-07-11' ] ] ], 'max' => [ [ 'type' => 'hour', 'duration' => 8, 'price' => 10, 'days' => ['mon', 'tue', 'wed', 'thu', 'fri'] ], [ 'type' => 'hour', 'duration' => 8, 'price' => 15, 'days' => ['sat', 'sun'], 'dates' => [ '2019-07-11' ] ] ] ]; $molek = new AkifRabbani\Molek\Molek($ruleset); echo "Price is RM " . $molek->calculate($start, $end);
Credits
- Akif Rabbani (https://github.com/akifrabbani)
- Mohd Hafizuddin M Marzuki (https://github.com/apih)
License
The MIT License (MIT). Please see License File for more information.