Jyxo\Time\TimeTest::testFormatExtended PHP Метод

testFormatExtended() публичный Метод

Tests the formatExtended() method.
См. также: Jyxo\Time\Time::formatExtended()
public testFormatExtended ( )
    public function testFormatExtended()
    {
        // No parameters provided
        $this->assertEquals(sprintf('6. %s 2008 v 5:04', mb_strtolower(_('July#~Genitive'), 'utf-8'), _('at')), Time::get('2008-07-06 05:04:03')->formatExtended());
        // Date format set
        $this->assertEquals('08-07-06 v 5:04', Time::get('2008-07-06 05:04:03')->formatExtended('y-m-d'));
        // Both the date and time format set
        $this->assertEquals('08-07-06 v 05:04:03', Time::get('2008-07-06 05:04:03')->formatExtended('y-m-d', 'H:i:s'));
        // Date and time format set; time part in the output should be empty
        $this->assertEquals('2008-07-06', Time::get('2008-07-06 05:04:03')->formatExtended('Y-m-d', ''));
        // Today
        $now = time();
        $this->assertEquals(_('Today'), Time::get($now)->formatExtended('j. F Y', ''));
        $this->assertEquals(_('Today') . ' ' . _('at') . ' ' . date('G:i', $now), Time::get($now, date_default_timezone_get())->formatExtended());
        // Yesterday
        $yesterday = strtotime('-1 day');
        $this->assertEquals(_('Yesterday'), Time::get($yesterday)->formatExtended('j. F Y', ''));
        $this->assertEquals(_('Yesterday') . ' ' . _('at') . ' ' . date('G:i', $yesterday), Time::get($yesterday)->formatExtended());
        // Last week
        $days = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday')];
        for ($i = 2; $i < 7; $i++) {
            $day = strtotime('-' . $i . ' days');
            $this->assertEquals($days[date('N', $day) - 1], Time::get($day)->formatExtended('j. F Y', ''));
            $this->assertEquals($days[date('N', $day) - 1] . ' v ' . date('G:i', $day), Time::get($day)->formatExtended());
        }
        // More than a week ago
        $this->assertEquals(sprintf('1. %s 2003', mb_strtolower(_('February#~Genitive'), 'utf-8')), Time::get('2003-02-01 04:05:06')->formatExtended('j. F Y', ''));
        $this->assertEquals(sprintf('1. %s 2003 %s 4:05', mb_strtolower(_('February#~Genitive'), 'utf-8'), _('at')), Time::get('2003-02-01 04:05:06')->formatExtended());
        // Time zone handling
        // Date line
        $time = new Time(gmdate('Y-m-d') . ' 00:00:00', 'UTC');
        $this->assertSame(_('Today'), $time->formatExtended('', '', 'Europe/Prague'));
        $this->assertSame(_('Yesterday'), $time->minus('2 hour')->formatExtended('', '', 'Europe/Prague'));
        // Last week
        $days = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday')];
        $timestamp = time() - 7 * 86400;
        $time = new Time(gmdate('Y-m-d', $timestamp) . ' 00:00:00', 'UTC');
        $day = $days[date('N', $timestamp) - 1];
        $this->assertSame(sprintf('%s %s %s 05:00:00', $day, gmdate('Y-m-d', $timestamp), _('at')), $time->formatExtended('l Y-m-d', 'H:i:s', 'Etc/GMT-5'));
    }