本文整理汇总了PHP中DateRange类的典型用法代码示例。如果您正苦于以下问题:PHP DateRange类的具体用法?PHP DateRange怎么用?PHP DateRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFilterInvalidValue
public function testFilterInvalidValue()
{
$from = new \DateTime('2010-10-10 06:00:00');
$to = new \DateTime('2010-10-12 08:30:00');
$filter = new DateRange($from, $to);
$this->assertFalse($filter->apply('foo'));
}
示例2: __construct
public function __construct(Date $base, $weekStart = Timestamp::WEEKDAY_MONDAY)
{
$firstDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-01');
$lastDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-' . date('t', $base->toStamp()));
$start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
$end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
$this->monthRange = DateRange::create()->lazySet($firstDayOfMonth, $lastDayOfMonth);
$this->fullRange = DateRange::create()->lazySet($start, $end);
$rawDays = $this->fullRange->split();
$this->fullLength = 0;
foreach ($rawDays as $rawDay) {
$day = CalendarDay::create($rawDay->toStamp());
if ($this->monthRange->contains($day)) {
$day->setOutside(false);
} else {
$day->setOutside(true);
}
$this->days[$day->toDate()] = $day;
$weekNumber = floor($this->fullLength / 7);
if (!isset($this->weeks[$weekNumber])) {
$this->weeks[$weekNumber] = CalendarWeek::create();
}
$this->weeks[$weekNumber]->addDay($day);
++$this->fullLength;
}
++$this->fullLength;
}
示例3: testCreatingNewSeriesSetsAllSharedDataAndCreatesInstances
public function testCreatingNewSeriesSetsAllSharedDataAndCreatesInstances()
{
$userId = 32;
$resourceId = 10;
$title = 'Title';
$description = 'some long decription';
$tz = 'America/Chicago';
$userSession = new FakeUserSession();
$startDateCst = '2010-02-02 12:15';
$endDateCst = '2010-02-04 17:15';
$startDateUtc = Date::Parse($startDateCst, $tz)->ToUtc();
$endDateUtc = Date::Parse($endDateCst, $tz)->ToUtc();
$dateRange = DateRange::Create($startDateCst, $endDateCst, $tz);
$repeatedDate = DateRange::Create('2010-01-01', '2010-01-02', 'UTC');
$repeatOptions = $this->getMock('IRepeatOptions');
$repeatDates = array($repeatedDate);
$repeatOptions->expects($this->once())->method('GetDates')->with($this->equalTo($dateRange->ToTimezone($userSession->Timezone)))->will($this->returnValue($repeatDates));
$resource = new FakeBookableResource($resourceId);
$series = ReservationSeries::Create($userId, $resource, $title, $description, $dateRange, $repeatOptions, $userSession);
$this->assertEquals($userId, $series->UserId());
$this->assertEquals($resource, $series->Resource());
$this->assertEquals($title, $series->Title());
$this->assertEquals($description, $series->Description());
$this->assertTrue($series->IsRecurring());
$this->assertEquals($repeatOptions, $series->RepeatOptions());
$instances = array_values($series->Instances());
$this->assertEquals(count($repeatDates) + 1, count($instances), "should have original plus instances");
$this->assertTrue($startDateUtc->Equals($instances[0]->StartDate()));
$this->assertTrue($endDateUtc->Equals($instances[0]->EndDate()));
$this->assertTrue($repeatedDate->GetBegin()->Equals($instances[1]->StartDate()));
$this->assertTrue($repeatedDate->GetEnd()->Equals($instances[1]->EndDate()));
}
示例4: getCurrentRange
public static function getCurrentRange()
{
$result = Db::getInstance()->getRow('
SELECT `id_date_range`, `time_end`
FROM `' . _DB_PREFIX_ . 'date_range`
WHERE `time_end` = (SELECT MAX(`time_end`) FROM `' . _DB_PREFIX_ . 'date_range`)');
if (!$result['id_date_range'] || strtotime($result['time_end']) < strtotime(date('Y-m-d H:i:s'))) {
// The default range is set to 1 day less 1 second (in seconds)
$rangeSize = 86399;
$dateRange = new DateRange();
$dateRange->time_start = date('Y-m-d');
$dateRange->time_end = strftime('%Y-%m-%d %H:%M:%S', strtotime($dateRange->time_start) + $rangeSize);
$dateRange->add();
return $dateRange->id;
}
return $result['id_date_range'];
}
示例5: makeDatesListByRange
public static function makeDatesListByRange(DateRange $range, IntervalUnit $unit, $hash = true)
{
$date = $unit->truncate($range->getStart());
if ('Date' == get_class($range->getStart())) {
$date = Date::create($date->toStamp());
}
$dates = array();
do {
if ($hash) {
$dates[$date->toString()] = $date;
} else {
$dates[] = $date;
}
$date = $date->spawn('+ 1' . $unit->getName());
} while ($range->getEnd()->toStamp() >= $date->toStamp());
return $dates;
}
示例6: getMutatedValues
/**
* @return array Mutates the filter values so that it is readily prepared for processing.
*/
public function getMutatedValues()
{
$operator = head($this->values);
$dates = explode(' - ', last($this->values));
switch ($operator) {
case 'before':
return [DateRange::before(Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->startOfDay())];
case 'in':
return [new DateRange(Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->subDay()->endOfDay(), Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->addDay()->startOfDay())];
case 'not_in':
return [new DateRange(Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->addDay()->startOfDay(), Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->subDay()->endOfDay())];
case 'after':
return [DateRange::after(Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->endOfDay())];
}
}
示例7: setPageViewed
public static function setPageViewed($id_page)
{
$id_date_range = DateRange::getCurrentRange();
// Try to increment the visits counter
Db::getInstance()->Execute('
UPDATE `' . _DB_PREFIX_ . 'page_viewed`
SET `counter` = `counter` + 1
WHERE `id_date_range` = ' . intval($id_date_range) . '
AND `id_page` = ' . intval($id_page));
// If no one has seen the page in this date range, it is added
if (Db::getInstance()->Affected_Rows() == 0) {
Db::getInstance()->Execute('
INSERT INTO `' . _DB_PREFIX_ . 'page_viewed` (`id_date_range`,`id_page`,`counter`)
VALUES (' . intval($id_date_range) . ',' . intval($id_page) . ',1)');
}
}
示例8: setPageViewed
public static function setPageViewed($id_page)
{
$id_date_range = DateRange::getCurrentRange();
$context = Context::getContext();
// Try to increment the visits counter
$sql = 'UPDATE `' . _DB_PREFIX_ . 'page_viewed`
SET `counter` = `counter` + 1
WHERE `id_date_range` = ' . (int) $id_date_range . '
AND `id_page` = ' . (int) $id_page . '
AND `id_shop` = ' . (int) $context->shop->id;
Db::getInstance()->execute($sql);
// If no one has seen the page in this date range, it is added
if (Db::getInstance()->Affected_Rows() == 0) {
Db::getInstance()->insert('page_viewed', array('id_date_range' => (int) $id_date_range, 'id_page' => (int) $id_page, 'counter' => 1, 'id_shop' => (int) $context->shop->id, 'id_shop_group' => (int) $context->shop->id_shop_group));
}
}
示例9: testConflictsIfResourceReservationExistsAtSameTime
public function testConflictsIfResourceReservationExistsAtSameTime()
{
$resourceId = 1;
$currentId = 19;
$currentDate = new DateRange(Date::Now()->AddDays(10), Date::Now()->AddDays(15));
$current = new TestReservation('ref', $currentDate);
$current->SetReservationId($currentId);
$series = new ExistingReservationSeries();
$series->WithPrimaryResource(new FakeBookableResource($resourceId));
$series->WithResource(new FakeBookableResource($resourceId + 1));
$series->WithCurrentInstance($current);
$reservations = array(new TestReservationItemView($currentId + 1, $currentDate->GetBegin(), $currentDate->GetEnd(), $resourceId));
$this->strategy->expects($this->once())->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue($reservations));
$rule = new ExistingResourceAvailabilityRule($this->strategy, $this->timezone);
$ruleResult = $rule->Validate($series);
$this->assertFalse($ruleResult->IsValid());
}
示例10: GetReservations
public function GetReservations(DateRange $dateRangeUtc, $scheduleId, $targetTimezone)
{
$reservationListing = $this->_coordinatorFactory->CreateReservationListing($targetTimezone);
$reservations = $this->_repository->GetReservationList($dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd(), null, null, $scheduleId, null);
Log::Debug("Found %s reservations for schedule %s between %s and %s", count($reservations), $scheduleId, $dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd());
foreach ($reservations as $reservation) {
$reservationListing->Add($reservation);
}
$blackouts = $this->_repository->GetBlackoutsWithin($dateRangeUtc, $scheduleId);
Log::Debug("Found %s blackouts for schedule %s between %s and %s", count($blackouts), $scheduleId, $dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd());
foreach ($blackouts as $blackout) {
$reservationListing->AddBlackout($blackout);
}
return $reservationListing;
}
示例11: setDate
public function setDate($val)
{
if ($val == "0000-00-00 in press") {
//handle non dates
$val = "";
}
$this["published"] = trim($val) == "" ? "in press" : $val;
//we can't really reliably determine this, we should also store it as text
if (empty($val)) {
return $this->published_at = null;
}
if (preg_match("/^\\d{4}\$/", $val)) {
//strtotime can't handle YYYY
$val = "Jan 1, " . $val;
}
$range = DateRange::parseString($val);
if (isset($range)) {
//try date range
return $this->published_at = DTStore::date($range->getStartDate());
} else {
if (strtotime($val) !== false) {
//try regular parse
return $this->published_at = DTStore::date(strtotime($val));
} else {
if (preg_match("/(\\d{4})/", $val, $matches)) {
//try just a year
return $this->published_at = DTSTore::date(strtotime("Jan 1, " . $matches[1]));
} else {
return $this->published_at = null;
}
}
}
//give up
}
示例12: startsBefore
/**
* Does another range start before this one does?
*
* @param DateRange $other_range
* @return bool True if the other range starts before this one.
*/
function startsBefore($other_range)
{
$this_start = $this->getStartDate();
$other_start = $other_range->getStartDate();
return $this_start->before($other_start);
}
示例13: testLoadsExistingReservationAndUpdatesData
public function testLoadsExistingReservationAndUpdatesData()
{
$seriesId = 109809;
$expectedSeries = new ExistingReservationSeries();
$currentDuration = new DateRange(Date::Now()->AddDays(1), Date::Now()->AddDays(2), 'UTC');
$removedResourceId = 190;
$resource = new FakeBookableResource(1);
$additionalId1 = $this->page->resourceIds[0];
$additionalId2 = $this->page->resourceIds[1];
$additional1 = new FakeBookableResource($additionalId1);
$additional2 = new FakeBookableResource($additionalId2);
$reservation = new Reservation($expectedSeries, $currentDuration);
$expectedSeries->WithId($seriesId);
$expectedSeries->WithCurrentInstance($reservation);
$expectedSeries->WithPrimaryResource($resource);
$expectedSeries->WithResource(new FakeBookableResource($removedResourceId));
$expectedSeries->WithAttribute(new AttributeValue(100, 'to be removed'));
$referenceNumber = $this->page->existingReferenceNumber;
$timezone = $this->user->Timezone;
$this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries));
$this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->page->resourceId))->will($this->returnValue($resource));
$this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalId1))->will($this->returnValue($additional1));
$this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalId2))->will($this->returnValue($additional2));
$this->page->repeatType = RepeatType::Daily;
$roFactory = new RepeatOptionsFactory();
$repeatOptions = $roFactory->CreateFromComposite($this->page, $this->user->Timezone);
$expectedDuration = DateRange::Create($this->page->GetStartDate() . " " . $this->page->GetStartTime(), $this->page->GetEndDate() . " " . $this->page->GetEndTime(), $timezone);
$attachment = new FakeUploadedFile();
$this->page->attachment = $attachment;
$this->page->hasEndReminder = false;
$existingSeries = $this->presenter->BuildReservation();
$expectedAccessories = array(new ReservationAccessory(1, 2, 'accessoryname'));
$expectedAttributes = array(1 => new AttributeValue(1, 'something'));
$this->assertEquals($seriesId, $existingSeries->SeriesId());
$this->assertEquals($this->page->seriesUpdateScope, $existingSeries->SeriesUpdateScope());
$this->assertEquals($this->page->title, $existingSeries->Title());
$this->assertEquals($this->page->description, $existingSeries->Description());
$this->assertEquals($this->page->userId, $existingSeries->UserId());
$this->assertEquals($resource, $existingSeries->Resource());
$this->assertEquals($repeatOptions, $existingSeries->RepeatOptions());
$this->assertEquals(array($additional1, $additional2), $existingSeries->AdditionalResources());
$this->assertEquals($this->page->participants, $existingSeries->CurrentInstance()->AddedParticipants());
$this->assertEquals($this->page->invitees, $existingSeries->CurrentInstance()->AddedInvitees());
$this->assertTrue($expectedDuration->Equals($existingSeries->CurrentInstance()->Duration()), "Expected: {$expectedDuration} Actual: {$existingSeries->CurrentInstance()->Duration()}");
$this->assertEquals($this->user, $expectedSeries->BookedBy());
$this->assertEquals($expectedAccessories, $existingSeries->Accessories());
$this->assertEquals($expectedAttributes, $existingSeries->AttributeValues());
$expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $seriesId);
$this->assertEquals(array($expectedAttachment), $expectedSeries->AddedAttachments());
$this->assertEquals($this->page->removedFileIds, $existingSeries->RemovedAttachmentIds());
$this->assertEquals(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()), $existingSeries->GetStartReminder());
$this->assertEquals(ReservationReminder::None(), $existingSeries->GetEndReminder());
}
示例14: SetReservationDate
public function SetReservationDate(DateRange $reservationDate)
{
$this->startDate = $reservationDate->GetBegin();
$this->endDate = $reservationDate->GetEnd();
}
示例15: renderDateInput
/**
* Renders date input
* @param $name
* @param DateRange|null $range
* @return string
*/
public function renderDateInput($name, DateRange $range = null)
{
return $this->renderTag('input', array('type' => 'text', 'name' => $name, 'id' => $this->generateId($name), 'class' => 'datepicker-field', 'value' => $range ? $this->formatDateValue($range->getMinDate()) : null));
}