本文整理汇总了PHP中DateTime::modify方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::modify方法的具体用法?PHP DateTime::modify怎么用?PHP DateTime::modify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::modify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->payments = new ArrayCollection();
$this->syncDate = new \DateTime();
$this->syncDate->modify('-3 years');
$this->setOptions(array());
}
示例2: run1
protected function run1($stage)
{
$stmt = '';
if (!$this->hasTableColumn('os', 'created')) {
$bCreated = true;
$this->console->out("Adding scalr.os.created column...");
$stmt .= ", ADD COLUMN `created` DATETIME NOT NULL COMMENT 'Created at timestamp' AFTER `is_system`";
}
if (!$this->hasTableIndex('os', 'idx_created')) {
$this->console->out("Adding idx_created index for scalr.os.created column...");
$stmt .= ", ADD INDEX `idx_created` (`created` ASC)";
}
if (!empty($stmt)) {
$this->db->Execute("ALTER TABLE `os` " . ltrim($stmt, ','));
}
if (!empty($bCreated)) {
$date = new \DateTime();
$date->modify('-1 hour');
$list = Os::find([['$or' => [['created' => null], ['created' => new \DateTime('0000-00-00 00:00:00')]]]]);
foreach ($list as $os) {
/* @var $os Os */
$os->created = $date;
$os->save();
$date->modify('+1 second');
}
}
}
示例3: setDefaultValues
public function setDefaultValues()
{
$defaults = array();
try {
$defaults['rood_mtype'] = civicrm_api3('MembershipType', 'getvalue', array('return' => 'id', 'name' => 'Lid SP en ROOD'));
} catch (Exception $e) {
//do nothing
}
try {
$defaults['rood_mstatus'] = civicrm_api3('MembershipStatus', 'getvalue', array('return' => 'id', 'name' => 'Correctie'));
} catch (Exception $e) {
//do nothing
}
try {
$defaults['sp_mtype'] = civicrm_api3('MembershipType', 'getvalue', array('return' => 'id', 'name' => 'Lid SP'));
} catch (Exception $e) {
//do nothing
}
try {
$status = civicrm_api3('MembershipStatus', 'getvalue', array('return' => 'id', 'name' => 'current'));
$defaults['member_status_id'][$status] = $status;
} catch (Exception $e) {
//do nothing
}
$date = new DateTime();
$date->modify('-26 years');
$date->modify('first day of this year');
list($defaults['birth_date_from']) = CRM_Utils_Date::setDateDefaults($date->format('Y-m-d'));
$date->modify('last day of this year');
list($defaults['birth_date_to']) = CRM_Utils_Date::setDateDefaults($date->format('Y-m-d'));
$minimum_fee = CRM_Core_BAO_Setting::getItem('nl.sp.rood', 'minimum_fee', null, '5.00');
$defaults['minimum_fee'] = $minimum_fee;
return $defaults;
}
示例4: datetime2range
/**
* Returns date range Y-m-d - Y-m-d
*
* @param DateTime $date
* @param string $type (day, week, month)
* @return array
*/
public static function datetime2range(DateTime $date, $type)
{
switch ($type) {
case 'day':
$from = $to = $date->format('Y-m-d');
break;
case 'week':
$fdow = Kohana::config('locale.start_monday') ? 1 : 7;
$dow = $date->format('N');
if ($dow > $fdow) {
$date->modify('-' . ($dow - $fdow) . ' days');
}
case '7days':
$from = $date->format('Y-m-d');
$date->modify('+6 days');
$to = $date->format('Y-m-d');
break;
case 'month':
$from = $date->format('Y-m-01');
$to = $date->format('Y-m-t');
break;
default:
return false;
}
return date::range($from, $to);
}
示例5: get_schedule
public function get_schedule($id, $module)
{
$date = new DateTime(phpgw::get_var('date'));
// Make sure $from is a monday
if ($date->format('w') != 1) {
$date->modify('last monday');
}
$prev_date = clone $date;
$next_date = clone $date;
$prev_date->modify('-1 week');
$next_date->modify('+1 week');
$building = $this->read_single($id);
$building['buildings_link'] = self::link(array('menuaction' => $module . '.index'));
$building['building_link'] = self::link(array('menuaction' => $module . '.show', 'id' => $building['id']));
$building['date'] = $date->format('Y-m-d');
$building['week'] = intval($date->format('W'));
$building['year'] = intval($date->format('Y'));
$building['prev_link'] = self::link(array('menuaction' => $module . '.schedule', 'id' => $building['id'], 'date' => $prev_date->format('Y-m-d')));
$building['next_link'] = self::link(array('menuaction' => $module . '.schedule', 'id' => $building['id'], 'date' => $next_date->format('Y-m-d')));
for ($i = 0; $i < 7; $i++) {
$building['days'][] = array('label' => sprintf('%s<br/>%s %s', lang($date->format('l')), lang($date->format('M')), $date->format('d')), 'key' => $date->format('D'));
$date->modify('+1 day');
}
return $building;
}
示例6: getValue
function getValue($fieldName, $relId, $templateId, $baseRecord = NULL, $partentTplId = NULL)
{
$val = parent::getValue($fieldName, $relId, $templateId, $baseRecord, $partentTplId);
if ('create_date' === $val) {
return date('Y-m-d');
} else {
if ('num_day' === $val) {
$db = PearDatabase::getInstance();
$dayFielddName = $fieldName . '_day';
if (NULL !== $baseRecord && NULL !== $partentTplId) {
$templateId = $partentTplId;
}
$numDaySql = "SELECT fld_val FROM vtiger_oss_project_templates WHERE fld_name = ? AND id_tpl = ?";
$numDayResult = $db->pquery($numDaySql, array($dayFielddName, $templateId), true);
$numDay = $db->query_result($numDayResult, 0, 'fld_val');
$typeFielddName = $fieldName . '_day_type';
$onlyBusinessDaySql = "SELECT fld_val FROM vtiger_oss_project_templates WHERE fld_name = ? AND id_tpl = ? ";
$onlyBusinessDayResult = $db->pquery($onlyBusinessDaySql, array($typeFielddName, $templateId), TRUE);
$dayType = $db->query_result($onlyBusinessDayResult, 0, 'fld_val');
$date = new DateTime();
if (!!$dayType) {
$date->modify("+ {$numDay} weekdays");
} else {
$date->modify("+ {$numDay} days");
}
return $date->format('Y-m-d');
} else {
return '';
}
}
}
示例7: increment
public function increment(\DateTime $date, $invert = false, $parts = null)
{
if (is_null($parts)) {
if ($invert) {
$date->modify('-1 minute');
} else {
$date->modify('+1 minute');
}
return $this;
}
$parts = strpos($parts, ',') !== false ? explode(',', $parts) : array($parts);
$minutes = array();
foreach ($parts as $part) {
$minutes = array_merge($minutes, $this->getRangeForExpression($part, 59));
}
$current_minute = $date->format('i');
$position = $invert ? count($minutes) - 1 : 0;
if (count($minutes) > 1) {
for ($i = 0; $i < count($minutes) - 1; $i++) {
if (!$invert && $current_minute >= $minutes[$i] && $current_minute < $minutes[$i + 1] || $invert && $current_minute > $minutes[$i] && $current_minute <= $minutes[$i + 1]) {
$position = $invert ? $i : $i + 1;
break;
}
}
}
if (!$invert && $current_minute >= $minutes[$position] || $invert && $current_minute <= $minutes[$position]) {
$date->modify(($invert ? '-' : '+') . '1 hour');
$date->setTime($date->format('H'), $invert ? 59 : 0);
} else {
$date->setTime($date->format('H'), $minutes[$position]);
}
return $this;
}
示例8: indexAction
/**
* @Route("/{year}/{month}", name="siswa__kehadiran")
* @Template("LanggasSisdikBundle:KehadiranSiswa:tabulasi.html.twig")
*/
public function indexAction($year = 0, $month = 0)
{
$waktuSekarang = new \DateTime();
$year = $year != 0 ? $year : $waktuSekarang->format('Y');
$month = $month != 0 ? $month : $waktuSekarang->format('m');
$tanggalTerpilih = new \DateTime("{$year}-{$month}-01");
$sekolah = $this->getSekolah();
$em = $this->getDoctrine()->getManager();
$tahunAkademik = $em->getRepository('LanggasSisdikBundle:TahunAkademik')->findOneBy(['sekolah' => $sekolah, 'aktif' => true]);
if (!$tahunAkademik instanceof TahunAkademik) {
throw $this->createNotFoundException($this->get('translator')->trans('flash.tahun.akademik.tidak.ada.yang.aktif'));
}
$siswa = $this->getUser()->getSiswa();
$siswaKelas = $em->getRepository('LanggasSisdikBundle:SiswaKelas')->findOneBy(['siswa' => $siswa, 'tahunAkademik' => $tahunAkademik, 'aktif' => true]);
if (!$siswaKelas instanceof SiswaKelas) {
throw $this->createNotFoundException($this->get('translator')->trans('flash.siswa.tidak.terdaftar.aktif.di.kelas'));
}
$objectCalendar = new Calendar();
$calendar = $objectCalendar->createMonthlyCalendar($tanggalTerpilih->format('Y'), $tanggalTerpilih->format('m'));
$nextmonth = date('Y-m-d', mktime(0, 0, 0, $tanggalTerpilih->format('m') + 1, 1, $tanggalTerpilih->format('Y')));
$kehadiran = $em->createQueryBuilder()->select('kehadiran')->from('LanggasSisdikBundle:KehadiranSiswa', 'kehadiran')->where('kehadiran.sekolah = :sekolah')->andWhere('kehadiran.tahunAkademik = :tahunAkademik')->andWhere('kehadiran.kelas = :kelas')->andWhere('kehadiran.siswa = :siswa')->andWhere('kehadiran.tanggal >= :firstday AND kehadiran.tanggal < :nextmonth')->setParameter('sekolah', $sekolah)->setParameter('tahunAkademik', $tahunAkademik)->setParameter('kelas', $siswaKelas->getKelas())->setParameter('siswa', $siswa)->setParameter('firstday', $tanggalTerpilih->format('Y-m-01'))->setParameter('nextmonth', $nextmonth)->getQuery()->getResult();
$tanggalTerpilih->modify('first day of -1 month');
$tahunBulanSebelumnya = $tanggalTerpilih->format('Y');
$bulanSebelumnya = $tanggalTerpilih->format('m');
$tanggalTerpilih->modify('first day of +2 month');
$tahunBulanBerikutnya = $tanggalTerpilih->format('Y');
$bulanBerikutnya = $tanggalTerpilih->format('m');
return ['tahunAkademik' => $tahunAkademik, 'kelas' => $siswaKelas, 'siswa' => $siswa, 'kehadiran' => $kehadiran, 'daftarStatusKehadiran' => JadwalKehadiran::getDaftarStatusKehadiran(), 'calendar' => $calendar, 'tanggalTerpilih' => $tanggalTerpilih, 'tahunBulanSebelumnya' => $tahunBulanSebelumnya, 'bulanSebelumnya' => $bulanSebelumnya, 'tahunBulanBerikutnya' => $tahunBulanBerikutnya, 'bulanBerikutnya' => $bulanBerikutnya];
}
示例9: convertPeriodToEndDate
public static function convertPeriodToEndDate($period)
{
$date = new DateTime();
switch ($period) {
case 'this month':
$date->modify('last day of this month');
return $date;
break;
case 'previous month':
$date->modify('last day of previous month');
return $date;
break;
case 'last 30 days':
return $date;
break;
case 'last 12 months':
return $date;
break;
case 'last 13 months':
return $date;
break;
case 'this year':
$date->modify('last day of December this year');
return $date;
break;
case 'previous year':
$date->modify('last day of December previous year');
return $date;
break;
}
return false;
}
示例10: seeInDatabaseExt
/**
* Assert that a given where condition exists in the database.
*
* @param string $table
* @param array $data
* @param string $connection
* @return $this
*/
protected function seeInDatabaseExt($table, array $where, array $dates, $isDeleted = false, $connection = null)
{
$database = $this->app->make('db');
$connection = $connection ?: $database->getDefaultConnection();
$query = $database->connection($connection)->table($table);
// where句連結
foreach ($where as $key => $value) {
$query->where($key, $value);
}
// 日付確認用
if (count($dates) == 0) {
$now = new \DateTime('now');
foreach ($dates as $dateColumn => $isNow) {
if ($isNow) {
//now()
$query->whereBetween($dateColumn, [$now->modify('-1 minutes')->format('Y-m-d H:i:s'), $now->modify('+1 minutes')->format('Y-m-d H:i:s')]);
} else {
// not now()
$query->whereNotBetween($dateColumn, [$now->modify('-1 minutes')->format('Y-m-d H:i:s'), $now->modify('+1 minutes')->format('Y-m-d H:i:s')]);
}
}
}
// delete flag確認
if ($isDeleted) {
$query->whereNotNull('deleted_at');
} else {
$query->whereNull('deleted_at');
}
$count = $query->count();
$this->assertGreaterThan(0, $count, sprintf('Unable to find row in database table [%s] that matched attributes [%s].', $table, json_encode($where), 'deleted_at' . $isDeleted));
return $this;
}
示例11: setUp
/**
* {@inheritDoc}
*/
public function setUp()
{
parent::setUp();
/** @var \Doctrine\ODM\MongoDB\SchemaManager $schemaManager */
$schemaManager = $this->dm->getSchemaManager();
$schemaManager->dropDocumentCollection('CronEventBundle:Schedule');
$this->repository = $this->dm->getRepository('CronEventBundle:Schedule');
$now = new \DateTime();
$yesterday = $now->modify('-1 day');
// all my troubles seemed so far away
// Now it looks as though they're here to stay
// oh, I believe in yesterday
$tomorrow = $now->modify('+1 day');
$schedule = new Schedule();
$schedule->setName('testEvent');
$schedule->setEnabled(true);
$schedule->setStartTime($tomorrow);
$schedule->setStartTimeExpired(false);
$schedule->setStatus('unexpired');
$schedule->setType('event');
$schedule->setEvent('cron_event.ad.not_published');
$schedule->setParameters(['id' => 'test']);
$this->dm->persist($schedule);
$this->dm->flush();
$schedule = new Schedule();
$schedule->setName('testTimer');
$schedule->setEnabled(true);
$schedule->setEndTime($yesterday);
$schedule->setEndTimeExpired(false);
$schedule->setStatus('unexpired');
$schedule->setType('timer');
$schedule->setParameters(['id' => 'test2']);
$this->dm->persist($schedule);
$this->dm->flush();
}
示例12: index_1Action
public function index_1Action()
{
$jetzt = date("Y-m-d H:i:s");
$ini_data = new DateTime($jetzt);
$cdata = str_replace('+0000', '', $ini_data->format(DateTime::ISO8601));
$remove = strstr($ini_data->modify('+1 day')->format(DateTime::ISO8601), 'T', true);
echo str_replace('T', '', strstr($ini_data->modify('+1 day')->format(DateTime::ISO8601), 'T', true));
}
示例13: increment
public function increment(\DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('-1 minute');
} else {
$date->modify('+1 minute');
}
return $this;
}
示例14: increment
public function increment(\DateTime $date, $invert = false)
{
if (${${"GLOBALS"}["pbwsjnnvxj"]}) {
$date->modify("-1 minute");
} else {
$date->modify("+1 minute");
}
return $this;
}
示例15: getByDate
public function getByDate(\DateTime $date)
{
$c = new \DateTime($date->format('Y-m-d'));
$start = $c->format('Y-m-d');
$c->modify('+1 month');
$c->modify('-1 day');
$stop = $c->format('Y-m-d');
return $this->_em->createQueryBuilder()->select('e')->from('ClubEventBundle:Event', 'e')->where('e.start_date > :start_date')->andWhere('e.stop_date < :stop_date')->setParameter('start_date', $start)->setParameter('stop_date', $stop)->getQuery()->getResult();
}