public function testInstanceFromDateTimeKeepsMicros() { $micro = 254687; $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro); $IntlCarbon = IntlCarbon::instance($datetime); $this->assertSame($micro, $IntlCarbon->micro); }
public function testCopyEnsureMicrosAreCopied() { $micro = 254687; $dating = IntlCarbon::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro); $dating2 = $dating->copy(); $this->assertSame($micro, $dating2->micro); }
public function testIssetReturnTrueForProperties() { $properties = array('year', 'month', 'day', 'hour', 'minute', 'second', 'dayOfWeek', 'dayOfYear', 'daysInMonth', 'timestamp', 'age', 'quarter', 'dst', 'offset', 'offsetHours', 'timezone', 'timezoneName', 'tz', 'tzName'); foreach ($properties as $property) { $this->assertTrue(isset(IntlCarbon::create(1234, 5, 6, 7, 8, 9)->{$property})); } }
public function testParseSettingTimezoneWithString() { $timezone = 'Asia/Tokyo'; $dtz = new \DateTimeZone($timezone); $dt = new \DateTime('now', $dtz); $dayLightSavingTimeOffset = $dt->format('I'); $c = IntlCarbon::parse('now', $timezone); $this->assertSame($timezone, $c->tzName); $this->assertSame(9 + $dayLightSavingTimeOffset, $c->offsetHours); }
public function testSecondsUntilEndOfDay() { $d = IntlCarbon::today()->endOfDay(); $this->assertSame(0, $d->secondsUntilEndOfDay()); $d = IntlCarbon::today()->endOfDay()->subSeconds(60); $this->assertSame(60, $d->secondsUntilEndOfDay()); $d = IntlCarbon::create(2014, 10, 24, 12, 34, 56); $this->assertSame(41103, $d->secondsUntilEndOfDay()); $d = IntlCarbon::create(2014, 10, 24, 0, 0, 0); $this->assertSame(86399, $d->secondsUntilEndOfDay()); }
public function testCreateFromFormatWithMillis() { $d = IntlCarbon::createFromFormat('Y-m-d H:i:s.u', '1975-05-21 22:32:11.254687'); $this->assertSame(254687, $d->micro); }
public function test3rdWednesdayOfYear() { $d = IntlCarbon::createFromDate(1975, 8, 5)->nthOfYear(3, 3); $this->assertIntlCarbon($d, 1975, 1, 15, 0, 0, 0); }
public function testCreateFromTimestampGMTDoesNotUseDefaultTimezone() { $d = IntlCarbon::createFromTimestampUTC(0); $this->assertIntlCarbon($d, 1970, 1, 1, 0, 0, 0); $this->assertSame(0, $d->offset); }
public function testInvalidGetter() { $this->setExpectedException('InvalidArgumentException'); $d = IntlCarbon::now(); $bb = $d->doesNotExit; }
/** * @param DateTime $datetime * @return IntlCalendar */ protected function getCalendarFromDateTime($datetime) { $calendar = $this->getCalendarObject(); // $c = IntlCarbon::createFromTimestamp($datetime->format('U'),$datetime->getTimezone()); // $c->setCalendar($calendar->getType()); $c = IntlCarbon::instance($datetime); // var_dump($c); // var_dump($datetime); // $calendar->setTime($datetime->format('U')); // $calendar->set($datetime->format('Y'), $datetime->format('n') - 1, $datetime->format('d'), // $datetime->format('G'), $datetime->format('i'), $datetime->format('s')); $calendar->set($c->format('Y'), $c->format('n') - 1, $c->format('d'), $c->format('G'), $c->format('i'), $c->format('s')); return $calendar; }
public function testTimeZoneWithTestValueSet() { $notNow = IntlCarbon::parse('2013-07-01 12:00:00', 'America/New_York'); IntlCarbon::setTestNow($notNow); $this->assertSame('2013-07-01T12:00:00-0400', IntlCarbon::parse('now')->toIso8601String()); $this->assertSame('2013-07-01T11:00:00-0500', IntlCarbon::parse('now', 'America/Mexico_City')->toIso8601String()); $this->assertSame('2013-07-01T09:00:00-0700', IntlCarbon::parse('now', 'America/Vancouver')->toIso8601String()); }
public function testAverageFromLower() { $dt1 = IntlCarbon::create(2009, 12, 31, 23, 59, 59); $dt2 = IntlCarbon::create(2000, 1, 1, 1, 1, 1)->average($dt1); $this->assertIntlCarbon($dt2, 2004, 12, 31, 12, 30, 30); }
public function testCreateFromDateWithDateTimeZone() { $d = IntlCarbon::createFromDate(1975, 5, 21, new \DateTimeZone('Europe/London')); $this->assertIntlCarbon($d, 1975, 5, 21); $this->assertSame('Europe/London', $d->tzName); }
public function testToW3cString() { $d = IntlCarbon::create(1975, 12, 25, 14, 15, 16); $this->assertSame('1975-12-25T14:15:16-05:00', $d->toW3cString()); }
/** * @expectedException InvalidArgumentException */ public function testInstanceWithDaysThrowsException() { $ci = CarbonInterval::instance(IntlCarbon::now()->diff(IntlCarbon::now()->addWeeks(3))); }
public function testIsBirthday() { $dt1 = IntlCarbon::createFromDate(1987, 4, 23); $dt2 = IntlCarbon::createFromDate(2014, 9, 26); $dt3 = IntlCarbon::createFromDate(2014, 4, 23); $this->assertFalse($dt2->isBirthday($dt1)); $this->assertTrue($dt3->isBirthday($dt1)); }
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); }
public function testFluidTimestampSetter() { $d = IntlCarbon::now(); $this->assertTrue($d->timestamp(10) instanceof IntlCarbon); $this->assertSame(10, $d->timestamp); }
public function testIsSameDayFalse() { $current = IntlCarbon::createFromDate(2012, 1, 2); $this->assertFalse($current->isSameDay(IntlCarbon::createFromDate(2012, 1, 3))); }
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)); }
public function testCreateWithTimeZoneString() { $d = IntlCarbon::create(2012, 1, 1, 0, 0, 0, 'Europe/London'); $this->assertIntlCarbon($d, 2012, 1, 1, 0, 0, 0); $this->assertSame('Europe/London', $d->tzName); }
public function testAddSecondPassingArg() { $this->assertSame(2, IntlCarbon::createFromTime(0)->addSecond(2)->second); }
/** * @param DateTime $datetime * @return IntlCalendar */ protected function getCalendarFromDateTime($datetime) { $calendar = $this->getCalendarObject(); $c = IntlCarbon::instance($datetime); $calendar->set($c->format('Y'), $c->format('n') - 1, $c->format('d'), $c->format('G'), $c->format('i'), $c->format('s')); return $calendar; }
public function testMaxValue() { $this->assertGreaterThanOrEqual(2147483647, IntlCarbon::maxValue()->getTimestamp()); }
/** * Get the difference by the given interval using a filter closure * * @param CarbonInterval $ci An interval to traverse by * @param Closure $callback * @param Carbon $dt * @param boolean $abs Get the absolute of the difference * * @return int */ public function diffFiltered(CarbonInterval $ci, Closure $callback, IntlCarbon $dt = null, $abs = true) { $start = $this; $end = $dt === null ? static::now($this->tz) : $dt; $inverse = false; if ($end < $start) { $start = $end; $end = $this; $inverse = true; } $period = new DatePeriod($start, $ci, $end); $vals = array_filter(iterator_to_array($period), function (DateTime $date) use($callback) { return call_user_func($callback, IntlCarbon::instance($date)); }); $diff = count($vals); return $inverse && !$abs ? -$diff : $diff; }
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 testDiffForHumansWithShorterMonthShouldStillBeAMonth() { $feb15 = IntlCarbon::parse('2015-02-15'); $mar15 = IntlCarbon::parse('2015-03-15'); $this->assertSame('1 month after', $mar15->diffForHumans($feb15)); }