本文整理汇总了PHP中Carbon\Carbon::setTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::setTimestamp方法的具体用法?PHP Carbon::setTimestamp怎么用?PHP Carbon::setTimestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::setTimestamp方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Execute
public function Execute()
{
$conn = \ZCL\DB\DB::getConnect();
$store_id = $this->headerdata['store_id'];
$item = \ZippyERP\ERP\Entity\Item::getSumItem();
$stock = \ZippyERP\ERP\Entity\Stock::getStock($store_id, $item->item_id, 1, true);
$discont = 0;
//скидки 704 счет
$date = new Carbon();
$date->setTimestamp($this->document_date);
$end = $date->endOfMonth()->getTimestamp();
$begin = $date->startOfMonth()->getTimestamp();
$sql = " select coalesce(abs(sum(amount)),0) from erp_account_subconto where amount < 0 and account_id=285 and extcode = {$store_id} and document_date <= " . $conn->DBDate($end);
$tm = $conn->GetOne($sql);
//торговая наценка на конец периода
//остатки на конец периода
$sql = " select coalesce(sum(quantity),0) AS quantity,coalesce(price,0) as price from erp_account_subconto sc join erp_store_stock st on sc.stock_id = st.stock_id where store_id = {$store_id} and date(document_date) <= " . $conn->DBDate($end);
$row = $conn->GetRow($sql);
$ost = $row['quantity'] / 1000;
$ost = $ost * $row['price'];
if ($ost == 0) {
return;
}
//выручка
$sql = " select coalesce(abs(sum(amount)),0) from erp_account_subconto where amount < 0 and account_id=702 and extcode = {$store_id} and date(document_date) <= " . $conn->DBDate($end) . " and date(document_date) >= " . $conn->DBDate($begin);
$saled = $conn->GetOne($sql);
//выручка сданная в кассу
$k = ($tm - $discont) / ($ost - $discont);
$sb = (1 - $k) * $saled;
//себестоимость
// списываем наценку
Entry::AddEntry("285", "282", $saled - $sb, $this->document_id, $this->document_date);
// себестоимость реализации
Entry::AddEntry("902", "282", $sb, $this->document_id, $this->document_date);
$item = \ZippyERP\ERP\Entity\Item::getSumItem();
$stockto = \ZippyERP\ERP\Entity\Stock::getStock($store_id, $item->item_id, 1, true);
$sc = new SubConto($this, 282, 0 - $saled);
$sc->setStock($stockto->stock_id);
$sc->setQuantity(0 - $saled * 1000);
//цена единицы товара - 1 копейка.
$sc->save();
// НДС
$nds = H::nds(true);
Entry::AddEntry("702", "641", $saled * $nds, $this->document_id, $this->document_date);
return true;
}
示例2: getBetweenTimes
public static function getBetweenTimes($month)
{
$startTime = new Carbon();
$startTime->setTimestamp(strtotime($month));
$endTime = clone $startTime;
$endTime->addMonth();
return [$startTime, $endTime];
}
示例3: get_all
public function get_all()
{
$this->db->select("type");
$this->db->from("widgets");
$q = $this->db->get();
$fileList = array_unique(array_values(array_flatten($q->result_array())));
foreach ($fileList as $file) {
$path = $_SERVER["DOCUMENT_ROOT"] . "/application/views/widgets/" . $file . ".php";
if (file_exists($path)) {
$mtime = filemtime($path);
$files[] = array("type" => $file, "mtime" => $mtime);
}
}
$query = $this->db->query("SELECT widgets.`type`, page.`title`, page.`slug`, `page_ID` FROM widgets JOIN (SELECT pages.`title`, pages.`ID`, pages.`slug` FROM pages GROUP BY pages.`title`) AS page ON widgets.`page_ID` = page.`ID` GROUP BY widgets.`type`");
$pages = $query->result_array();
$records = array();
foreach ($files as $file) {
foreach ($pages as $page) {
if ($file["type"] == $page["type"]) {
$date = new Carbon();
$date->setTimestamp($file["mtime"]);
$records[] = array("page_ID" => $page["page_ID"], "type" => $file["type"], "mtime" => $date, "slug" => $page["slug"], "title" => $page["title"]);
}
}
}
$this->sortArray($records, "mtime");
foreach ($records as &$record) {
$weekAgo = Carbon::now()->subWeeks(1);
$mtime = $record["mtime"];
$diff = Carbon::now()->diffForHumans($mtime, true);
$diffDays = Carbon::now()->diffInDays($mtime);
$record = array_merge($record, array("diff" => array("text" => $diff, "days" => $diffDays)));
if ($mtime->gt($weekAgo)) {
// echo $record["title"]." | Last change: $diff ago<br>";
}
}
return $records;
}
示例4: draw_list
/**
* Make a calendar list of events.
*
* Outputs a list of events according to events for the specified range.
*
* @since 3.0.0
* @access private
*
* @param int $timestamp
* @param int $id
*
* @return string
*/
private function draw_list($timestamp, $id = 0)
{
$calendar = $this->calendar;
if (empty($calendar)) {
$calendar = $this->calendar = simcal_get_calendar(intval($id));
if (!$calendar instanceof Default_Calendar) {
return '';
}
}
date_default_timezone_set($calendar->timezone);
$now = $calendar->now;
$current_events = $this->get_events($timestamp);
$day_format = explode(' ', $calendar->date_format);
ob_start();
// Draw the events.
$block_tag = $calendar->compact_list && !empty($current_events) ? 'div' : 'dl';
$data_heading = '';
$heading = $this->get_heading();
foreach ($heading as $k => $v) {
$data_heading .= ' data-heading-' . $k . '="' . $v . '"';
}
echo '<' . $block_tag . ' class="simcal-events-list-container"' . ' data-prev="' . $this->prev . '"' . ' data-next="' . $this->next . '"' . $data_heading . '>';
if (!empty($current_events) && is_array($current_events)) {
foreach ($current_events as $ymd => $events) {
$day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp();
if (!$calendar->compact_list) {
$date = new Carbon('now', $calendar->timezone);
$date->setLocale(substr(get_locale(), 0, 2));
$date->setTimestamp($day_ts);
if ($date->isToday()) {
$the_color = new Color($calendar->today_color);
} else {
$the_color = new Color($calendar->days_events_color);
}
$bg_color = '#' . $the_color->getHex();
$color = $the_color->isDark() ? '#ffffff' : '#000000';
$border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" ';
$bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"';
echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>';
echo '<span' . $bg_style . '>';
foreach ($day_format as $format) {
echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n($format, $day_ts) . '</span> ' : ' ';
}
echo '</span>';
echo '</dt>' . "\n";
}
$list_events = '<ul class="simcal-events">' . "\n";
$calendar_classes = array();
$day_classes = 'simcal-weekday-' . date('w', $day_ts);
// Is this the present, the past or the future, Doc?
if ($timestamp <= $now && $timestamp >= $now) {
$day_classes .= ' simcal-today simcal-present simcal-day';
} elseif ($timestamp < $now) {
$day_classes .= ' simcal-past simcal-day';
} elseif ($this->end > $now) {
$day_classes .= ' simcal-future simcal-day';
}
$count = 0;
foreach ($events as $day_events) {
foreach ($day_events as $event) {
if ($event instanceof Event) {
$event_classes = $event_visibility = '';
$calendar_class = 'simcal-events-calendar-' . strval($event->calendar);
$calendar_classes[] = $calendar_class;
$recurring = $event->recurrence ? 'simcal-event-recurring ' : '';
$has_location = $event->venue ? 'simcal-event-has-location ' : '';
$event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class;
// Toggle some events visibility if more than optional limit.
if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) {
$event_classes .= ' simcal-event-toggled';
$event_visibility = ' style="display: none"';
}
$event_color = '';
$bullet = '';
$event_color = $event->get_color();
if (!empty($event_color)) {
$side = is_rtl() ? 'right' : 'left';
$event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"';
}
$list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemprop="event" itemscope itemtype="http://schema.org/Event">' . "\n";
$list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html($event) . '</div>' . "\n";
$list_events .= "\t" . '</li>' . "\n";
$count++;
// Event falls within today.
if ($this->end <= $now && $this->start >= $now) {
$day_classes .= ' simcal-today-has-events';
}
//.........这里部分代码省略.........
示例5: asDateTime
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return \Carbon\Carbon
*/
protected function asDateTime($value)
{
// If the value is already a Carbon instance, we will just skip the rest of
// these checks since they will be a waste of time, and hinder performance
// when checking the field. We will just return the Carbon right away.
if ($value instanceof Carbon) {
//
} elseif (is_numeric($value)) {
$date = new Carbon();
return $date->setTimestamp($value);
} elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
return Carbon::createFromFormat('Y-m-d', $value);
} elseif (preg_match('/^(\\d{2}):(\\d{2}):(\\d{2})$/', $value)) {
return Carbon::createFromFormat('H:i:s', $value);
} elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})Z$/', $value)) {
return Carbon::createFromFormat('Y-m-d\\TH:i:s\\Z', $value);
}
return new Carbon($value->format('Y-m-d H:i:s.u'), $value->getTimeZone());
}
示例6: get_events
/**
* Get events for current display.
*
* @since 3.0.0
* @access private
*
* @param int $timestamp
*
* @return array
*/
private function get_events($timestamp)
{
$calendar = $this->calendar;
if (!$calendar->group_type || !$calendar->group_span) {
return array();
}
// Need to pass in timezone here to get beginning of day.
$current = Carbon::createFromTimestamp($timestamp, $calendar->timezone);
$prev = clone $current;
$next = clone $current;
$this->start = $timestamp;
$interval = $span = max(absint($calendar->group_span), 1);
if ('monthly' == $calendar->group_type) {
$this->prev = $prev->subMonths($span)->getTimestamp();
$this->next = $next->addMonths($span)->getTimestamp();
} elseif ('weekly' == $calendar->group_type) {
$week = new Carbon($calendar->timezone);
$week->setTimestamp($timestamp);
$week->setWeekStartsAt($calendar->week_starts);
$this->prev = $prev->subWeeks($span)->getTimestamp();
$this->next = $next->addWeeks($span)->getTimestamp();
} elseif ('daily' == $calendar->group_type) {
$this->prev = $prev->subDays($span)->getTimestamp();
$this->next = $next->addDays($span)->getTimestamp();
}
$events = $calendar->events;
$daily_events = $paged_events = $flattened_events = array();
if ('events' != $calendar->group_type) {
$this->end = $this->next - 1;
$timestamps = array_keys($events);
$lower_bound = array_filter($timestamps, array($this, 'filter_events_before'));
$higher_bound = array_filter($lower_bound, array($this, 'filter_events_after'));
if (is_array($higher_bound) && !empty($higher_bound)) {
$filtered = array_intersect_key($events, array_combine($higher_bound, $higher_bound));
foreach ($filtered as $timestamp => $events) {
$paged_events[intval($timestamp)] = $events;
}
}
} else {
foreach ($events as $timestamp => $e) {
$second = 0;
foreach ($e as $event) {
$flattened_events[intval($timestamp + $second)][] = $event;
$second++;
}
}
ksort($flattened_events, SORT_NUMERIC);
$keys = array_keys($flattened_events);
$current = 0;
foreach ($keys as $timestamp) {
if ($timestamp < $this->start) {
$current++;
}
}
$paged_events = array_slice($flattened_events, $current, $interval, true);
$events_end = isset($keys[$current + $interval]) ? $keys[$current + $interval] : $calendar->end;
$this->end = $events_end > $calendar->end ? $calendar->end : $events_end;
$this->prev = isset($keys[$current - $interval]) ? $keys[$current - $interval] : $calendar->earliest_event;
$this->next = isset($keys[$current + $interval]) ? $keys[$current + $interval] : $this->end;
}
// Put resulting events in an associative array, with Ymd date as key for easy retrieval in calendar days loop.
foreach ($paged_events as $timestamp => $events) {
// TODO First $paged_events item timestamp 1 second off? Plus or minus?
if ($timestamp <= $this->end) {
// TODO Could go back to using Carbon to be consistent.
// $date is off by a couple hours for dates in multi-day event, but not for first event.
// But only certain timezones? UTC-1, UTC+1, UTC+2, UTC+3 ???
// Offset changes after first day with these timezones only. Why?
// November 1, 2016 is daylight savings for them!!!
/*
$date = Carbon::createFromTimestamp( $timestamp, $calendar->timezone );
// Add date offset back in?
// $date = Carbon::createFromTimestamp( $timestamp + $date->offset, $calendar->timezone );
$dateYmd = $date->copy()->endOfDay()->format( 'Ymd' );
*/
// Using native PHP 5.3+ (not Carbon) here.
// Offset value after first day same behavior as Carbon above still.
$dtz = new \DateTimeZone($calendar->timezone);
$date = \DateTime::createFromFormat('U', $timestamp);
// Doesn't seem to make a difference omitting timezone.
//$date = \DateTime::createFromFormat( 'U', $timestamp, $dtz );
// Add offset to timestamp to get correct date.
// TODO Need to add +1 second also?
$offset = $dtz->getOffset($date);
$date_offset = clone $date;
$date_offset->add(\DateInterval::createFromDateString($offset . ' seconds'));
// TODO Multiple day events will be off if part-way through there's daylight savings.
$dateYmd = $date_offset->format('Ymd');
//.........这里部分代码省略.........