Get locked documents for a date range or all documents if no date range is given
@param string $fromDateTime
@param string $tillDateTime
@return array
357350
public function getLockedDocuments($fromDateTime = null , $tillDateTime = null)
    {
        $query = array();
        if(!empty($fromDateTime) || !empty($tillDateTime)){
            $query[_LOCKED_FOR_TRANS_TS] = array();

            if (!empty($fromDateTime)) {
                $query[_LOCKED_FOR_TRANS_TS][MONGO_OPERATION_GTE] = \Tripod\Mongo\DateUtil::getMongoDate(strtotime($fromDateTime)*1000);
            }
            if (!empty($tillDateTime)) {
                $query[_LOCKED_FOR_TRANS_TS][MONGO_OPERATION_LTE] = \Tripod\Mongo\DateUtil::getMongoDate(strtotime($tillDateTime)*1000);
            }
        }
        $docs = $this->getLocksCollection()->find($query, array('sort' => array(_LOCKED_FOR_TRANS => 1)));

        if($this->getLocksCollection()->count($query) == 0 ) {
            return array();
        }

        $res = array();
        foreach($docs as $doc){
            $res[] = $doc;
        }
        return $res;
    }
607403
public function getWallets($merchantGroupId, DateTime $pastDate = null)
    {
        if (!$pastDate) {
            $pastDate = new DateTime('1970-01-01');
        }
        return $this->hipay->getMerchantsGroupAccounts($merchantGroupId, $pastDate);
    }
955893
protected function processRecurringEvents(\DateTime $fromDate, \DateTime $toDate, $limit = null)
	{
		if ($this->recurrenceFactory) {
			foreach ($this->recurrenceFactory->getRecurrenceTypes() as $recurrence) {
				$recurrenceType = new $recurrence();

				$occurrences = $recurrenceType->generateOccurrences($this->recurrentEvents, $fromDate, $toDate, $limit);

				$this->recurrentEvents = array_merge($this->recurrentEvents, $occurrences);
			}
		}

		// Remove recurring events that do not occur within the date range
		$this->recurrentEvents = array_filter($this->recurrentEvents, function ($event) use ($fromDate, $toDate) {

			if (! $event->getRecurrenceType()) {
				return true;
			} elseif ($event->getStartDate() <= $toDate  && $event->getEndDate() >= $fromDate) {
				return true;
			}

			return false;
		});

		$this->allEvents = array_merge($this->allEvents, $this->recurrentEvents);
	}
93445
protected function dateDiffNoDST(\DateTime $from, \DateTime $to)
    {
        $fromUTC = new \DateTime($from->format('Y-m-d\TH:i:s+00:00'));
        $toUTC = new \DateTime($to->format('Y-m-d\TH:i:s+00:00'));

        return $fromUTC->diff($toUTC);
    }
863836
private function getAttaches($to, $from) {
		for ($i = 0; $i < count($from); $i++) {
			$line = $from[$i]['values'];
			$to[] = $line;
		}
		return $to;
	}
951658
protected static function rangeFromBoundaryAddresses(AddressInterface $from = null, AddressInterface $to = null)
    {
        if ($from === null && $to === null) {
            $result = null;
        } elseif ($to === null) {
            $result = Range\Single::fromAddress($from);
        } elseif ($from === null) {
            $result = Range\Single::fromAddress($to);
        } else {
            $result = null;
            $addressType = $from->getAddressType();
            if ($addressType === $to->getAddressType()) {
                $cmp = strcmp($from->getComparableString(), $to->getComparableString());
                if ($cmp === 0) {
                    $result = Range\Single::fromAddress($from);
                } else {
                    if ($cmp > 0) {
                        list($from, $to) = array($to, $from);
                    }
                    $fromBytes = $from->getBytes();
                    $toBytes = $to->getBytes();
                    $numBytes = count($fromBytes);
                    $sameBits = 0;
                    for ($byteIndex = 0; $byteIndex < $numBytes; ++$byteIndex) {
                        $fromByte = $fromBytes[$byteIndex];
                        $toByte = $toBytes[$byteIndex];
                        if ($fromByte === $toByte) {
                            $sameBits += 8;
                        } else {
                            $differentBitsInByte = decbin($fromByte ^ $toByte);
                            $sameBits += 8 - strlen($differentBitsInByte);
                            break;
                        }
                    }
                    $result = static::rangeFromString($from->toString(true).'/'.(string) $sameBits);
                }
            }
        }

        return $result;
    }
195902
private function getInvoices(DateTime $startDate, DateTime $endDate)
    {
        $offset = Mirakl::MIRAKL_API_MAX_PAGINATE;

        $invoicesData = $this->mirakl->getInvoices(
            $startDate,
            $endDate
        );

        $invoices = array_merge(array(), $invoicesData['invoices']);

        $total = $invoicesData['total_count'];

        while ($total % $offset !== $total) {

            $invoicesData = $this->mirakl->getInvoices(
                $startDate,
                $endDate,
                Mirakl::MIRAKL_API_MAX_PAGINATE,
                $offset
            );

            $invoices = array_merge($invoices, $invoicesData['invoices']);

            $offset += Mirakl::MIRAKL_API_MAX_PAGINATE;
        }

        return $invoices;
    }
42844
private function between(\DateTime $time, DateTimeFormatInterface $start, DateTimeFormatInterface $end)
    {
        return $this->after($time, $start) && $this->before($time, $end);
    }
1288438
public function limitTo(int $from, int $until) {
		// build the limit to 
		$this->Limit = array($from, $until);
		// return self to the next method
		return $this;
	}
792367
public static function getDecadesAgo($ago, $endDateTime = null)
    {
        return static::getDateTimeRange(
            Carbon::now()->subYears($ago * 10)->startOfDecade(),
            $endDateTime ?: Carbon::now()->subYears($ago * 10)->endOfDecade()
        );
    }
553057
public function getReportQuery($siteId, $fromDate, $toDate, $filter, $limit = null)
    {
        $siteList = [];
        $filter   = strtolower($filter);

        if (empty($fromDate)) {
            $fromDate = (new DateTime('first day of the year'))->format('Y-m-d');
        }

        if (empty($toDate)) {
            $toDate = (new DateTime('last day of this month'))->format('Y-m-d');
        }

        $builder = $this->getEntityManager()->createQuerybuilder();
        $query   = $builder->select(
            [
                '(e.popularity) total',
                'DATE(e.rankedAt) regDay',
                's.domain domain',
                '1 valid',
                'e.rankedAt createdAt',
            ]
        )->from($this->getEntity(), 'e')
            ->innerJoin('e.site', 's')
            ->where('e.rankedAt >= :start')
            ->andWhere('e.rankedAt <= :end')
            //->andWhere('s.siteType = :siteType')
            ->addOrderBy('e.rankedAt')
            ->addOrderBy('e.popularity')
            ->addGroupBy('e.site')
            ->setParameters(
                [
                    ':start'    => $fromDate,
                    ':end'      => $toDate,
                   // ':siteType' => 1,
                ]
            );

        if ($siteId) {
            $siteList = array_filter(array_unique(array_merge($siteList, (array)$siteId)));
        } elseif ($limit) {
            $subQueryBuilder = $builder = $this->getEntityManager()->createQuerybuilder();
            $subQuery        = $subQueryBuilder->select('f.id, s.id site_id')
                ->from($this->getEntity(), 'f')
                ->innerJoin('f.site', 's')
                ->groupBy('s.id')
                ->orderBy('f.popularity', 'ASC')
                ->setMaxResults($limit);

            foreach ($subQuery->getQuery()->getArrayResult() as $item) {
                $siteList[] = $item['site_id'];
            }
        }

        if ($siteList) {
            $query->andWhere($builder->expr()->in('s.id', $siteList));
        }
        switch ($filter) {
            case 'year':
                $query->addSelect('YEAR(e.rankedAt) regYear')
                    ->addGroupBy('regYear');
                break;
            case 'month':
                $query->addSelect('Month(e.rankedAt) regMonth')
                    ->addGroupBy('regMonth');
                break;
            case 'week':
                $query->addSelect('WEEK(e.rankedAt) regWeek')
                    ->addGroupBy('regWeek');
                break;
            case 'hour':
                $query->addSelect('HOUR(e.rankedAt) regHour')
                    ->addGroupBy('regHour');
                break;
            case 'day':
            default:
                $query->addGroupBy('regDay');
        }

        return $query->getQuery()->getArrayResult();
    }
799757
protected static function getLockData()
    {
        if ( null === static::$lockData )
        {
            $data = Json::decode(
                file_get_contents( static::LOCK_FILE ),
                Json::TYPE_ARRAY
            );

            if ( empty( $data ) )
            {
                static::$lockData = array();
            }
            else
            {
                static::$lockData = (array) $data;
            }
        }

        return static::$lockData;
    }
1165670
public static function dateDiff($from, $to = null)
    {
        if (!$to) {
            $to = $from;
            $from = date("d/m/Y");
        }

        if (!$dateFrom = static::date("U", $from)) {
            return;
        }

        if (!$dateTo = static::date("U", $to)) {
            return;
        }

        $diff = $dateTo - $dateFrom;
        $days = round($diff / 86400);

        return $days;
    }
1307371
protected function getDocBlock(Stmt $stmt, array $uses = []): ?array
    {
        $comments = $stmt->getAttribute('comments');

        if (is_array($comments)) {
            foreach ($comments as $comment) {
                if ($comment instanceof Doc) {
                    return $this->processDocBlock($comment->getText(), $uses);
                }
            }
        }

        return null;
    }
573666
private function isBetween($timestamp, $fromTime, $toTime, $format = 'Hi')
    {
        $dateTime = new DateTime();
        $timezone = new DateTimeZone('UTC');
        $dtRef = $dateTime->createFromFormat('U', $timestamp, $timezone);
        $dtFrom = $dateTime->createFromFormat($format, $fromTime, $timezone);
        $dtTo = $dateTime->createFromFormat($format, $toTime, $timezone);
        if ($dtFrom > $dtTo) {
            $dtTo->modify('+1 day');
        }
        return (
                $dtFrom <= $dtRef &&
                $dtRef <= $dtTo
            ) || (
                $dtFrom <= $dtRef->modify('+1 day') &&
                $dtRef <= $dtTo
            );
    }
533883
public static function getRelTime($datetime, $datetimeFrom = null)
    {
        $ret = '';
        $dateTime = self::getDateTime($datetime);
        $dateTimeFrom = self::getDateTime($datetimeFrom);
        $dateTimeSameDay = clone $dateTimeFrom;
        $dateTimeSameDay->setTime(0, 0, 0);
        $diffSec = $dateTimeFrom->getTimestamp() - $dateTime->getTimestamp();
        if ($dateTime > $dateTimeFrom) {
            // Future
            $dateTimeTest = clone $dateTimeSameDay;
            if ($dateTime < $dateTimeTest->modify('tomorrow')) {
                $ret = 'Today at '.$dateTime->format('g:ia');
            } elseif ($dateTime < $dateTimeTest->modify('+2 days')) {
                $ret = 'Tomorrow at '.$dateTime->format('g:ia');
            } else {
                $ret = $dateTime->format('F jS');
            }
        } elseif ($diffSec < 60) {
            // within a min
            $ret = 'Just now';
        } elseif ($diffSec < 3600) {
            // within an hour
            $ret = \round(($diffSec)/60) .' min ago';
        } elseif ($diffSec < 3600*6) {
            // within 6 hours
            $hrs = \round(($diffSec)/3600);
            $ret = $hrs.' '.Str::plural($hrs, 'hour').' ago';
        } elseif ($dateTime > $dateTimeSameDay) {             // since midnight so it's today
            $ret = 'Today at '.$dateTime->format('g:ia');
        } elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400) {
            $ret = 'Yesterday at '.$dateTime->format('g:ia');
        } elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400*7) {
            $ret = $dateTime->format('l \a\t g:ia');
        } elseif ($dateTime->getTimestamp() > \mktime(0, 0, 0, 1, 1)) {// since 1st Jan so it's this year
            $ret = $dateTime->format('F jS');
        } else {                                // last year..
            $ret = $dateTime->format('F jS, Y');
        }
        $ret = \str_replace(' at 12:00am', '', $ret);
        return $ret;
    }
197107
public static function getTimestamp($dateTime = null)
    {
        return $dateTime ? is_numeric($dateTime) ? $dateTime : strtotime($dateTime) : time();
    }