/** * Constructor * * @param string $start The start date of the period 'YYYY-mm-dd' * @param string $end optional End date * @param string $timezone optional Timezone * @throws \InvalidArgumentException */ public function __construct($start, $end = null, $timezone = 'UTC') { $this->mode = 'day'; $this->timezone = new DateTimeZone($timezone); $this->today = $this->getTodayDate(); $this->start = new DateTime($start instanceof DateTime ? $start->format('Y-m-d 00:00:00') : $start, $this->timezone); $this->end = !empty($end) ? new DateTime($end instanceof DateTime ? $end->format('Y-m-d 00:00:00') : $end, $this->timezone) : null; //Difference in days between Start and End dates $diffdays = $this->start->diff($this->end, true)->days; //Difference in days between Start and Today dates $diffTodayDays = $this->start->diff($this->today, true)->days; //Previous interval is the same period in the past $this->prevInterval = new \DateInterval('P' . ($diffdays + 1) . 'D'); if ($diffdays < 2 && $diffTodayDays < 14) { $this->interval = '1 hour'; } else { $this->interval = '1 day'; } $this->prevStart = clone $this->start; $this->prevStart->sub($this->prevInterval); $this->wholePeriodPerviousEnd = clone $this->start; $this->wholePeriodPerviousEnd->modify('-1 day'); $this->prevEnd = clone $this->prevStart; $this->prevEnd->add(new \DateInterval('P' . $this->start->diff(min($this->end, $this->today), true)->days . 'D')); $endoftheday = new \DateInterval('PT23H59M59S'); $this->end->add($endoftheday); $this->prevEnd->add($endoftheday); $this->wholePeriodPerviousEnd->add($endoftheday); if (!$this->di) { $this->di = \DateInterval::createFromDateString($this->interval); } $this->dt = clone $this->start; }
static function createDateString($dateString = 'yesterday') { global $gTimezone; $date = new \DateTime('now', new \DateTimeZone($gTimezone)); $date->add(\DateInterval::createFromDateString($dateString)); return $date->format('Ymd'); }
public function testIsGreaterThanOrEqualTo() { $this->given($asserter = $this->newTestedInstance)->then->exception(function () use($asserter) { $asserter->isGreaterThanOrEqualTo(new \DateInterval('P1D')); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Interval is undefined')->if($asserter->setWith(new \DateInterval('P1Y')))->then->object($asserter->isGreaterThanOrEqualTo(new \DateInterval('P1M')))->isIdenticalTo($asserter)->exception(function () use($asserter, &$interval) { $asserter->isGreaterThanOrEqualTo($interval = new \DateInterval('P2Y')); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage('Interval ' . $asserter . ' is not greater than or equal to ' . $interval->format('%Y/%M/%D %H:%I:%S')); }
/** * Transforms a DateInterval object into a date string with the configured format. * * @param \DateInterval $value A DateInterval object * * @return string An ISO 8601 or relative date string like date interval presentation * * @throws UnexpectedTypeException If the given value is not a \DateInterval instance. */ public function transform($value) { if (null === $value) { return ''; } if (!$value instanceof \DateInterval) { throw new UnexpectedTypeException($value, '\\DateInterval'); } return $value->format($this->format); }
/** * {@inheritdoc} */ public function setDuration(\DateInterval $duration, $notify = TRUE) { // Generate an ISO 8601 formatted string as supported by // DateInterval::__construct() and setValue(). $this->value = $duration->format('%rP%yY%mM%dDT%hH%mM%sS'); // Notify the parent of any changes. if ($notify && isset($this->parent)) { $this->parent->onChange($this->name); } }
/** * @param \DateInterval $interval * @return string */ public static function format(\DateInterval $interval) { $string = $interval->format('%I:%S'); if ($interval->h > 0) { $string = $interval->format('%H:') . $string; } if ($interval->d > 0) { $string = $interval->format('%D:') . $string; } return $string; }
public function getDefaultLength() { $dateString = $this->webstream->getDbLength(); $arr = explode(":", $dateString); if (count($arr) == 3) { list($hours, $min, $sec) = $arr; $di = new DateInterval("PT{$hours}H{$min}M{$sec}S"); return $di->format("%Hh %Im"); } return ""; }
public function run() { // TODO initialize formatter settings at begin of request from user settings Yii::$app->formatter->timeZone = 'Europe/Berlin'; $now = $this->getTimeComponent()->getStartTime(); $end = clone $now; $end->add($this->duration); // TODO introduce constant for DateInterval format $strDuration = $this->duration->format('%H:%I:%S'); $strEnd = Yii::$app->formatter->asDatetime($end); return "<div>Duration: {$strDuration}, until: {$strEnd}</div>"; }
public function index() { /** @var WP_Locale $wp_locale */ global $wp_locale; $this->enqueueStyles(array('frontend' => array('css/intlTelInput.css'), 'module' => array('css/calendar.css', 'css/fullcalendar.min.css'), 'backend' => array('css/chosen.min.css', 'css/jquery-ui-theme/jquery-ui.min.css', 'css/bookly.main-backend.css', 'bootstrap/css/bootstrap.min.css'))); $this->enqueueScripts(array('backend' => array('js/angular-1.3.11.min.js' => array('jquery'), 'js/angular-ui-date-0.0.7.js' => array('ab-angular-1.3.11.min.js'), 'js/ng-new_customer_dialog.js' => array('ab-angular-1.3.11.min.js'), 'js/moment.min.js' => array('jquery'), 'bootstrap/js/bootstrap.min.js' => array('jquery'), 'js/chosen.jquery.min.js' => array('jquery')), 'module' => array('js/ng-app.js' => array('ab-angular-ui-date-0.0.7.js', 'jquery-ui-datepicker', 'jquery-ui-widget', 'jquery-ui-dialog'), 'js/fullcalendar.min.js' => array('ab-moment.min.js'), 'js/fc-multistaff-view.js' => array('ab-fullcalendar.min.js'), 'js/calendar.js' => array('ab-fc-multistaff-view.js', 'ab-intlTelInput.min.js')), 'frontend' => array('js/intlTelInput.min.js' => array('jquery')))); $slot_length_minutes = get_option('ab_settings_time_slot_length', '15'); $slot = new DateInterval('PT' . $slot_length_minutes . 'M'); $this->staff_members = AB_Utils::isCurrentUserAdmin() ? AB_Staff::query()->sortBy('position')->find() : AB_Staff::query()->where('wp_user_id', get_current_user_id())->find(); wp_localize_script('ab-calendar.js', 'BooklyL10n', array('slotDuration' => $slot->format('%H:%I:%S'), 'shortMonths' => array_values($wp_locale->month_abbrev), 'longMonths' => array_values($wp_locale->month), 'shortDays' => array_values($wp_locale->weekday_abbrev), 'longDays' => array_values($wp_locale->weekday), 'AM' => $wp_locale->meridiem['AM'], 'PM' => $wp_locale->meridiem['PM'], 'dpDateFormat' => AB_DateTimeUtils::convertFormat('date', AB_DateTimeUtils::FORMAT_JQUERY_DATEPICKER), 'mjsDateFormat' => AB_DateTimeUtils::convertFormat('date', AB_DateTimeUtils::FORMAT_MOMENT_JS), 'mjsTimeFormat' => AB_DateTimeUtils::convertFormat('time', AB_DateTimeUtils::FORMAT_MOMENT_JS), 'today' => __('Today', 'bookly'), 'week' => __('Week', 'bookly'), 'day' => __('Day', 'bookly'), 'month' => __('Month', 'bookly'), 'allDay' => __('All Day', 'bookly'), 'noStaffSelected' => __('No staff selected', 'bookly'), 'newAppointment' => __('New appointment', 'bookly'), 'editAppointment' => __('Edit appointment', 'bookly'), 'are_you_sure' => __('Are you sure?', 'bookly'), 'startOfWeek' => (int) get_option('start_of_week'), 'country' => get_option('ab_settings_phone_default_country'), 'intlTelInput_utils' => plugins_url('intlTelInput.utils.js', AB_PATH . '/frontend/resources/js/intlTelInput.utils.js'))); $this->render('calendar'); }
/** * Format a date (or interval) to a string with a given format * * See formatting options as in PHP date() * * @param integer|string|\DateTime|\DateInterval $date * @param string $format * @return string */ public function format($date, $format) { if ($date instanceof \DateTimeInterface) { return $date->format($format); } elseif ($date instanceof \DateInterval) { return $date->format($format); } elseif ($date === 'now') { return date($format); } else { $timestamp = (int) $date; return date($format, $timestamp); } }
/** * Get the time things should be cached for in seconds. * * @return int */ public function getCacheDuration() { if (!isset($this->_cacheDuration)) { $duration = $this->get('cacheDuration'); if ($duration) { $interval = new DateInterval($duration); $this->_cacheDuration = $interval->toSeconds(); } else { $this->_cacheDuration = 0; } } return $this->_cacheDuration; }
/** * * Return duration in seconds * * @return int, duration in seconds */ public function getDuration() { $this->initialRequest(); if (isset($this->item['contentDetails']['duration'])) { $date = new \DateInterval($this->item['contentDetails']['duration']); $ret = 0; $ret += (int) $date->format('%d') * 86400; $ret += (int) $date->format('%h') * 3600; $ret += (int) $date->format('%i') * 60; $ret += (int) $date->format('%s'); return $ret; } else { $this->onApiBadInterpretation("contentDetails.duration not found"); } }
/** * @param string $time * @return \DateInterval */ public static function createFromDateString($time) { $interval = parent::createFromDateString($time); $interval->u = 0; // should be implemented return $interval; }
/** * Subtract given interval from current date time * * @param string $intervalString * * @return \DateTime */ protected function prepareDateInterval($intervalString = null) { $date = new \DateTime('now', new \DateTimeZone('UTC')); $intervalString = $intervalString ?: $this->getContainer()->getParameter('oro_batch.cleanup_interval'); $date->sub(\DateInterval::createFromDateString($intervalString)); return $date; }
/** * Check if the time limit is up * * @param DateTime $started Start time * * @return boolean True if the time limit is up */ public function isPassed(\DateTime $started) { // Create a new datetime to now, subtract the limit from it and see if its less than started $now = new \DateTime(); $now->sub(\DateInterval::createFromDateString(sprintf('%d seconds', $this->timeLimit))); return $now >= $started; }
public function test_FiveMinResolutionDailySum_RollupTime_ReturnSumForEachDay() { $value = 1; $nDays = 20; $resolution = Resolution::DAY; $aggregation = Aggregation::SUM; $start = new DateTIme('2015-10-10 00:00:00'); $end = clone $start; $end->add(DateInterval::createFromDateString($nDays . ' days')); $dateperiodExpected = new DatePeriod($start, DateInterval::createFromDateString('1 day'), $end); $expected = []; foreach ($dateperiodExpected as $datetime) { $expected[$datetime->format('Y-m-d H:i:s')] = $value * (86400 / $resolution); } $dateperiod = new DatePeriod($start, DateInterval::createFromDateString($resolution . ' seconds'), $end); $valsByTimestamp = []; foreach ($dateperiod as $datetime) { $valsByTimestamp[$datetime->getTimestamp()] = $value; } $series = new Series($valsByTimestamp); $convert = new ConvertToDateStringKeys(); $action = new RollupTime($resolution, $aggregation); $output = $action->run($series); $output = $convert->run($output); $this->assertEquals($expected, $output); }
/** * Generate the view of the week for given month and given year * with events in this period. * * @param string $year * @param string $week * @return view weekView * * */ public function showWeek($year, $week) { // Create week start date on monday (day 1) $weekStart = date('Y-m-d', strtotime($year . "W" . $week . '1')); // Create the number of the next week $nextWeek = date("W", strtotime("next Week" . $weekStart)); $nextYear = date("Y", strtotime("next Week" . $weekStart)); // Create week end date - we go till tuesday (day 2) because café needs alternative week view (Mi-Di) $weekEnd = date('Y-m-d', strtotime($nextYear . "W" . $nextWeek . '2')); // Create the number of the previous week $previousWeek = date("W", strtotime("previous Week" . $weekStart)); $previousYear = date("Y", strtotime("previous Week" . $weekStart)); // Convert number of prev/next week to verbatim format - needed for correct << and >> button links $nextWeek = $nextYear . "/KW" . $nextWeek; $previousWeek = $previousYear . "/KW" . $previousWeek; $date = array('year' => $year, 'week' => $week, 'weekStart' => $weekStart, 'weekEnd' => $weekEnd, 'nextWeek' => $nextWeek, 'previousWeek' => $previousWeek); $events = ClubEvent::where('evnt_date_start', '>=', $weekStart)->where('evnt_date_start', '<=', $weekEnd)->with('getPlace', 'getSchedule.getEntries.getJobType', 'getSchedule.getEntries.getPerson.getClub')->orderBy('evnt_date_start')->orderBy('evnt_time_start')->get(); $tasks = Schedule::where('schdl_show_in_week_view', '=', '1')->where('schdl_due_date', '>=', $weekStart)->where('schdl_due_date', '<=', $weekEnd)->with('getEntries.getPerson.getClub', 'getEntries.getJobType')->get(); // TODO: don't use raw query, rewrite with eloquent. $persons = Cache::remember('personsForDropDown', 10, function () { $timeSpan = new DateTime("now"); $timeSpan = $timeSpan->sub(DateInterval::createFromDateString('3 months')); return Person::whereRaw("prsn_ldap_id IS NOT NULL \n\t\t\t\t\t\t\t\t\t\t AND (prsn_status IN ('aktiv', 'kandidat') \n\t\t\t\t\t\t\t\t\t\t OR updated_at>='" . $timeSpan->format('Y-m-d H:i:s') . "')")->orderBy('clb_id')->orderBy('prsn_name')->get(); }); $clubs = Club::orderBy('clb_title')->lists('clb_title', 'id'); // IDs of schedules shown, needed for bulk-update $updateIds = array(); foreach ($events as $event) { array_push($updateIds, $event->getSchedule->id); } return View::make('weekView', compact('events', 'schedules', 'date', 'tasks', 'entries', 'weekStart', 'weekEnd', 'persons', 'clubs')); }
/** * Creates a TicketEvolution_DateInterval from a DateInterval instance. * Makes it easy to pass in a standard PHP DateInterval to create an TicketEvolution_DateInterval * * NOTE: Even if the $dateInterval you pass in has the 'days' property set * it will be set to boolean false. Apparently you cannot extend * DateInterval and still use the 'days' property. This also means * that you cannot use format('%a') as it will return '(unknown)' * * @param DateInterval The DateInterval to create from * @return Onyx_DateInterval */ public function __construct($dateInterval) { if ($dateInterval instanceof DateInterval) { $period = 'P'; $time = 'T'; if ($dateInterval->y > 0) { $period .= $dateInterval->y . 'Y'; } if ($dateInterval->m > 0) { $period .= $dateInterval->m . 'M'; } if ($dateInterval->d > 0) { $period .= $dateInterval->d . 'D'; } if ($dateInterval->h > 0) { $time .= $dateInterval->h . 'H'; } if ($dateInterval->i > 0) { $time .= $dateInterval->i . 'M'; } if ($dateInterval->s > 0) { $time .= $dateInterval->s . 'S'; } if ($time != 'T') { $period .= $time; } parent::__construct($period); $this->invert = $dateInterval->invert; //$this->days = $dateInterval->days; } else { parent::__construct($dateInterval); } }
/** * Constructor * * @param string $start The start date of the period 'YYYY-mm-dd' * @param string $end optional End date * @param string $timezone optional Timezone * @throws \InvalidArgumentException */ public function __construct($start, $end = null, $timezone = 'UTC') { $this->mode = 'month'; $this->timezone = new DateTimeZone($timezone); $this->today = $this->getTodayDate(); $this->start = new DateTime($start instanceof DateTime ? $start->format('Y-m-d 00:00:00') : $start, $this->timezone); $this->end = !empty($end) ? new DateTime($end instanceof DateTime ? $end->format('Y-m-d 00:00:00') : $end, $this->timezone) : null; //Previous period is the previous month started from the the first day of the month $this->prevInterval = new \DateInterval('P1M'); $this->interval = '1 day'; $this->start = new DateTime($this->start->format('Y-m-01'), $this->timezone); $this->end = new DateTime($this->start->format('Y-m-t'), $this->timezone); $this->prevStart = clone $this->start; $this->prevStart->sub($this->prevInterval); $this->wholePeriodPerviousEnd = clone $this->prevStart; $this->wholePeriodPerviousEnd->modify('last day of this month'); $this->determinePrevEnd(); $endoftheday = new \DateInterval('PT23H59M59S'); $this->end->add($endoftheday); $this->prevEnd->add($endoftheday); $this->wholePeriodPerviousEnd->add($endoftheday); if (!$this->di) { $this->di = \DateInterval::createFromDateString($this->interval); } $this->dt = clone $this->start; }
function a(DateTime $start, DateTime $end) { $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($start, $interval, 1); $period = new DatePeriod($start, $interval, $end); $period = new DatePeriod('P1D'); }
/** * @dataProvider useCases * * @param $config */ public function test_UseCase($config) { date_default_timezone_set($config['timezone']); $timezone = new DateTimeZone($config['timezone']); $start = new DateTime($config['start'], $timezone); $end = new DateTime($config['end'], $timezone); $storage = new Storage(); $storage->setDefaultMiddleware($this->conn, new Logger(null)); $pipelineFactory = new Factory($this->conn); $pipeline = new Pipeline(); $cvs = []; $dateperiod = new DatePeriod($start, DateInterval::createFromDateString($config['insertResolution'] . ' seconds'), $end); foreach ($dateperiod as $datetime) { $cvs[] = new CounterValue($config['sid'], $config['nid'], $datetime, $config['val'], $config['incremental']); } $storage->store($cvs); $sequence = $pipelineFactory->createMultiAction($config['sid'], $config['nid'], $start, $end, $config['retrieveResolution'], $config['aggregation']); $sequence[] = new ConvertToDateStringKeys(); $valsByDate = $pipeline->run($sequence); $msg = $config['description']; $msg .= "\nExpected\n"; $msg .= json_encode($config['expected'], JSON_PRETTY_PRINT); $msg .= "\nActual:\n"; $msg .= json_encode($valsByDate, JSON_PRETTY_PRINT); $this->assertTrue($valsByDate === $config['expected'], $msg); }
/** * Generate chart * * @return array */ public function toArray() { $data = array(); $statistics = $this->getRepository()->getStatistics(); $commitsByContributor = $statistics['contributors']->getItems(); foreach ($commitsByContributor as $contributor) { $contributorInfo = null; $begin = new \DateTime($this->getRepository()->getFirstCommitDate()); $end = new \DateTime($this->getRepository()->getLastCommitDate()); $interval = \DateInterval::createFromDateString('1 day'); $period = new \DatePeriod($begin, $interval, $end); $commitsData = array(); $totalCommits = 0; $contributorCommits = $contributor->getItems(); foreach ($period as $date) { $dayFormatted = $date->format("Y-m-d"); $value = isset($contributorCommits[$dayFormatted]) ? count($contributorCommits[$dayFormatted]) : 0; if ($value > 0 && $contributorInfo === null) { $commit = $contributorCommits[$dayFormatted][0]; $contributorInfo = array('name' => $commit->getAuthor()->getName(), 'email' => $commit->getAuthor()->getEmail()); } $totalCommits += $value; $commitsData['x'][] = $dayFormatted; $commitsData['y'][] = $value; } $data[] = array('name' => $contributorInfo['name'], 'email' => $contributorInfo['email'], 'commits' => $totalCommits, 'data' => $commitsData); } usort($data, array($this, 'sortContributorsByCommits')); return $data; }
/** * Performs dates arithmetic * * @param string $interval * Each duration period is represented by an integer value followed by a period * designator. If the duration contains time elements, that portion of the * specification is preceded by the letter T. * Period Designators: Y - years, M - months, D - days, W - weeks, H - hours, * M - minutes, S - seconds. * Examples: two days - 2D, two seconds - T2S, six years and five minutes - 6YT5M. * The unit types must be entered from the largest scale unit on the left to the * smallest scale unit on the right. * Use first "-" char for negative periods. * OR * Relative period. * Examples: "+5 weeks", "12 day", "-7 weekdays", '3 months - 5 days' * * @return Date */ public function add($interval) { $i = null; try { $intervalTmp = strtoupper($interval); $isNegative = false; $firstChar = substr($intervalTmp, 0, 1); if ($firstChar === "-") { $isNegative = true; $intervalTmp = substr($intervalTmp, 1); $firstChar = substr($intervalTmp, 0, 1); } if ($firstChar !== "P") { $intervalTmp = "P" . $intervalTmp; } $i = new \DateInterval($intervalTmp); if ($isNegative) { $i->invert = 1; } } catch (\Exception $e) { } if ($i == null) { $i = \DateInterval::createFromDateString($interval); } $this->value->add($i); return $this; }
protected function setHistory($history = '-1 week') { $now = new \DateTime(); $prev = new \DateTime(); $prev->add(\DateInterval::createFromDateString($history)); $this->date = array($now, $prev); }
private function getDurationsByUser(WakaUser $user) { $settings = new Settings(); $settings->username = $user->username; $settings->password = $user->password; $waka = new Client($settings); $now = $this->time->now(); $weekAgo = $now - 7 * 86400; $lastFetch = $user->lastFetch; if (!$lastFetch) { $lastFetch = $weekAgo; } $today = date('Y-m-d', $now); $lastDate = date('Y-m-d', $lastFetch); if ($today > $lastDate) { $begin = new \DateTime($lastDate); $end = new \DateTime($today); $interval = \DateInterval::createFromDateString('1 day'); $period = new \DatePeriod($begin, $interval, $end); /** @var \DateTime $dt */ foreach ($period as $dt) { $date = $dt->format("Y-m-d"); echo $date, PHP_EOL; $this->getDurationsByUserAndDate($user, $waka, $date); $user->lastFetch = strtotime($date); $user->save(); } } }
public function formatWithoutZeroes() { // Each argument may have only one % parameter // Result does not handle %R or %r -- but you can retrieve that information using $this->format('%R') and using your own logic $parts = array(); foreach (func_get_args() as $arg) { $pre = mb_substr($arg, 0, mb_strpos($arg, '%')); $param = mb_substr($arg, mb_strpos($arg, '%'), 2); $post = mb_substr($arg, mb_strpos($arg, $param) + mb_strlen($param)); $num = intval(parent::format($param)); $open = preg_quote($this->pluralCheck[0], '/'); $close = preg_quote($this->pluralCheck[1], '/'); $pattern = "/{$open}(.*){$close}/"; list($pre, $post) = preg_replace($pattern, $num == 1 ? $this->singularReplacement : '$1', array($pre, $post)); if ($num != 0) { $parts[] = $pre . $num . $post; } } $output = ''; $l = count($parts); foreach ($parts as $i => $part) { $output .= $part . ($i < $l - 2 ? $this->separator : ($l == 2 ? $this->finalSeparator2 : ($i == $l - 2 ? $this->finalSeparator : ''))); } return $output; }
public function testTime() { /* This tests multiple formats. Ideally, all the format checking * should be done testing the date helper, but we'll do this * here for now. */ $forum = new Forum(); // Test #1, relative time $forumTime = '7 minutes ago'; $verifyTime = new \DateTime('NOW'); $verifyTime->add(\DateInterval::createFromDateString($forumTime)); $forum->setTime($forumTime); $this->assertEquals($verifyTime->format('Y-m-d\\TH:iO'), $forum->getTime()); // Test #2, partial date (same year) $forumTime = 'Jun 17, 1:01 PM'; $currentTime = new \DateTime('NOW'); $currentYear = $currentTime->format('Y'); $verifyTime = new \DateTime($currentYear . '-06-17 13:01'); $forum->setTime($forumTime); $this->assertEquals($verifyTime->format('Y-m-d\\TH:iO'), $forum->getTime()); // Test #3, full date $forumTime = ' May 1, 2014 1:19 PM'; $verifyTime = new \DateTime('2014-05-01 13:19'); $forum->setTime($forumTime); $this->assertEquals($verifyTime->format('Y-m-d\\TH:iO'), $forum->getTime()); }
function action_save() { global $current_user; //Get users date format $dateformat = $current_user->getPreference('datef'); //create datetime objects $startdate = DateTime::createFromFormat($dateformat, $_REQUEST['holiday_start_date']); $enddate = DateTime::createFromFormat($dateformat, $_REQUEST['holiday_end_date']); $enddate->modify('+1 day'); //1 day has to be added to include the last day as a holiday //Create an array of days between the start and end dates $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($startdate, $interval, $enddate); //loop through days and save new holiday record for each day. foreach ($period as $dt) { //format to default mysql date format $holiday_day = $dt->format('Y-m-d'); $this->bean = new AM_ProjectHolidays(); $this->bean->name = $_REQUEST['name']; $this->bean->description = $_REQUEST['description']; $this->bean->resourse_users = $_REQUEST['resourse_users']; $this->bean->holiday_date = $holiday_day; $this->bean->save(); } }
public function test_FiveMinResolutionSumTwoSeries_RollupSpace_ReturnSumForBothSeries() { $value1 = 10; $value2 = 20; $nDays = 20; $aggregation = Aggregation::SUM; $start = new DateTIme('2015-10-10 00:00:00'); $end = clone $start; $end->add(DateInterval::createFromDateString($nDays . ' days')); $dateperiod = new DatePeriod($start, DateInterval::createFromDateString('5 minutes'), $end); $vals1 = []; $vals2 = []; $expected = []; foreach ($dateperiod as $datetime) { $vals1[$datetime->getTimestamp()] = $value1; $vals2[$datetime->getTimestamp()] = $value2; $expected[$datetime->format('Y-m-d H:i:s')] = $value1 + $value2; } $series1 = new Series($vals1); $series2 = new Series($vals2); $convert = new ConvertToDateStringKeys(); $action = new RollupSpace($aggregation); $output = $action->run([$series1, $series2]); $output = $convert->run($output); $this->assertEquals($expected, $output); }
/** * Constructor * * @param string $start The start date of the period 'YYYY-mm-dd' * @param string $end optional End date * @param string $timezone optional Timezone * @throws \InvalidArgumentException */ public function __construct($start, $end = null, $timezone = 'UTC') { $this->mode = 'quarter'; $this->timezone = new DateTimeZone($timezone); $this->today = $this->getTodayDate(); $this->start = new DateTime($start instanceof DateTime ? $start->format('Y-m-d 00:00:00') : $start, $this->timezone); $this->end = !empty($end) ? new DateTime($end instanceof DateTime ? $end->format('Y-m-d 00:00:00') : $end, $this->timezone) : null; $quarters = new Quarters(SettingEntity::getQuarters()); $this->interval = '1 week'; $currentPeriod = $quarters->getPeriodForDate($this->start); $this->start = $currentPeriod->start; $this->end = $currentPeriod->end; $this->wholePeriodPerviousEnd = clone $this->start; $this->wholePeriodPerviousEnd->modify('-1 day'); $prevPeriod = $quarters->getPeriodForDate($this->wholePeriodPerviousEnd); $this->prevStart = $prevPeriod->start; $this->prevInterval = new \DateInterval('P' . sprintf("%d", $this->start->diff($this->end, true)->days) . 'D'); $this->determinePrevEnd(); $endoftheday = new \DateInterval('PT23H59M59S'); $this->end->add($endoftheday); $this->prevEnd->add($endoftheday); $this->wholePeriodPerviousEnd->add($endoftheday); if (!$this->di) { $this->di = \DateInterval::createFromDateString($this->interval); } $this->dt = clone $this->start; }