本文整理汇总了PHP中DateTimeHelper类的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeHelper类的具体用法?PHP DateTimeHelper怎么用?PHP DateTimeHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTimeHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria();
if (isset($_GET["Audit"])) {
$dH = new DateTimeHelper();
$dtFrom = $dH->getDateTimeFromUI($_GET["Audit"]["dateTimeFrom"]);
$dtTo = $dH->getDateTimeFromUI($_GET["Audit"]["dateTimeTo"]);
if ($desde !== false) {
$criteria->addCondition('date_time >= ' . $dtFrom->getTimestamp());
} else {
$criteria->addCondition('date_time >= ' . $dH->getDefaultStartRangeFilter("")->getTimestamp());
}
if ($hasta !== false) {
$criteria->addCondition('date_time <= ' . $dtTo->getTimestamp());
} else {
$criteria->addCondition('date_time <= ' . $dH->getDefaultEndRangeFilter("audit")->getTimestamp());
}
}
$criteria->compare('object', $this->object, true);
$criteria->compare('operation', $this->operation, true);
$criteria->compare('description', $this->description, true);
$criteria->compare('user', $this->user, true);
return new CActiveDataProvider($this, array('criteria' => $criteria));
}
示例2: actionCreateEvent
public function actionCreateEvent()
{
$transaction = Yii::app()->db->beginTransaction();
try {
$dU = new DateTimeHelper();
$e = new Event();
$e->title = $_POST['title'];
$e->body = $_POST['body'];
$dt = $dU->getDateTimeFromUI($_POST['end']);
$e->end = $dt->getTimestamp();
$dt = $dU->getDateTimeFromUI($_POST['start']);
$e->start = $dt->getTimestamp();
$e->user_id = Yii::app()->user->id;
if (!$e->save()) {
$transaction->commit();
Response::ok(CJSON::encode(array("result" => "error", "message" => CJSON::encode($e->getErrors()))));
} else {
Response::ok(CJSON::encode(array("result" => "success", "message" => $e->id)));
}
} catch (Exception $exc) {
$transaction->rollback();
Yii::log($exc->getMessage(), DBLog::LOG_LEVEL_ERROR);
Response::error(CJSON::encode(array("result" => "error", "message" => Yii::app()->params["httpErrorCode500Message"])));
}
}
示例3: saveSitemap
/**
* @param SproutSeo_SitemapModel $attributes
*
* @return mixed|null|string
*/
public function saveSitemap(SproutSeo_SitemapModel $attributes)
{
$row = array();
$isNew = false;
if (isset($attributes->id) && substr($attributes->id, 0, 3) === "new") {
$isNew = true;
}
if (!$isNew) {
$row = craft()->db->createCommand()->select('*')->from('sproutseo_sitemap')->where('id=:id', array(':id' => $attributes->id))->queryRow();
}
$model = SproutSeo_SitemapModel::populateModel($row);
$model->id = !$isNew ? $attributes->id : null;
$model->sectionId = isset($attributes->sectionId) ? $attributes->sectionId : null;
$model->url = isset($attributes->url) ? $attributes->url : null;
$model->priority = $attributes->priority;
$model->changeFrequency = $attributes->changeFrequency;
$model->enabled = $attributes->enabled == 'true' ? 1 : 0;
$model->ping = $attributes->ping == 'true' ? 1 : 0;
$model->dateUpdated = DateTimeHelper::currentTimeForDb();
$model->uid = StringHelper::UUID();
if ($isNew) {
$model->dateCreated = DateTimeHelper::currentTimeForDb();
craft()->db->createCommand()->insert('sproutseo_sitemap', $model->getAttributes());
return craft()->db->lastInsertID;
} else {
$result = craft()->db->createCommand()->update('sproutseo_sitemap', $model->getAttributes(), 'id=:id', array(':id' => $model->id));
return $model->id;
}
}
示例4: actionFetchPackageInfo
/**
* Fetches the installed package info from Elliott.
*/
public function actionFetchPackageInfo()
{
$this->requireAjaxRequest();
$etResponse = craft()->et->fetchPackageInfo();
if ($etResponse) {
// Make sure we've got a valid license key (mismatched domain is OK for these purposes)
if ($etResponse->licenseKeyStatus != LicenseKeyStatus::Invalid) {
$packages = $etResponse->data;
// Include which packages are actually licensed
foreach ($etResponse->licensedPackages as $packageName) {
$packages[$packageName]['licensed'] = true;
}
// Include which packages are in trial
foreach ($etResponse->packageTrials as $packageName => $expiryDate) {
$currentTime = DateTimeHelper::currentUTCDateTime();
$diff = $expiryDate - $currentTime->getTimestamp();
$daysLeft = round($diff / 86400);
// 60 * 60 * 24
$packages[$packageName]['trial'] = true;
$packages[$packageName]['daysLeftInTrial'] = $daysLeft;
}
$this->returnJson(array('success' => true, 'packages' => $packages));
} else {
$this->returnErrorJson(Craft::t('Your license key is invalid.'));
}
} else {
$this->returnErrorJson(Craft::t('Craft is unable to fetch package info at this time.'));
}
}
示例5: getTimeTotals
public function getTimeTotals($user_id, $time_range)
{
switch ($time_range) {
case 'overall':
$date_from = null;
$date_to = null;
break;
case 'this_week':
$days = DateTimeHelper::create()->getDaysOfWeek(date('W'), date('Y'));
$date_from = date('Y-m-d 00:00:00', $days[1]);
$date_to = date('Y-m-d 23:59:59', $days[7]);
break;
case 'last_week':
$days = DateTimeHelper::create()->getDaysOfWeek(date('W') - 1, date('Y'));
$date_from = date('Y-m-d 00:00:00', $days[1]);
$date_to = date('Y-m-d 23:59:59', $days[7]);
break;
case 'this_month':
$date_from = date('Y-m-d 00:00:00', mktime(00, 00, 00, date('m'), 01));
$date_to = date('Y-m-d 23:59:59', strtotime($date_from . '+1 MONTH -1 SECOND'));
break;
case 'last_month':
$month = strtotime('last month');
$date_from = date('Y-m-d 00:00:00', mktime(00, 00, 00, date('m', $month), 01));
$date_to = date('Y-m-d 23:59:59', strtotime($date_from . '+1 MONTH -1 SECOND'));
break;
}
$query = Doctrine_Query::create()->select('p.*, i.*, SUM(i.value) as total')->from('Project p')->where('i.user_id=?', $user_id)->innerJoin('p.TimeLogItems i')->groupBy('p.id')->orderBy('p.name');
if ($date_from != null && $date_to != null) {
$query->andWhere('i.itemdate >= ? AND i.itemdate <= ?', array($date_from, $date_to));
}
return $query->execute();
}
示例6: run
public function run()
{
$columnsParameters = array(array('dbField' => 'SupportDiscussionsEntity.idObjet', 'dtField' => 'objet', 'formatter' => function ($d, $row) {
return \SupportObjetsHelper::getLibelle($d);
}), array('dbField' => 'AdminsEntity.name', 'dtField' => 'compte', 'formatter' => function ($d, $row) {
if ($this->isAdmin) {
return $row["user"];
} else {
return $d;
}
}), array('dbField' => 'AccountEntityUser.login', 'dtField' => 'user'), array('dbField' => 'SupportDiscussionsEntity.date', 'dtField' => 'date', 'formatter' => function ($d, $row) {
return \DateTimeHelper::dateTimeToFormatedString($d, "d/m/Y");
}), array('dbField' => 'SupportDiscussionsEntity.dateDernierMessage', 'dtField' => 'lastMessage', 'formatter' => function ($d, $row) {
$firstDate = date("Y-m-d");
$secondDate = $d->format('Y-m-d');
if ($firstDate == $secondDate) {
return \DateTimeHelper::dateTimeToFormatedString($d, "H:i:s");
} else {
return \DateTimeHelper::dateTimeToFormatedString($d);
}
}), array('dbField' => 'SupportMessagesEntity.id', 'dtField' => 'nonLuInDiscussion', 'formatter' => function ($d, $row) {
if ($d === null) {
return "";
} else {
return "lineGreen";
}
}), array('dbField' => 'SupportDiscussionsEntity.id', 'dtField' => 'actions', 'formatter' => function ($d, $row) {
$varButton = '<a class="btn btn-material btn-primary btn-sm" onclick="DiscussionOpen(\'' . \Encryption::encrypt($d) . '\')"><i class="material-icons md-icon-message"></i></a>';
$varButton .= '<a class="btn btn-material btn-warning btn-sm" onclick="DiscussionArchivage(\'' . \Encryption::encrypt($d) . '\', 1)"><i class="material-icons md-icon-archive"></i></a>';
return '<div class="btn-toolbar">' . $varButton . "</div>";
}));
$datatable = new \DataTable();
$datatable->setColumnsParameters($columnsParameters)->setRequest($_GET)->from("\\Site\\Entity\\SupportDiscussions", "SupportDiscussionsEntity")->innerJoin("\\Site\\Entity\\Admins", "AdminsEntity", "WITH", "AdminsEntity.idCompte = SupportDiscussionsEntity.idAdmin")->leftJoin("\\Account\\Entity\\Account", "AccountEntityUser", "WITH", "AccountEntityUser.id = SupportDiscussionsEntity.idCompte")->leftJoin("\\Site\\Entity\\SupportMessages", "SupportMessagesEntity", "WITH", "SupportMessagesEntity.idDiscussion = SupportDiscussionsEntity.id AND SupportMessagesEntity.etat = " . \SupportEtatMessageHelper::NON_LU . " AND SupportMessagesEntity.idCompte != " . $this->objAccount->getId() . "")->andWhere("SupportDiscussionsEntity.idCompte = " . $this->objAccount->getId() . " OR SupportDiscussionsEntity.idAdmin = " . $this->objAccount->getId() . "")->andWhere("SupportDiscussionsEntity.estArchive = 0")->groupBy("SupportDiscussionsEntity.id");
$datatable->getResult()->toJson();
}
示例7: getStatus
/**
* Returns the element's status.
*
* @return string|null
*/
public function getStatus()
{
$currentTime = DateTimeHelper::currentTimeStamp();
$startDate = $this->startDate ? $this->startDate->getTimestamp() : null;
$endDate = $this->endDate ? $this->endDate->getTimestamp() : null;
$pluginSettings = craft()->plugins->getPlugin('maintenance')->pluginSettings;
$interval = $pluginSettings['maintenanceImminent'];
$interval = DateInterval::createFromDateString($interval);
$secondsInAdvance = (new DateTime('@0'))->add($interval)->getTimeStamp();
if (!$startDate) {
return static::NONE;
}
if (!$this->blockCp && !$this->blockSite) {
return static::DISABLED;
} else {
if ($startDate > $currentTime) {
if ($startDate > $currentTime + $secondsInAdvance) {
return static::PENDING;
} else {
return static::IMMINENT;
}
} else {
if ($startDate <= $currentTime && (!$endDate || $endDate > $currentTime)) {
return static::INPROGRESS;
} else {
if ($startDate <= $currentTime) {
return static::COMPLETED;
}
}
}
}
}
示例8: currentTimeForDb
/**
* @static
* @return string
*/
public static function currentTimeForDb()
{
// Eventually this will return the time in the appropriate database format for MySQL, Postgre, etc.
// For now, it's MySQL only.
$date = DateTimeHelper::currentUTCDateTime();
return $date->format(DateTime::MYSQL_DATETIME, DateTime::UTC);
}
示例9: run
public function run()
{
global $request;
$em = \Shared\DoctrineHelper::getEntityManager();
$idCompte = $request->request->get("idCompte");
$idDiscussion = $request->request->get("idDiscussion");
$message = $request->request->get("message");
$objSupportMessage = new \Site\Entity\SupportMessages();
$objSupportMessage->setIdCompte($idCompte);
$objSupportMessage->setIdDiscussion($idDiscussion);
$objSupportMessage->setMessage($message);
$objSupportMessage->setDate(new \DateTime(date("Y-m-d H:i:s")));
$objSupportMessage->setEtat(\SupportEtatMessageHelper::NON_LU);
$objSupportMessage->setDatechangementEtat(new \DateTime(date("Y-m-d H:i:s")));
$objSupportMessage->setIp($this->ipAdresse);
try {
$objSupportDiscussion = \Site\SiteHelper::getSupportDiscussionsRepository()->find($idDiscussion);
$objSupportDiscussion->setDateDernierMessage(new \DateTime(date("Y-m-d H:i:s")));
$em->persist($objSupportDiscussion);
$em->persist($objSupportMessage);
$em->flush();
if ($idCompte == $objSupportDiscussion->getIdAdmin()) {
$objAccountJoueur = \Account\AccountHelper::getAccountRepository()->find($objSupportDiscussion->getIdCompte());
if ($objAccountJoueur !== null) {
$template = $this->objTwig->loadTemplate("MessagerieMessageAdd.html5.twig");
$result = $template->render(["compte" => $objAccountJoueur->getLogin(), "objet" => \SupportObjetsHelper::getLibelle($objSupportDiscussion->getIdObjet())]);
$subject = 'VamosMT2 - Réponse à votre ticket';
\EmailHelper::sendEmail($objAccountJoueur->getEmail(), $subject, $result);
}
}
echo json_encode(["id" => $objSupportMessage->getId(), "date" => \DateTimeHelper::dateTimeToFormatedString($objSupportMessage->getDate(), "H:i"), "message" => nl2br($objSupportMessage->getMessage())]);
} catch (Exception $ex) {
}
}
示例10: getFeedItems
/**
* Fetches and parses an RSS or Atom feed, and returns its items.
*
* Each element in the returned array will have the following keys:
*
* - **authors** – An array of the item’s authors, where each sub-element has the following keys:
* - **name** – The author’s name
* - **url** – The author’s URL
* - **email** – The author’s email
* - **categories** – An array of the item’s categories, where each sub-element has the following keys:
* - **term** – The category’s term
* - **scheme** – The category’s scheme
* - **label** – The category’s label
* - **content** – The item’s main content.
* - **contributors** – An array of the item’s contributors, where each sub-element has the following keys:
* - **name** – The contributor’s name
* - **url** – The contributor’s URL
* - **email** – The contributor’s email
* - **date** – A {@link DateTime} object representing the item’s date.
* - **dateUpdated** – A {@link DateTime} object representing the item’s last updated date.
* - **permalink** – The item’s URL.
* - **summary** – The item’s summary content.
* - **title** – The item’s title.
*
* @param string $url The feed’s URL.
* @param int $limit The maximum number of items to return. Default is 0 (no limit).
* @param int $offset The number of items to skip. Defaults to 0.
* @param string $cacheDuration Any valid [PHP time format](http://www.php.net/manual/en/datetime.formats.time.php).
*
* @return array|string The list of feed items.
*/
public function getFeedItems($url, $limit = 0, $offset = 0, $cacheDuration = null)
{
$items = array();
if (!extension_loaded('dom')) {
Craft::log('Craft needs the PHP DOM extension (http://www.php.net/manual/en/book.dom.php) enabled to parse feeds.', LogLevel::Warning);
return $items;
}
if (!$cacheDuration) {
$cacheDuration = craft()->config->getCacheDuration();
} else {
$cacheDuration = DateTimeHelper::timeFormatToSeconds($cacheDuration);
}
$feed = new \SimplePie();
$feed->set_feed_url($url);
$feed->set_cache_location(craft()->path->getCachePath());
$feed->set_cache_duration($cacheDuration);
$feed->init();
// Something went wrong.
if ($feed->error()) {
Craft:
log('There was a problem parsing the feed: ' . $feed->error(), LogLevel::Warning);
return array();
}
foreach ($feed->get_items($offset, $limit) as $item) {
$date = $item->get_date('U');
$dateUpdated = $item->get_updated_date('U');
$items[] = array('authors' => $this->_getItemAuthors($item->get_authors()), 'categories' => $this->_getItemCategories($item->get_categories()), 'content' => $item->get_content(true), 'contributors' => $this->_getItemAuthors($item->get_contributors()), 'date' => $date ? new DateTime('@' . $date) : null, 'dateUpdated' => $dateUpdated ? new DateTime('@' . $dateUpdated) : null, 'permalink' => $item->get_permalink(), 'summary' => $item->get_description(true), 'title' => $item->get_title(), 'enclosures' => $this->_getEnclosures($item->get_enclosures()));
}
return $items;
}
示例11: actionDownloadFile
/**
* Downloads a file and cleans up old temporary assets
*/
public function actionDownloadFile()
{
// Clean up temp assets files that are more than a day old
$fileResults = array();
$files = IOHelper::getFiles(craft()->path->getTempPath(), true);
foreach ($files as $file) {
$lastModifiedTime = IOHelper::getLastTimeModified($file, true);
if (substr(IOHelper::getFileName($file, false, true), 0, 6) === "assets" && DateTimeHelper::currentTimeStamp() - $lastModifiedTime->getTimestamp() >= 86400) {
IOHelper::deleteFile($file);
}
}
// Sort out the file we want to download
$id = craft()->request->getParam('id');
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = $id;
$asset = $criteria->first();
if ($asset) {
// Get a local copy of the file
$sourceType = craft()->assetSources->getSourceTypeById($asset->sourceId);
$localCopy = $sourceType->getLocalCopy($asset);
// Send it to the browser
craft()->request->sendFile($asset->filename, IOHelper::getFileContents($localCopy), array('forceDownload' => true));
craft()->end();
}
}
示例12: _writeTableBody
private function _writeTableBody()
{
// die letzten 5 Flüge aus dem Hauptflugbuch werden ermittelt
$flightlog = $this->_getData();
// Rückgabevariable initialisieren
$html = '';
// alle gefunden Flüge werden durchlaufen und
// anschließend in die Tabelle geschrieben
foreach ($flightlog as $flight) {
// Tabelleninhalt schreiben
$html .= sprintf('
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
', DateTimeHelper::DateFormat($flight['datum']), $flight['kennzeichen'], DateTimeHelper::TimeFormat($flight['startzeit']), DateTimeHelper::TimeFormat($flight['landezeit']), DateTimeHelper::MinutesToTimeFormat($flight['flugzeit']));
}
// es wird geprüft, ob und wann die letzten 5 Flüge des angemeldeten
// Mitgliedes durchgeführt wurden, sind keine Daten vorhanden,
// dann wird eine entsprechende Meldung ausgegeben
if (count($flightlog) == 0) {
// Meldung, dass keine aktuellen Flüge vorhanden sind, zurückgeben
$html = sprintf('
<tr>
<td colspan="5" class="no-data">z. Zt. keine aktuellen Flüge</td>
</tr>
');
}
// der Tabelleninhalt wird im HTML-Format zurückgegeben
return $html;
}
示例13: getJsonObject
public function getJsonObject()
{
$ret = array('departureCity' => $this->getDepartureCity()->localRu, 'departureCityPre' => $this->getDepartureCity()->casePre, 'arrivalCity' => $this->getArrivalCity()->localRu, 'arrivalCityPre' => $this->getArrivalCity()->casePre, 'departureDate' => DateTimeHelper::formatForJs($this->departureDate), 'arrivalDate' => DateTimeHelper::formatForJs($this->getArrivalDate()), 'fullDuration' => $this->fullDuration, 'flightParts' => array());
foreach ($this->flightParts as $flightPart) {
$ret['flightParts'][] = $flightPart->getJsonObject();
}
return $ret;
}
示例14: getUrlAppendix
/**
* Get appendix for an URL based on it's Source caching settings.
*
* @param BaseAssetSourceType $source
* @param AssetFileModel $file
*
* @return string
*/
public static function getUrlAppendix(BaseAssetSourceType $source, AssetFileModel $file)
{
$appendix = '';
if (!empty($source->getSettings()->expires) && DateTimeHelper::isValidIntervalString($source->getSettings()->expires)) {
$appendix = '?mtime=' . $file->dateModified->format("YmdHis");
}
return $appendix;
}
示例15: getNextAnnouncement
/**
* Returns the next active announcement.
*
* @param string $timeInAdvance
*
* @return AnnouncementModel
*/
public function getNextAnnouncement($timeInAdvance = '0')
{
$time = DateTimeHelper::currentUTCDateTime();
$time->modify('+' . $timeInAdvance);
$announcementRecord = craft()->db->createCommand()->select('*')->from('maintenance_announcements')->where(array('and', array('or', 'blockSite = 1', 'blockCp = 1'), 'startDate <= :time', array('or', 'endDate >= :now', 'endDate IS NULL')), array(':now' => DateTimeHelper::formatTimeForDb(), ':time' => DateTimeHelper::formatTimeForDb($time)))->order('startDate desc')->queryRow();
if ($announcementRecord) {
return Maintenance_AnnouncementModel::populateModel($announcementRecord);
}
}