-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
87 lines (78 loc) · 1.53 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// Run this example in terminal / console
use AkifRabbani\Molek\Molek;
require 'src/Molek.php';
$bench_time_start = microtime(true);
if (!isset($argv[1])) die('Please provide start date!');
if (!isset($argv[2])) die('Please provide end date!');
$start_at = new DateTime($argv[1]);
$end_at = new DateTime($argv[2]);
// Complete ruleset
// All rules are optional
$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 Molek();
$molek->setRuleset($ruleset);
$result = $molek->calculate($start_at, $end_at, true);
var_dump($result);
echo 'Ran in ' . number_format(microtime(true) - $bench_time_start, 3) . ' seconds';