Get tasks from Toggl for $rundate.  Will set $rundate to yesterday if not supplied

@param string $startdate
@param string $enddate
@return array
@throws Exception
342652
public function getTimeEntries($startdate = null, $enddate = null)
    {
        if (empty($startdate)) {
            $startdate = date('Y-m-d', time() - 86400);
        }
        if (empty($enddate)) {
            $enddate = $startdate;
        }
        $this->uri = 'https://toggl.com/reports/api/v2/details?user_agent=' . $this->user_agent . '&since=' . $startdate . '&until=' . $enddate . '&workspace_id=' . $this->workspace_id;

        $data = null;
        
        $response = $this->processRequest($data, self::GET);
        $this->_handleError($data, $response);
        $toggl_entries = $this->processTogglResponse($response);
        $timeEntries = [];
        foreach ($toggl_entries as $entry) {
            $te = new TimeEntry(
                $this,
                $entry->id,
                $entry->client,
                $entry->project,
                $entry->description
            );
            $te->setEntryDate(date('Y-m-d', strtotime($entry->start)));
            $te->setDurationTime($entry->dur);
            $te->setTask($entry->task);
            $te->setDescription($entry->description);
            $te->processTags($entry->tags);
            $te->setBillable($entry->is_billable);
            $timeEntries[] = $te;
        }
        return $timeEntries;
    }
43605
public static function inBetween( $startDate, $endDate, $date ) {

		$start 	= is_string( $startDate ) ? strtotime( $startDate ) : $startDate->getTimestamp();
		$end 	= is_string( $endDate ) ? strtotime( $endDate ) : $endDate->getTimestamp();
		$test 	= is_string( $date ) ? strtotime( $date ) : $date->getTimestamp();

		// Test in between start and end
		return ( ( $test >= $start ) && ( $test <= $end ) );
	}
1282441
public static function getOrderStats(\DateTime $startDate, \DateTime $endDate, $status = null)
    {
        if ($status === null) {
            $status = OrderStatusQuery::getPaidStatusIdList();
        }

        return self::create()
            ->filterByStatusId($status, Criteria::IN)
            ->filterByCreatedAt(sprintf("%s 00:00:00", $startDate->format('Y-m-d')), Criteria::GREATER_EQUAL)
            ->filterByCreatedAt(sprintf("%s 23:59:59", $endDate->format('Y-m-d')), Criteria::LESS_EQUAL)
            ->count();
    }
124525
protected function processOptimalSubperiods($startDate, $endDate)
    {
        while ($startDate->isEarlier($endDate)
            || $startDate == $endDate
        ) {
            $week        = new Week($startDate);
            $startOfWeek = $week->getDateStart();
            $endOfWeek   = $week->getDateEnd();

            if ($endOfWeek->isLater($endDate)) {
                $this->fillDayPeriods($startDate, $endDate);
            } elseif ($startOfWeek == $startDate) {
                $this->addSubperiod($week);
            } else {
                $this->fillDayPeriods($startDate, $endOfWeek);
            }

            $startDate = $endOfWeek->addDay(1);
        }
    }
632859
protected function processOptimalSubperiods($startDate, $endDate)
    {
        while ($startDate->isEarlier($endDate)
            || $startDate == $endDate) {
            $endOfPeriod = null;

            $month        = new Month($startDate);
            $endOfMonth   = $month->getDateEnd();
            $startOfMonth = $month->getDateStart();

            $year        = new Year($startDate);
            $endOfYear   = $year->getDateEnd();
            $startOfYear = $year->getDateStart();

            if ($startDate == $startOfYear
                && ($endOfYear->isEarlier($endDate)
                    || $endOfYear == $endDate
                    || $endOfYear->isLater($this->today)
                )
                // We don't use the year if
                // the end day is in this year, is before today, and year not finished
                && !($endDate->isEarlier($this->today)
                    && $this->today->toString('Y') == $endOfYear->toString('Y')
                    && $this->today->compareYear($endOfYear) == 0)
            ) {
                $this->addSubperiod($year);
                $endOfPeriod = $endOfYear;
            } elseif ($startDate == $startOfMonth
                && ($endOfMonth->isEarlier($endDate)
                    || $endOfMonth == $endDate
                    || $endOfMonth->isLater($this->today)
                )
                // We don't use the month if
                // the end day is in this month, is before today, and month not finished
                && !($endDate->isEarlier($this->today)
                    && $this->today->toString('Y') == $endOfMonth->toString('Y')
                    && $this->today->compareMonth($endOfMonth) == 0)
            ) {
                $this->addSubperiod($month);
                $endOfPeriod = $endOfMonth;
            } else {
                // From start date,
                //  Process end of week
                $week        = new Week($startDate);
                $startOfWeek = $week->getDateStart();
                $endOfWeek   = $week->getDateEnd();

                $firstDayNextMonth      = $startDate->addPeriod(2, 'month')->setDay(1);
                $useMonthsNextIteration = $firstDayNextMonth->isEarlier($endDate);

                if ($useMonthsNextIteration
                    && $endOfWeek->isLater($endOfMonth)
                ) {
                    $this->fillArraySubPeriods($startDate, $endOfMonth, 'day');
                    $endOfPeriod = $endOfMonth;
                } //   If end of this week is later than end date, we use days
                elseif ($this->isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) &&
                    ($endOfWeek->isEarlier($this->today)
                        || $startOfWeek->toString() != $startDate->toString()
                        || $endDate->isEarlier($this->today))
                ) {
                    $this->fillArraySubPeriods($startDate, $endDate, 'day');
                    break 1;
                } elseif ($startOfWeek->isEarlier($startDate)
                    && $endOfWeek->isEarlier($this->today)
                ) {
                    $this->fillArraySubPeriods($startDate, $endOfWeek, 'day');
                    $endOfPeriod = $endOfWeek;
                } else {
                    $this->addSubperiod($week);
                    $endOfPeriod = $endOfWeek;
                }
            }
            $startDate = $endOfPeriod->addDay(1);
        }
    }
1033008
protected function getVisitsViewsUsersForPeriod(
        DateTime $startDate,
        DateTime $endDate
    ) {
        $cacheName = md5(serialize('visits-views-users'
            .$startDate->format('Y-m-d').$endDate->format('Y-m-d')));

        $urlParams = [
            'ids'        => $this->counter_id,
            'date1'      => $startDate->format('Y-m-d'),
            'date2'      => $endDate->format('Y-m-d'),
            'metrics'    => 'ym:s:visits,ym:s:pageviews,ym:s:users',
            'dimensions' => 'ym:s:date',
            'sort'       => 'ym:s:date',
        ];

        $this->data = $this->request($urlParams, $cacheName);
    }
1165305
protected static function calculateEndDate( $startDate, $durationDays )
	{
		$time	= strtotime( $startDate ) + $durationDays * 24 * 60 * 60;
		$time	= date( "Y-m-d", $time );
		return $time;
	}
1134911
public function getDateAdjustedStartTimes(\DateTime $startDate, $num_days)
    {
        $array = array();

        for ($i=0; $i<$num_days; $i++)
        {
            $startDate->add(\DateInterval::createFromDateString('+1 day'));

            if ($startDate->format('N') == $this->getDayOfWeekNumber())
            {
                $dayOfWeek = new DayOfWeek($startDate->format('N'));

                $startTime = $this->getStartTimeObject($startDate->format('Y-m-d'));

                while ($startTime->format('H:i') < $this->getEndTime())
                {
                    $array[] = clone $startTime;

                    $startTime->add(\DateInterval::createFromDateString('+2 hours'));
                }
            }
        }

        return $array;
    }
301352
public function getEmailStats($date, $endDate = null, $aggregatedBy = null)
    {
        $url = $this->getApiEndpoint() . '/v2/email/stats/since-date/' . $date;
        if ($endDate && $aggregatedBy) {
            $url .= '?endDate=' . $endDate . '&aggregatedBy=' . $aggregatedBy;
        }

        $response = $this->setUrl($url)
            ->setVerb('GET')
            ->execute();

        if (isset($response->message)) {
            $this->helper->log('GET EMAIL STATS : ' . $response->message);
        }

        return $response;
    }
132783
public function performQuery(string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = [])
    {
        $cacheName = $this->determineCacheName(func_get_args());

        if ($this->cacheLifeTimeInMinutes == 0) {
            $this->cache->forget($cacheName);
        }

        return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use ($viewId, $startDate, $endDate, $metrics, $others) {
            $result = $this->service->data_ga->get(
                "ga:{$viewId}",
                $startDate->format('Y-m-d'),
                $endDate->format('Y-m-d'),
                $metrics,
                $others
            );

            while ($nextLink = $result->getNextLink()) {
                if (isset($others['max-results']) && count($result->rows) >= $others['max-results']) {
                    break;
                }

                $options = [];

                parse_str(substr($nextLink, strpos($nextLink, '?') + 1), $options);

                $response = $this->service->data_ga->call('get', [$options], 'Google_Service_Analytics_GaData');

                if ($response->rows) {
                    $result->rows = array_merge($result->rows, $response->rows);
                }

                $result->nextLink = $response->nextLink;
            }

            return $result;
        });
    }
371671
public static List<String> getDayListBetween2Day(String startDate, String endDate, Format format) {
        List<String> dayList = new ArrayList<String>();
        int dataNum = Integer.parseInt(getTwoDay2String(startDate, endDate, format));
        for (int i = 0; i < (dataNum + 1); i++) {
            String resultDate = getNextDay2String(startDate, String.valueOf(i), format);
            dayList.add(resultDate);
        }
        return dayList;
    }
1334952
public function reportCampaignList($start_date, $end_date, $show_hidden)
		{
			$form_data = array(
				'from_date' => $start_date,
				'to_date' => $end_date,
				'show_hidden' => $show_hidden
			);
			$xml = $this->call('rpt_campaign_list', $form_data);

			$campaigns = array();

			foreach ($xml->Data as $campaign_item) {
				$campaign = new Report();
				$campaign
					->setCampaignId((int)$campaign_item->campaign_id)
					->setListId((int)$campaign_item->list_id)
					->setListName((string)$campaign_item->list_name)
					->setSubject((string)$campaign_item->subject)
					->setDate(\DateTime::createFromFormat('Y/m/d H:i:s', $campaign_item->deploy_date)) //2016-02-01 11:16:33
					->setRecipients((int)$campaign_item->pieces_sent)
					->setTaskId((int)$campaign_item->task_id);

				$campaigns[] = $campaign;
			}
			return $campaigns;
		}
344317
public static function getSecondsCount($beginDate, $endDate)
    {
        // Get minutes count
        $minutes = static::getMinutesCount($beginDate, $endDate);

        // Get seconds
        $diff = $endDate->diff($beginDate);
        $seconds = $diff->s;

        // Return all seconds
        return $seconds + $minutes * 60;
    }
245477
public static function normalize(\DateTime $startDate = null, \DateTime $endDate = null)
    {
        if (!empty($startDate) || !empty($endDate)) {
            return [
                DateNormalizer::normalize($startDate),
                DateNormalizer::normalize($endDate),
            ];
        }

        return [];
    }
81178
public function fire(Carbon $startDate, Carbon $endDate)
    {
        $this->start = $startDate;
        $this->end   = $endDate;

        return $this->getData();
    }
844381
private function createTimestampCalendar(
        DateTimeInterface $startDate,
        DateTimeInterface $endDate,
        CultureFeed_Cdb_Data_Calendar_TimestampList $calendar,
        $index = null
    ) {
        // Make a clone of the original calendar to avoid updating input param.
        $newCalendar = clone $calendar;

        $first24Hours = Period::createFromDuration($startDate, new DateInterval('P1D'));

        // Easy case an no seconds needed for indexing.
        if ($first24Hours->contains($endDate)) {
            $newCalendar->add(
                new CultureFeed_Cdb_Data_Calendar_Timestamp(
                    $startDate->format('Y-m-d'),
                    $this->formatDateTimeAsCdbTime($startDate),
                    $this->formatDateTimeAsCdbTime($endDate)
                )
            );
        } elseif (is_int($index)) {
            // Complex case and seconds needed for indexing.
            $period = new Period($startDate, $endDate);

            $startTimestamp = new CultureFeed_Cdb_Data_Calendar_Timestamp(
                $startDate->format('Y-m-d'),
                $this->formatDateTimeAsCdbTime($startDate, $index)
            );

            $endTimestamp = new CultureFeed_Cdb_Data_Calendar_Timestamp(
                $endDate->format('Y-m-d'),
                $this->createIndexedTimeString($index),
                $this->formatDateTimeAsCdbTime($endDate)
            );

            $untilEndOfSecondDay = new Period(
                $startDate,
                Chronos::instance($startDate)->addDay()->endOfDay()
            );

            if ($untilEndOfSecondDay->contains($endDate)) {
                $fillerTimestamps = [];
            } else {
                $days = iterator_to_array($period->getDatePeriod('1 DAY'));
                $fillerTimestamps = array_map(
                    function (DateTimeInterface $dateTime) use ($index) {
                        return new CultureFeed_Cdb_Data_Calendar_Timestamp(
                            $dateTime->format('Y-m-d'),
                            $this->createIndexedTimeString($index)
                        );
                    },
                    array_slice($days, 1, count($days) === 2 ? 2 : -1)
                );
            }

            $newCalendar = array_reduce(
                array_merge([$startTimestamp], $fillerTimestamps, [$endTimestamp]),
                function (CultureFeed_Cdb_Data_Calendar_TimestampList $calendar, $timestamp) {
                    $calendar->add($timestamp);
                    return $calendar;
                },
                $newCalendar
            );
        }

        return $newCalendar;
    }
365598
public function getOneTimeEvents($starttime = null, $endtime = null) {

		if (is_null($starttime)) {
			$starttime = time();
		}
		if (is_null($endtime)) {
			$endtime = strtotime('+1 year', $starttime);
		}

		$starttime = sanitize_int($starttime);
		$endtime = sanitize_int($endtime);
		$relationship_name = sanitize_string(self::EVENT_CALENDAR_RELATIONSHIP);

		$dbprefix = elgg_get_config('dbprefix');

		// for performance we'll denormalize metastrings first
		$mdr_name = elgg_get_metastring_id('repeat');
		$mdr_val = elgg_get_metastring_id(0);
		$mds_name = elgg_get_metastring_id('start_timestamp');
		$mde_name = elgg_get_metastring_id('end_timestamp');
		$options = array(
			'type' => 'object',
			'subtype' => Event::SUBTYPE,
			'joins' => array(
				"JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid", // calendar relationship
				"JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid", // repeating metadata
				"JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid", // start time metadata
				"JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id", // start time metastring
				"JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid", // end time metadata
				"JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id" // end time metastring
			),
			'wheres' => array(
				"er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'",
				"mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}",
				"mds.name_id = {$mds_name}",
				"mde.name_id = {$mde_name}",
				"((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime})
					OR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))"
			),
			'limit' => false
		);

		return new ElggBatch('elgg_get_entities', $options);
	}