Ejemplo n.º 1
0
 public function testResetToStringFormat()
 {
     $d = IntlCarbon::now();
     IntlCarbon::setToStringFormat('123');
     IntlCarbon::resetToStringFormat();
     $this->assertSame($d->toDateTimeString(), '' . $d);
 }
Ejemplo n.º 2
0
 public function testParseCreatesAnInstanceDefaultToNow()
 {
     $c = IntlCarbon::parse();
     $now = IntlCarbon::now();
     $this->assertInstanceOfIntlCarbon($c);
     $this->assertSame($now->tzName, $c->tzName);
     $this->assertIntlCarbon($c, $now->year, $now->month, $now->day, $now->hour, $now->minute, $now->second);
 }
 public function testCreateFromTimeWithTimeZoneString()
 {
     $d = IntlCarbon::createFromTime(12, 0, 0, 'Europe/London');
     $this->assertIntlCarbon($d, IntlCarbon::now()->year, IntlCarbon::now()->month, IntlCarbon::now()->day, 12, 0, 0);
     $this->assertSame('Europe/London', $d->tzName);
 }
 public function testNowWithTimezone()
 {
     $dt = IntlCarbon::now('Europe/London');
     $this->assertSame(time(), $dt->timestamp);
     $this->assertSame('Europe/London', $dt->tzName);
 }
Ejemplo n.º 5
0
 public function testInvalidGetter()
 {
     $this->setExpectedException('InvalidArgumentException');
     $d = IntlCarbon::now();
     $bb = $d->doesNotExit;
 }
Ejemplo n.º 6
0
 public function testCopy()
 {
     $dating = IntlCarbon::now();
     $dating2 = $dating->copy();
     $this->assertNotSame($dating, $dating2);
 }
 public function testDiffForHumansLocalizedInFarsi()
 {
     IntlCarbon::setLocale('fa');
     $d = IntlCarbon::now()->subSecond();
     $this->assertSame('1 ثانیه پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subSeconds(2);
     $this->assertSame('2 ثانیه پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subMinute();
     $this->assertSame('1 دقیقه پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subMinutes(2);
     $this->assertSame('2 دقیقه پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subHour();
     $this->assertSame('1 ساعت پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subHours(2);
     $this->assertSame('2 ساعت پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subDay();
     $this->assertSame('1 روز پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subDays(2);
     $this->assertSame('2 روز پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subWeek();
     $this->assertSame('1 هفته پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subWeeks(2);
     $this->assertSame('2 هفته پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subMonth();
     $this->assertSame('1 ماه پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subMonths(2);
     $this->assertSame('2 ماه پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subYear();
     $this->assertSame('1 سال پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->subYears(2);
     $this->assertSame('2 سال پیش', $d->diffForHumans());
     $d = IntlCarbon::now()->addSecond();
     $this->assertSame('1 ثانیه بعد', $d->diffForHumans());
     $d = IntlCarbon::now()->addSecond();
     $d2 = IntlCarbon::now();
     $this->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2));
     $this->assertSame('1 ثانیه پس از', $d2->diffForHumans($d));
     $d = IntlCarbon::now()->addSecond();
     $d2 = IntlCarbon::now();
     $this->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2));
     $this->assertSame('1 ثانیه پس از', $d2->diffForHumans($d));
     $this->assertSame('1 ثانیه', $d->diffForHumans($d2, true));
     $this->assertSame('2 ثانیه', $d2->diffForHumans($d->addSecond(), true));
 }
Ejemplo n.º 8
0
 public function testMaxIsFluid()
 {
     $dt = IntlCarbon::now();
     $this->assertTrue($dt->max() instanceof IntlCarbon);
 }
Ejemplo n.º 9
0
 public function testCreateWithDefaults()
 {
     $d = IntlCarbon::create();
     $this->assertSame($d->timestamp, IntlCarbon::now()->timestamp);
 }
Ejemplo n.º 10
0
 public function testIsPastFalse()
 {
     $this->assertFalse(IntlCarbon::now()->addSecond()->isPast());
     $this->assertFalse(IntlCarbon::now()->isPast());
 }
Ejemplo n.º 11
0
 public function testFluidTimestampSetter()
 {
     $d = IntlCarbon::now();
     $this->assertTrue($d->timestamp(10) instanceof IntlCarbon);
     $this->assertSame(10, $d->timestamp);
 }
 public function testAddWithNegativeDiffDateInterval()
 {
     $diff = IntlCarbon::now()->diff(IntlCarbon::now()->subWeeks(3));
     $ci = CarbonInterval::create(4, 3, 6, 7, 8, 10, 11)->add($diff);
     $this->assertCarbonInterval($ci, 4, 3, 28, 8, 10, 11);
 }
Ejemplo n.º 13
0
 public function testNowWithTestValueSet()
 {
     $notNow = IntlCarbon::yesterday();
     IntlCarbon::setTestNow($notNow);
     $this->assertEquals($notNow, IntlCarbon::now());
 }
Ejemplo n.º 14
0
 public function testAverageIsFluid()
 {
     $dt = IntlCarbon::now()->average();
     $this->assertTrue($dt instanceof IntlCarbon);
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testInstanceWithDaysThrowsException()
 {
     $ci = CarbonInterval::instance(IntlCarbon::now()->diff(IntlCarbon::now()->addWeeks(3)));
 }
Ejemplo n.º 16
0
 public function testDiffForHumansAbsoluteYears()
 {
     $d = IntlCarbon::now()->subYears(1);
     $this->assertSame('1 year', IntlCarbon::now()->diffForHumans($d, true));
     $d = IntlCarbon::now()->addYears(1);
     $this->assertSame('1 year', IntlCarbon::now()->diffForHumans($d, true));
 }