<?php
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
function getFillNotion(\DateTimeImmutable $fillStart, \DateTimeImmutable $fillEnd, \DateTimeInterface $gapStart, \DateTimeInterface $gapEnd)
{
//$gapInterval = $gapStart->diff($gapEnd); // Doesn't work
$gapInterval = new \DateInterval('PT'.($gapEnd->getTimestamp() - $gapStart->getTimestamp()).'S');
if($gapStart > $fillStart) {
//The fill is older than the gap so make the fill's endTime match the gap's endTime
$fillEndModified = $fillEnd
->modify('previous '.$gapEnd->format('D'))
->setTime(...explode('.', $gapEnd->format('H.i.s.u')));
if($fillEndModified->diff($fillEnd)->format('%a') >= 7) {
$fillEndModified = $fillEndModified->add(new \DateInterval('P7D'));
}
$fillStartModified = $fillEndModified->sub($gapInterval);
if($fillStartModified < $fillStart) {
return [];
}
}
else {
//The fill is newer than the gap so make the fill's startTime match the gap's startTime
$fillStartModified = $fillStart
->modify('next '.$gapStart->format('D'))
->setTime(...explode('.', $gapStart->format('H.i.s.u')));
if($fillStart->diff($fillStartModified)->format('%a') >= 7) {
$fillStartModified = $fillStartModified->sub(new \DateInterval('P7D'));
}
$fillEndModified = $fillStartModified->add($gapInterval);
if($fillEndModified > $fillEnd) {
return [];
}
}
return [$fillStartModified, $fillEndModified];
}
function getFillRequinix(\DateTime $fillStart, \DateTime $fillEnd, \DateTime $gapStart, \DateTime $gapEnd)
{
//
// being with the original start
$fillStartModified = clone $fillStart;
// move to the next weekday and time
$wdtStart = $gapStart->format("l H:i:s");
if ($fillStartModified->format("l H:i:s") != $wdtStart) {
$fillStartModified->modify("next {$wdtStart}");
}
// get the duration, minus a bit so we can do a "next <day>" after
$days = $gapStart->diff($gapEnd)->days - 1;
// get the weekday and time
$wdtEnd = $gapEnd->format("l H:i:s");
// update
$fillEndModified = clone $fillStartModified;
$fillEndModified->modify("+${days} days");
$fillEndModified->modify("next {$wdtEnd}");
return $fillStartModified < $fillStart || $fillEndModified > $fillEnd?[]:[$fillStartModified, $fillEndModified];
}
function isDifferent(?DateTimeInterface $requinix, $notion) {
if($requinix xor $notion) {
return true;
}
elseif(!$requinix && !$notion) {
return false;
}
else {
return $requinix->getTimestamp() !== $notion->getTimestamp();
}
}
/*
Fill Sunday 2019-02-17 08:09:53 -> Saturday 2019-04-06 19:09:48
Gap Sunday 2019-04-14 20:33:00 -> Tuesday 2019-05-28 10:05:28
*/
$max = 800*24*60*60;
$int = 80*24*60*60;
$score = ['requinix'=>0, 'notion'=>0, 'tie'=>0, 'nofill'=>0];
for ($i = 0; $i < 10000; $i++) {
$fillEnd = time()-rand(0, $max);
$fillStart = $fillEnd-rand(0, $int);
$gapEnd = time()-rand(0, $max);
$gapStart = $gapEnd-rand(0, $int);
$fillEnd = new DateTime("@$fillEnd");
$fillStart = new DateTime("@$fillStart");
$gapEnd = new DateTime("@$gapEnd");
$gapStart = new DateTime("@$gapStart");
$fillRequinix = getFillRequinix($fillStart, $fillEnd, $gapStart, $gapEnd);
$fillNotion = getFillNotion(DateTimeImmutable::createFromMutable( $fillStart ), DateTimeImmutable::createFromMutable( $fillEnd ), $gapStart, $gapEnd);
if($fillRequinix && $fillNotion) {
$gapStartTimestamp = $gapStart->getTimestamp();
$fillRequinixOffset = abs($gapStartTimestamp - $fillRequinix[0]->getTimestamp());
$fillNotionOffset = abs($gapStartTimestamp - $fillNotion[0]->getTimestamp());
if($fillRequinixOffset === $fillNotionOffset) {
$score['tie']++;
}
elseif($fillRequinixOffset<$fillNotionOffset) {
$score['requinix']++;
}
else {
$score['notion']++;
}
}
elseif($fillRequinix) {
$score['requinix']++;
}
elseif($fillNotion) {
$score['notion']++;
}
else {
$score['nofill']++;
}
}
$score['total'] = array_sum($score);
print_r($score);
- Output for 7.4.10
- Array
(
[requinix] => 79
[notion] => 2145
[tie] => 2315
[nofill] => 5461
[total] => 10000
)
- Output for 7.4.9
- Array
(
[requinix] => 65
[notion] => 2118
[tie] => 2369
[nofill] => 5448
[total] => 10000
)
- Output for 7.4.8
- Array
(
[requinix] => 62
[notion] => 2124
[tie] => 2373
[nofill] => 5441
[total] => 10000
)
- Output for 7.4.7
- Array
(
[requinix] => 64
[notion] => 2103
[tie] => 2322
[nofill] => 5511
[total] => 10000
)
- Output for 7.4.6
- Array
(
[requinix] => 58
[notion] => 2191
[tie] => 2375
[nofill] => 5376
[total] => 10000
)
- Output for 7.4.5
- Array
(
[requinix] => 74
[notion] => 2113
[tie] => 2349
[nofill] => 5464
[total] => 10000
)
- Output for 7.4.4
- Array
(
[requinix] => 76
[notion] => 2073
[tie] => 2424
[nofill] => 5427
[total] => 10000
)
- Output for 7.4.3
- Array
(
[requinix] => 75
[notion] => 2062
[tie] => 2408
[nofill] => 5455
[total] => 10000
)
- Output for 7.4.2
- Array
(
[requinix] => 67
[notion] => 2088
[tie] => 2414
[nofill] => 5431
[total] => 10000
)
- Output for 7.4.1
- Array
(
[requinix] => 62
[notion] => 2152
[tie] => 2313
[nofill] => 5473
[total] => 10000
)
- Output for 7.4.0
- Array
(
[requinix] => 58
[notion] => 2106
[tie] => 2454
[nofill] => 5382
[total] => 10000
)
- Output for 7.3.22
- Array
(
[requinix] => 73
[notion] => 2108
[tie] => 2377
[nofill] => 5442
[total] => 10000
)
- Output for 7.3.21
- Array
(
[requinix] => 62
[notion] => 2067
[tie] => 2362
[nofill] => 5509
[total] => 10000
)
- Output for 7.3.20
- Array
(
[requinix] => 77
[notion] => 2084
[tie] => 2398
[nofill] => 5441
[total] => 10000
)
- Output for 7.3.19
- Array
(
[requinix] => 66
[notion] => 2064
[tie] => 2365
[nofill] => 5505
[total] => 10000
)
- Output for 7.3.18
- Array
(
[requinix] => 68
[notion] => 2105
[tie] => 2419
[nofill] => 5408
[total] => 10000
)
- Output for 7.3.17
- Array
(
[requinix] => 68
[notion] => 2197
[tie] => 2319
[nofill] => 5416
[total] => 10000
)
- Output for 7.3.16
- Array
(
[requinix] => 88
[notion] => 2106
[tie] => 2354
[nofill] => 5452
[total] => 10000
)
- Output for 7.3.15
- Array
(
[requinix] => 70
[notion] => 2093
[tie] => 2380
[nofill] => 5457
[total] => 10000
)
- Output for 7.3.14
- Array
(
[requinix] => 85
[notion] => 2154
[tie] => 2368
[nofill] => 5393
[total] => 10000
)
- Output for 7.3.13
- Array
(
[requinix] => 64
[notion] => 2086
[tie] => 2365
[nofill] => 5485
[total] => 10000
)
- Output for 7.3.12
- Array
(
[requinix] => 79
[notion] => 2154
[tie] => 2435
[nofill] => 5332
[total] => 10000
)
- Output for 7.3.11
- Array
(
[requinix] => 67
[notion] => 2107
[tie] => 2372
[nofill] => 5454
[total] => 10000
)
- Output for 7.3.10
- Array
(
[requinix] => 73
[notion] => 2118
[tie] => 2367
[nofill] => 5442
[total] => 10000
)
- Output for 7.3.9
- Array
(
[requinix] => 80
[notion] => 2157
[tie] => 2416
[nofill] => 5347
[total] => 10000
)
- Output for 7.3.8
- Array
(
[requinix] => 71
[notion] => 2158
[tie] => 2374
[nofill] => 5397
[total] => 10000
)
- Output for 7.3.7
- Array
(
[requinix] => 76
[notion] => 2179
[tie] => 2353
[nofill] => 5392
[total] => 10000
)
- Output for 7.3.6
- Array
(
[requinix] => 80
[notion] => 2091
[tie] => 2383
[nofill] => 5446
[total] => 10000
)
- Output for 7.3.5
- Array
(
[requinix] => 59
[notion] => 2155
[tie] => 2362
[nofill] => 5424
[total] => 10000
)
- Output for 7.3.4
- Array
(
[requinix] => 73
[notion] => 2139
[tie] => 2357
[nofill] => 5431
[total] => 10000
)
- Output for 7.3.3
- Array
(
[requinix] => 62
[notion] => 2089
[tie] => 2422
[nofill] => 5427
[total] => 10000
)
- Output for 7.3.2
- Array
(
[requinix] => 58
[notion] => 2111
[tie] => 2344
[nofill] => 5487
[total] => 10000
)
- Output for 7.3.1
- Array
(
[requinix] => 69
[notion] => 2111
[tie] => 2360
[nofill] => 5460
[total] => 10000
)
- Output for 7.3.0
- Array
(
[requinix] => 62
[notion] => 2137
[tie] => 2375
[nofill] => 5426
[total] => 10000
)
- Output for 7.2.33
- Array
(
[requinix] => 78
[notion] => 2090
[tie] => 2394
[nofill] => 5438
[total] => 10000
)
- Output for 7.2.32
- Array
(
[requinix] => 74
[notion] => 2127
[tie] => 2377
[nofill] => 5422
[total] => 10000
)
- Output for 7.2.31
- Array
(
[requinix] => 86
[notion] => 2086
[tie] => 2397
[nofill] => 5431
[total] => 10000
)
- Output for 7.2.30
- Array
(
[requinix] => 57
[notion] => 2117
[tie] => 2404
[nofill] => 5422
[total] => 10000
)
- Output for 7.2.29
- Array
(
[requinix] => 58
[notion] => 2141
[tie] => 2458
[nofill] => 5343
[total] => 10000
)
- Output for 7.2.28
- Array
(
[requinix] => 57
[notion] => 2073
[tie] => 2395
[nofill] => 5475
[total] => 10000
)
- Output for 7.2.27
- Array
(
[requinix] => 65
[notion] => 2210
[tie] => 2386
[nofill] => 5339
[total] => 10000
)
- Output for 7.2.26
- Array
(
[requinix] => 77
[notion] => 2022
[tie] => 2495
[nofill] => 5406
[total] => 10000
)
- Output for 7.2.25
- Array
(
[requinix] => 68
[notion] => 2147
[tie] => 2331
[nofill] => 5454
[total] => 10000
)
- Output for 7.2.24
- Array
(
[requinix] => 68
[notion] => 2120
[tie] => 2432
[nofill] => 5380
[total] => 10000
)
- Output for 7.2.23
- Array
(
[requinix] => 68
[notion] => 2122
[tie] => 2375
[nofill] => 5435
[total] => 10000
)
- Output for 7.2.22
- Array
(
[requinix] => 80
[notion] => 2126
[tie] => 2365
[nofill] => 5429
[total] => 10000
)
- Output for 7.2.21
- Array
(
[requinix] => 76
[notion] => 2151
[tie] => 2422
[nofill] => 5351
[total] => 10000
)
- Output for 7.2.20
- Array
(
[requinix] => 61
[notion] => 2155
[tie] => 2321
[nofill] => 5463
[total] => 10000
)
- Output for 7.2.19
- Array
(
[requinix] => 76
[notion] => 2125
[tie] => 2431
[nofill] => 5368
[total] => 10000
)
- Output for 7.2.18
- Array
(
[requinix] => 67
[notion] => 2127
[tie] => 2365
[nofill] => 5441
[total] => 10000
)
- Output for 7.2.17
- Array
(
[requinix] => 77
[notion] => 2098
[tie] => 2385
[nofill] => 5440
[total] => 10000
)
- Output for 7.2.16
- Array
(
[requinix] => 82
[notion] => 2151
[tie] => 2401
[nofill] => 5366
[total] => 10000
)
- Output for 7.2.15
- Array
(
[requinix] => 86
[notion] => 2110
[tie] => 2360
[nofill] => 5444
[total] => 10000
)
- Output for 7.2.14
- Array
(
[requinix] => 61
[notion] => 2138
[tie] => 2351
[nofill] => 5450
[total] => 10000
)
- Output for 7.2.13
- Array
(
[requinix] => 65
[notion] => 2103
[tie] => 2443
[nofill] => 5389
[total] => 10000
)
- Output for 7.2.12
- Array
(
[requinix] => 67
[notion] => 2126
[tie] => 2432
[nofill] => 5375
[total] => 10000
)
- Output for 7.2.11
- Array
(
[requinix] => 63
[notion] => 2160
[tie] => 2389
[nofill] => 5388
[total] => 10000
)
- Output for 7.2.10
- Array
(
[requinix] => 71
[notion] => 2142
[tie] => 2374
[nofill] => 5413
[total] => 10000
)
- Output for 7.2.9
- Array
(
[requinix] => 57
[notion] => 2139
[tie] => 2390
[nofill] => 5414
[total] => 10000
)
- Output for 7.2.8
- Array
(
[requinix] => 70
[notion] => 2062
[tie] => 2421
[nofill] => 5447
[total] => 10000
)
- Output for 7.2.7
- Array
(
[requinix] => 55
[notion] => 2145
[tie] => 2369
[nofill] => 5431
[total] => 10000
)
- Output for 7.2.6
- Array
(
[requinix] => 73
[notion] => 2172
[tie] => 2306
[nofill] => 5449
[total] => 10000
)
- Output for 7.2.5
- Array
(
[requinix] => 65
[notion] => 2117
[tie] => 2408
[nofill] => 5410
[total] => 10000
)
- Output for 7.2.4
- Array
(
[requinix] => 59
[notion] => 2072
[tie] => 2314
[nofill] => 5555
[total] => 10000
)
- Output for 7.2.3
- Array
(
[requinix] => 60
[notion] => 2017
[tie] => 2379
[nofill] => 5544
[total] => 10000
)
- Output for 7.2.2
- Array
(
[requinix] => 71
[notion] => 2085
[tie] => 2410
[nofill] => 5434
[total] => 10000
)
- Output for 7.2.1
- Array
(
[requinix] => 68
[notion] => 2227
[tie] => 2325
[nofill] => 5380
[total] => 10000
)
- Output for 7.2.0
- Array
(
[requinix] => 45
[notion] => 2116
[tie] => 2392
[nofill] => 5447
[total] => 10000
)
preferences:
88.03 ms | 401 KiB | 73 Q