Changes to timew() and wtime() to leverage last 2 bits for 4 year timestamp, making msgid checking valid according to FTSC. Added a test suite for timew()/wtime().
This commit is contained in:
59
tests/Unit/TimeWTest.php
Normal file
59
tests/Unit/TimeWTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TimeWTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*/
|
||||
public function test_timew(): void
|
||||
{
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s.v','2023-12-07 12:13:14.567');
|
||||
|
||||
$this->assertEquals(4042011877,timew($date));
|
||||
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s.v','2019-12-07 12:13:14.567');
|
||||
|
||||
$this->assertEquals(4042011877,timew($date));
|
||||
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s.v','2022-12-07 01:28:50.400');
|
||||
|
||||
$this->assertEquals(2967565092,timew($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*/
|
||||
public function test_wtime(): void
|
||||
{
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s.v','2023-12-07 12:13:14.5');
|
||||
|
||||
$this->assertEquals($date,wtime(4042011877,2022));
|
||||
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s.v','2019-12-07 12:13:14.5');
|
||||
|
||||
$this->assertEquals($date,wtime(4042011877,2018));
|
||||
|
||||
$date = Carbon::createFromFormat('Y-m-d H:i:s.v','2022-12-07 01:28:50.400');
|
||||
|
||||
$this->assertEquals($date,wtime(2967565092,2022));
|
||||
}
|
||||
|
||||
public function test_random_time(): void
|
||||
{
|
||||
$times = [];
|
||||
$now = Carbon::now()->milli(rand(0,9)*100);
|
||||
|
||||
for ($i=0;$i<1000;$i++) {
|
||||
$ran = $now->clone()->addYears(rand(-50,50))->addDays(rand(-365,365))->addHours(rand(-24,24))->addMinutes(rand(-60,60))->addSeconds(rand(-60,60));
|
||||
$times[timew($ran)] = $ran;
|
||||
}
|
||||
|
||||
foreach ($times as $wtime => $time)
|
||||
$this->assertEquals($time,wtime($wtime,$time->year));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user