本文整理汇总了PHP中DateTimeUtils类的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeUtils类的具体用法?PHP DateTimeUtils怎么用?PHP DateTimeUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTimeUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateValue
/**
* @covers Pql::CreateValue
*/
public function testCreateValue()
{
$this->assertEquals('hello', Pql::CreateValue(new TextValue('hello'))->value);
$this->assertEquals('value1', Pql::CreateValue('value1')->value);
$this->assertEquals(false, Pql::CreateValue(false)->value);
$this->assertEquals('1', Pql::CreateValue(1)->value);
$this->assertEquals('1.02', Pql::CreateValue(1.02)->value);
$this->assertEquals('2012-12-02T12:45:00+08:00', DateTimeUtils::ToStringWithTimeZone(Pql::CreateValue($this->dateTime1)->value));
$this->assertEquals('2012-12-02', DateTimeUtils::ToString(Pql::CreateValue($this->dateTime1->date)->value));
}
示例2: testCreateTraining
/**
*
*/
public function testCreateTraining()
{
$factory = new MarketplaceFactory();
$training = $factory->buildTraining();
$training->setName('test training');
$training->setDescription('test training description');
$training->activate();
$service = new TrainingServiceManager($repository = new SapphireTrainingServiceRepository());
$repository->add($training);
$courses = $service->getCoursesByDate($training->getIdentifier(), DateTimeUtils::getCurrentDate());
}
示例3: doClean
/**
* @see sfValidatorBase
*/
protected function doClean($value)
{
$clean = (string) $value;
if (!DateTimeUtils::validTimeString($value)) {
throw new sfValidatorError($this, 'invalid');
}
$clean = DateTimeUtils::formatTime(DateTimeUtils::parseTime($value));
$cleanedSeconds = DateTimeUtils::getTimeSeconds($value);
if ($cleanedSeconds < DateTimeUtils::getTimeSeconds($this->getOption('startTime'))) {
throw new sfValidatorError($this, 'start_time', array('value' => $clean, 'start_time' => $this->getOption('start_time')));
}
if ($cleanedSeconds > DateTimeUtils::getTimeSeconds($this->getOption('endTime'))) {
throw new sfValidatorError($this, 'end_time', array('value' => $clean, 'end_time' => $this->getOption('end_time')));
}
return $clean;
}
示例4: testCreateValue
/**
* @covers Pql::CreateValue
*/
public function testCreateValue()
{
$this->assertEquals('hello', Pql::CreateValue(new TextValue('hello'))->value);
$this->assertEquals('value1', Pql::CreateValue('value1')->value);
$this->assertEquals(false, Pql::CreateValue(false)->value);
$this->assertEquals('1', Pql::CreateValue(1)->value);
$this->assertEquals('1.02', Pql::CreateValue(1.02)->value);
$this->assertEquals('2012-12-02T12:45:00+08:00', DateTimeUtils::ToStringWithTimeZone(Pql::CreateValue($this->dateTime1)->value));
$this->assertEquals('2012-12-02', DateTimeUtils::ToString(Pql::CreateValue($this->dateTime1->date)->value));
$values = Pql::CreateValue([23, 42, 5, 10, 1])->values;
$this->assertEquals(5, count($values));
$this->assertEquals(23, $values[0]->value);
$this->assertEquals(42, $values[1]->value);
$this->assertEquals(5, $values[2]->value);
$this->assertEquals(10, $values[3]->value);
$this->assertEquals(1, $values[4]->value);
}
示例5: testDay_yyyy_mm_dd
function testDay_yyyy_mm_dd()
{
$date = "2011-10-16";
$day = DateTimeUtils::day_yyyy_mm_dd($date);
$this->assertEqual(16, $day, "Il giorno non corrisponde!!");
/*
try
{
DateTimeUtils::day_yyyy_mm_dd("10-07-2012");
$this->fail("Viene accettata una data in un formato non corretto!");
}
catch(InvalidParameterException $ex)
{
//ok
}
*/
}
示例6: ToString
/**
* Creates a String from the Value.
*
* @param Value $value the value to convert
* @return string the string representation of the value
* @throws InvalidArgumentException if value cannot be converted
*/
public static function ToString(Value $value)
{
if ($value instanceof BooleanValue) {
return $value->value ? 'true' : 'false';
} else {
if ($value instanceof NumberValue || $value instanceof TextValue) {
return strval($value->value);
} else {
if ($value instanceof DateTimeValue) {
return isset($value->value) ? DateTimeUtils::ToStringWithTimeZone($value->value) : '';
} else {
if ($value instanceof DateValue) {
return DateTimeUtils::ToString($value->value);
} else {
throw new InvalidArgumentException(sprintf("Unsupported Value type [%s]", get_class($value)));
}
}
}
}
}
示例7: date
$lineItemService = $user->GetService('LineItemService', 'v201311');
// Set the ID of the order to get line items from.
$orderId = 'INSERT_ORDER_ID_HERE';
// Calculate time from three days ago.
$threeDaysAgo = date(DateTimeUtils::$DFP_DATE_TIME_STRING_FORMAT, strtotime('-3 day'));
// Create bind variables.
$vars = MapUtils::GetMapEntries(array('orderId' => new NumberValue($orderId), 'threeDaysAgo' => new TextValue($threeDaysAgo)));
// Create statement object to only select line items belonging to the order
// and have been modified in the last 3 days.
$filterStatement = new Statement("WHERE orderId = :orderId " . "AND lastModifiedDateTime >= :threeDaysAgo " . "LIMIT 500", $vars);
// Get line items by statement.
$page = $lineItemService->getLineItemsByStatement($filterStatement);
// Display results.
if (isset($page->results)) {
$i = $page->startIndex;
foreach ($page->results as $lineItem) {
// Format lastModifiedDateTime for printing.
$lastModifiedDateTime = DateTimeUtils::GetDateTime($lineItem->lastModifiedDateTime);
$lastModifiedDateTimeText = $lastModifiedDateTime->format(DateTimeUtils::$DFP_DATE_TIME_STRING_FORMAT);
print $i . ') Line item with ID "' . $lineItem->id . '", belonging to order ID "' . $lineItem->orderId . '", with name "' . $lineItem->name . '", and last modified ' . $lastModifiedDateTimeText . " was found.\n";
$i++;
}
}
print 'Number of results found: ' . $page->totalResultSetSize . "\n";
} catch (OAuth2Exception $e) {
ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
print $e->getMessage() . "\n";
}
示例8: dirname
// DfpUser.php directly via require_once.
// $path = '/path/to/dfp_api_php_lib/src';
$path = dirname(__FILE__) . '/lib';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php';
require_once 'Google/Api/Ads/Dfp/Util/v201508/StatementBuilder.php';
require_once 'Google/Api/Ads/Dfp/Util/v201508/DateTimeUtils.php';
require_once dirname(__FILE__) . '/examples/Common/ExampleUtils.php';
try {
// Get DfpUser from credentials in "../auth.ini"
// relative to the DfpUser.php file's directory.
$user = new DfpUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get DateUtils
$dateTimeUtils = new DateTimeUtils();
// Get the LineItemService.
$lineItemService = $user->GetService('LineItemService', 'v201508');
// Create a statement to select all line items.
$statementBuilder = new StatementBuilder();
$statementBuilder->OrderBy('id DESC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
$statementBuilder->Where("EndDateTime >= '" . date('Y-m-d', time() - 86400 * 7) . "'");
//$statementBuilder->Limit("100");
// Default for total result set size.
$totalResultSetSize = 0;
printf("Downloading and saving results to file\n");
$fn = "./line-items.csv";
$fp = fopen($fn, "a");
fwrite($fp, implode(',', array('orderId', 'orderName', 'lineItemId', 'lineItemName', 'externalId', 'creationDateTime', 'startDateTime', 'endDateTime', 'priority', 'costType', 'lineItemType', 'impressionsDelivered', 'clicksDelivered', 'expectedDeliveryPercentage', 'actualDeliveryPercentage', 'status', 'notes', 'isMissingCreatives', 'primaryGoalType', 'primaryGoalUnitType', 'primaryGoalUnits', 'targetingGeo', 'targetingExcludedAdunits', 'targetingBrowser', 'targetingCategory', 'targetingDevice', 'targetingOs', 'targetingOsVersion', 'targetingCustom', 'frequencyCaps', 'targetingPlatform')) . "\n");
do {
// Get line items by statement.
示例9: ReportQuery
// Get the ReportService.
$reportService = $user->GetService('ReportService', 'v201605');
// Create report query.
$reportQuery = new ReportQuery();
$reportQuery->dimensions = array('ORDER_ID', 'ORDER_NAME');
$reportQuery->dimensionAttributes = array('ORDER_TRAFFICKER', 'ORDER_START_DATE_TIME', 'ORDER_END_DATE_TIME');
$reportQuery->columns = array('AD_SERVER_IMPRESSIONS', 'AD_SERVER_CLICKS', 'AD_SERVER_CTR', 'AD_SERVER_CPM_AND_CPC_REVENUE', 'AD_SERVER_WITHOUT_CPD_AVERAGE_ECPM');
// Create statement to filter for an order.
$statementBuilder = new StatementBuilder();
$statementBuilder->Where('order_id = :orderId')->WithBindVariableValue('orderId', $orderId);
// Set the filter statement.
$reportQuery->statement = $statementBuilder->ToStatement();
// Set the start and end dates or choose a dynamic date range type.
$reportQuery->dateRangeType = 'CUSTOM_DATE';
$reportQuery->startDate = DateTimeUtils::ToDfpDateTime(new DateTime('-10 days', new DateTimeZone('America/New_York')))->date;
$reportQuery->endDate = DateTimeUtils::ToDfpDateTime(new DateTime('now', new DateTimeZone('America/New_York')))->date;
// Create report job.
$reportJob = new ReportJob();
$reportJob->reportQuery = $reportQuery;
// Run report job.
$reportJob = $reportService->runReportJob($reportJob);
// Create report downloader.
$reportDownloader = new ReportDownloader($reportService, $reportJob->id);
// Wait for the report to be ready.
$reportDownloader->waitForReportReady();
// Change to your file location.
$filePath = sprintf('%s.csv.gz', tempnam(sys_get_temp_dir(), 'delivery-report-'));
printf("Downloading report to %s ...\n", $filePath);
// Download the report.
$reportDownloader->downloadReport('CSV_DUMP', $filePath);
printf("done.\n");
示例10: InventoryTargeting
$lineItem->lineItemType = 'SPONSORSHIP';
// Create inventory targeting.
$inventoryTargeting = new InventoryTargeting();
$inventoryTargeting->targetedPlacementIds = array($targetPlacementId);
// Set targeting for line item.
$targeting = new Targeting();
$targeting->inventoryTargeting = $inventoryTargeting;
$lineItem->targeting = $targeting;
// Create the creative placeholder.
$creativePlaceholder = new CreativePlaceholder();
$creativePlaceholder->size = new Size(300, 250, FALSE);
// Set the size of creatives that can be associated with this line item.
$lineItem->creativePlaceholders = array($creativePlaceholder);
// Set the line item's time to be now until the projected end date time.
$lineItem->startDateTimeType = 'IMMEDIATELY';
$lineItem->endDateTime = DateTimeUtils::GetDfpDateTime(new DateTime('+1 week'));
// Set the line item to use 50% of the impressions.
$lineItem->unitType = 'IMPRESSIONS';
$lineItem->unitsBought = 50;
// Set the cost type to match the unit type.
$lineItem->costType = 'CPM';
// Get forecast for line item.
$forecast = $forecastService->getForecast($lineItem);
// Display results.
$matchedUnits = $forecast->matchedUnits;
$percentAvailableUnits = $forecast->availableUnits / $matchedUnits * 100;
$unitType = strtolower($forecast->unitType);
printf("%d %s matched.\n", $matchedUnits, $unitType);
printf("%d%% %s available.\n", $percentAvailableUnits, $unitType);
if (isset($forecast->possibleUnits)) {
$percentPossibleUnits = $forecast->possibleUnits / $matchedUnits * 100;
示例11: getDays
/**
* @return string
*/
public function getDays()
{
return DateTimeUtils::getDayDiff($this->dto->getStartDate(), $this->dto->getEndDate());
}
示例12: updateResultFilters
public static function updateResultFilters($peer)
{
$all_fields = $peer->__getAllFields();
foreach (Params::keys() as $key) {
if (self::isFilter($key, Params::get($key))) {
$value = Params::get($key);
$filter_call = self::getFilterCall($key);
if (self::isDateReversingEnabled()) {
if ($all_fields[self::getFilterField($key)]["type"] == "date") {
$value = DateTimeUtils::reverse_date_dd_mm_yyyy(Params::get($key));
}
}
$peer->{$filter_call}($value);
}
}
}
示例13: getCompanyTraining
/**
* @param int $training_id
* @param string $company_url_segment
* @return array
* @throws Exception
*/
public function getCompanyTraining($training_id, $company_url_segment)
{
if (empty($company_url_segment)) {
throw new Exception("Invalid Company");
}
//@todo: remove dataobjects dependencies
$company = Company::get()->filter('URLSegment', $company_url_segment)->first();
$training = empty($training_id) ? null : TrainingService::get()->byID($training_id);
if (!$company) {
throw new Exception("Invalid Company");
}
if (!$training) {
//get default program
$training = $company->getDefaultTraining();
}
//check if program belongs to selected company
$training_company = $training->Company();
if ($training_company->getIdentifier() != $company->getIdentifier()) {
//if not , get default program
$training = $company->getDefaultTraining();
}
if (!$this->training_manager->isActive($training->getIdentifier())) {
return Security::permissionFailure($this->controller, "non active training!.");
}
$courses = $this->training_manager->getCoursesByDate($training->getIdentifier(), DateTimeUtils::getCurrentDate());
$courses_vm = new ArrayList();
foreach ($courses as $course) {
$course_dto = new CourseDTO($course->getIdentifier(), $course->getName(), $course->getDescription(), $course->getTraining()->getIdentifier(), null, null, null, $course->level()->Level, $course->isOnline(), null, null, null, null, null, $course->getOnlineLink());
$locations_dto = $this->course_repository->getLocationsByDate($course->getIdentifier(), DateTimeUtils::getCurrentDate());
$locations_vm = new ArrayList();
foreach ($locations_dto as $location_dto) {
$locations_vm->push(new CourseLocationViewModel($location_dto));
}
$courses_vm->push(new CourseViewModel($course_dto, $locations_vm, $course->projects()));
}
$res = array('Company' => $company, 'Training' => $training, 'Courses' => $courses_vm, 'Slug' => $training->getSlug());
return $res;
}
示例14: isLeapYear
<?php
DateTimeUtils::addDate('2012-12-01', 1, 'y');
DateTimeUtils::getWeekDay('2012/10/01', '/');
DateTimeUtils::isLeapYear('2012');
DateTimeUtils::timeFromNow(strtotime("2012-10-26 14:15:13"));
class DateTimeUtils
{
/**
* Checks for leap year, returns true if it is. No 2-digit year check. Also
* handles julian calendar correctly.
* @param integer $year year to check
* @return boolean true if is leap year
*/
public static function isLeapYear($year)
{
$year = self::digitCheck($year);
if ($year % 4 != 0) {
return false;
}
if ($year % 400 == 0) {
return true;
} else {
if ($year > 1582 && $year % 100 == 0) {
return false;
}
}
return true;
}
/**
* Fix 2-digit years. Works for any century.
* Assumes that if 2-digit is more than 30 years in future, then previous century.
示例15: setupWithMap
public function setupWithMap($do, $params)
{
$all_fields = $this->__getAllFields();
foreach ($params as $key => $value) {
$saved = false;
if ($all_fields[$key]["type"] == "date") {
$do->{$key} = DateTimeUtils::reverse_date_dd_mm_yyyy($value);
$saved = true;
}
if (!$saved) {
$do->{$key} = $value;
}
}
return $do;
}