Beispiel #1
0
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past date string < 2 weeks.', function ($t) {
    $date = date('Y-m-d H:i:s', time() - 86400 * 8);
    $diff = Humanise::relativeTime($date);
    $t->does($diff)->equal('a week ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past date string < 1 month.', function ($t) {
    $date = date('Y-m-d H:i:s', time() - 86400 * 14);
    $diff = Humanise::relativeTime($date);
    $t->does($diff)->equal('2 weeks ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past date string < 2 months.', function ($t) {
    $date = date('Y-m-d H:i:s', time() - 86400 * 32);
    $diff = Humanise::relativeTime($date);
    $t->does($diff)->equal('a month ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past date string < 1 year.', function ($t) {
    $date = date('Y-m-d H:i:s', time() - 86400 * 30 * 3);
    $diff = Humanise::relativeTime($date);
    $t->does($diff)->equal('3 months ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past date string < 2 years.', function ($t) {
    $date = date('Y-m-d H:i:s', time() - 86400 * 370);
    $diff = Humanise::relativeTime($date);
    $t->does($diff)->equal('a year ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past date string > 2 years.', function ($t) {
    $date = date('Y-m-d H:i:s', time() - 86400 * 760);
    $diff = Humanise::relativeTime($date);
    $t->does($diff)->equal('2 years ago');
})->covers(Humanise::class, 'relativeTime');
Beispiel #2
0
<?php

use Molovo\Humanise\Humanise;
function timeDataProvider()
{
    return [[60, 'a minute'], [300, '5 minutes'], [3600, 'an hour'], [18000, '5 hours'], [86400, 'a day'], [86400 * 5, '5 days'], [86400 * 8, 'a week'], [86400 * 14, '2 weeks'], [86400 * 32, 'a month'], [86400 * 30 * 3, '3 months'], [86400 * 365, 'a year'], [86400 * 365 * 3, '3 years']];
}
test('Test time with seconds only.', function ($t, $seconds, $expected) {
    $t->does(Humanise::time($seconds))->equal($expected);
})->covers(Humanise::class, 'time')->data(timeDataProvider());
Beispiel #3
0
<?php

use Molovo\Humanise\Humanise;
test('Test relative time with two matching timestamps.', function ($t) {
    $diff = Humanise::relativeTime(time(), time());
    $t->does($diff)->equal('now');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with two matching date strings.', function ($t) {
    $diff = Humanise::relativeTime(date('Y-m-d H:i:s'), date('Y-m-d H:i:s'));
    $t->does($diff)->equal('now');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with two matching DateTime objects.', function ($t) {
    $diff = Humanise::relativeTime(new DateTime(), new DateTime());
    $t->does($diff)->equal('now');
})->covers(Humanise::class, 'relativeTime');
Beispiel #4
0
    $diff = Humanise::relativeTime(time() - 86400);
    $t->does($diff)->equal('a day ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp < 1 week.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 6);
    $t->does($diff)->equal('6 days ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp < 2 weeks.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 8);
    $t->does($diff)->equal('a week ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp < 1 month.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 14);
    $t->does($diff)->equal('2 weeks ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp < 2 months.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 32);
    $t->does($diff)->equal('a month ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp < 1 year.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 30 * 3);
    $t->does($diff)->equal('3 months ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp < 2 years.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 370);
    $t->does($diff)->equal('a year ago');
})->covers(Humanise::class, 'relativeTime');
test('Test relative time with past timestamp > 2 years.', function ($t) {
    $diff = Humanise::relativeTime(time() - 86400 * 365 * 6);
    $t->does($diff)->equal('6 years ago');
})->covers(Humanise::class, 'relativeTime');
Beispiel #5
0
    $bytes = 1125899906842624;
    $t->does(Humanise::size($bytes, 2, Humanise::GB))->equal('1,048,576.00GB');
})->covers(Humanise::class, 'size');
test('Test byte amounts are converted correctly with TB precision.', function ($t) {
    $bytes = 128;
    $t->does(Humanise::size($bytes, 2, Humanise::TB))->equal('0.00TB');
    $bytes = 1024;
    $t->does(Humanise::size($bytes, 2, Humanise::TB))->equal('0.00TB');
    $bytes = 1048576;
    $t->does(Humanise::size($bytes, 2, Humanise::TB))->equal('0.00TB');
    $bytes = 1073741824;
    $t->does(Humanise::size($bytes, 2, Humanise::TB))->equal('0.00TB');
    $bytes = 1099511627776;
    $t->does(Humanise::size($bytes, 2, Humanise::TB))->equal('1.00TB');
    $bytes = 1125899906842624;
    $t->does(Humanise::size($bytes, 2, Humanise::TB))->equal('1,024.00TB');
})->covers(Humanise::class, 'size');
test('Test byte amounts are converted correctly with PB precision.', function ($t) {
    $bytes = 128;
    $t->does(Humanise::size($bytes, 2, Humanise::PB))->equal('0.00PB');
    $bytes = 1024;
    $t->does(Humanise::size($bytes, 2, Humanise::PB))->equal('0.00PB');
    $bytes = 1048576;
    $t->does(Humanise::size($bytes, 2, Humanise::PB))->equal('0.00PB');
    $bytes = 1073741824;
    $t->does(Humanise::size($bytes, 2, Humanise::PB))->equal('0.00PB');
    $bytes = 1099511627776;
    $t->does(Humanise::size($bytes, 2, Humanise::PB))->equal('0.00PB');
    $bytes = 1125899906842624;
    $t->does(Humanise::size($bytes, 2, Humanise::PB))->equal('1.00PB');
})->covers(Humanise::class, 'size');