Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7454222
DateTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
DateTest.php
View Options
<?php
use
Eris\Generators
;
class
DateTest
extends
\PHPUnit\Framework\TestCase
{
use
Eris\TestTrait
;
public
function
testYearOfADate
()
{
$this
->
forAll
(
Generators
::
date
(
"2014-01-01T00:00:00"
,
"2014-12-31T23:59:59"
)
)
->
then
(
function
(
DateTime
$date
)
{
$this
->
assertEquals
(
"2014"
,
$date
->
format
(
'Y'
)
);
});
}
public
function
testDefaultValuesForTheInterval
()
{
$this
->
forAll
(
Generators
::
date
()
)
->
then
(
function
(
DateTime
$date
)
{
$this
->
assertGreaterThanOrEqual
(
"1970"
,
$date
->
format
(
'Y'
)
);
$this
->
assertLessThanOrEqual
(
"2038"
,
$date
->
format
(
'Y'
)
);
});
}
public
function
testFromDayOfYearFactoryMethodRespectsDistanceBetweenDays
()
{
$this
->
forAll
(
Generators
::
choose
(
2000
,
2020
),
Generators
::
choose
(
0
,
364
),
Generators
::
choose
(
0
,
364
)
)
->
then
(
function
(
$year
,
$dayOfYear
,
$anotherDayOfYear
)
{
$day
=
fromZeroBasedDayOfYear
(
$year
,
$dayOfYear
);
$anotherDay
=
fromZeroBasedDayOfYear
(
$year
,
$anotherDayOfYear
);
$this
->
assertEquals
(
abs
(
$dayOfYear
-
$anotherDayOfYear
)
*
86400
,
abs
(
$day
->
getTimestamp
()
-
$anotherDay
->
getTimestamp
()),
"Days of the year $year: $dayOfYear, $anotherDayOfYear"
.
PHP_EOL
.
"{$day->format(DateTime::ISO8601)}, {$anotherDay->format(DateTime::ISO8601)}"
);
});
}
}
function
fromZeroBasedDayOfYear
(
$year
,
$dayOfYear
)
{
return
DateTime
::
createFromFormat
(
'z Y H i s'
,
$dayOfYear
.
' '
.
$year
.
' 00 00 00'
,
new
DateTimeZone
(
"UTC"
)
);
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 23:08 (3 d, 8 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f5/3b/ad55d17da58f3408403cdd3384bc
Default Alt Text
DateTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment