<?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)); } }