Return a random datetime from the past, optionally restricted to a lower bound

@param string $sLow The lowest possible datetime to return

@return string
334734
protected function randomPastDateTime($sLow = null)
    {
        $oNow = Factory::factory('DateTime');
        return $this->randomDateTime($sLow, $oNow->format('Y-m-d H:i:s'));
    }
298787
public static function getDateTime($datetime = null)
    {
        if ($datetime instanceof \DateTime) {
            return clone $datetime;
        }
        if ($datetime instanceof \DateTimeImmutable) {
            return new \DateTime($datetime->format(\DateTime::ATOM));
        }
        if (\is_string($datetime)) {
            if (\is_numeric($datetime)) {
                /*
                    check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS
                    Debug::_log('datetime', $datetime)
                */
                $isTs = !preg_match('/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/', $datetime);
                if ($isTs) {
                    $datetime = '@'.$datetime;
                }
            }
            Debug::_log('datetime', $datetime);
            return new \DateTime($datetime);
        }
        if (\is_int($datetime) || \is_float($datetime)) {
            $dateTime = new \DateTime();
            $dateTime->setTimestamp($datetime);
            return $dateTime;
        }
        return new \DateTime();
    }
1191551
protected function DESC($limit = NULL)
    {
        $value = array_reverse($this->value);
        if ($limit === NULL) {
            return $value;
        } else {
            return array_slice($value, 0, $limit);
        }
    }
631949
public static function GetCurrentDateTime( $context )
	{
		$res = DateTimeValue::fromDate( false, new \DateTime( "@" . $context->RunningContext->now ) );
		$res->Value->microseconds = 0;
		$res->IsLocal = false;
		return $res;
	}
747451
public static function GetCurrentDate( $context )
	{
		$res = DateValue::fromDate( false, new \DateTime( "@" . $context->RunningContext->now ) );
		$res->IsLocal = false;
		$res->Value->microseconds = 0;
		return $res;
	}
241773
function get_first_date_last_year($y=1) {
    return $this->mdate($this->dateFormat, mktime(0, 0, 0, 1, 1, $this->mdate("Y")-$y));
  }
304348
public static function getNowDateTime()
    {
        if (PHP_VERSION_ID < 70100) {
            $now = \DateTime::createFromFormat('U.u', \sprintf('%.6F', microtime(true)));
        } else {
            $now = new \DateTime(null);
        }

        return $now;
    }
136341
public function lastEarnedDate() : \DateTime
    {
        return new \DateTime(
            $this->comparing() ?
            $this->group->comparedUser->lastUpdateDate :
            $this->group->fromUser->lastUpdateDate
        );
    }
521288
public function slowLogGet(?int $count = null)
    {
        if ($count) {
            return $this->handle->slowlog("get $count");
        }
        return $this->handle->slowlog('get');
    }
468410
protected static function getDateTime()
    {
        // Lazyload
        if (null === self::$dateTime) {
            /* @var Doozr_Datetime_Service self::$dateTime */
            self::$dateTime = Doozr_Loader_Serviceloader::load('datetime');
        }

        return self::$dateTime;
    }
56277
public function earnedDate() : ?\DateTime
    {
        if (!$this->earned()) return null;

        return new \DateTime(
            $this->comparing() ?
            $this->trophy->comparedUser->earnedDate :
            $this->trophy->fromUser->earnedDate
        );
    }
850464
public function getLastUpdatedAt()
    {
        $qb = $this->createQueryBuilder('p');

        $date = $qb
            ->select('p.updatedAt')
            ->addOrderBy('p.updatedAt', 'DESC')
            ->getQuery()
            ->setMaxResults(1)
            ->getSingleScalarResult();

        if (null !== $date) {
            return new \DateTime($date);
        }

        return null;
    }
837675
public static function longDate($timestamp = null)
    {
        $l = self::getLocale();
        return self::date($l->shortDateTime, $timestamp);
    }
597482
public static function datetime($time = null, $nowIfNull = true, $format = 'Y-m-d H:i:s')
    {
        if (empty($time)) {
            return $nowIfNull ? date($format) : null;
        } else {
            return date($format, $time);
        }
    }
37478
public function offsetDatetime($time = null, $offset = 0)
    {
        if ($this->timeFormat === static::$timeFormatDatetime) {
            return date('Y-m-d H:i:s', strtotime(($offset >= 0 ? "+$offset" : $offset) . " seconds", is_string($time) ? strtotime($time) : (is_int($time) ? $time : time())));
        }
        if ($this->timeFormat === static::$timeFormatTimestamp) {
            return (is_int($time) ? $time : time()) + $offset;
        }
        return null;
    }
1010916
public static function denormalize($dateString = null)
    {
        if (!empty($dateString)) {
            try {
                $dateTime = \DateTime::createFromFormat(static::DATE_FORMAT, $dateString);

                return $dateTime;
            } catch (\Exception $e) {
            }
        }

        return null;
    }
1328369
public function getUpdatedAtDatetime(string $timezone = null): ?DateTime
    {
        if (!$this->hasUpdatedAt()) {
            return null;
        }

        if ($timezone === null) {
            $timezone = 'UTC';
        }

        return new DateTime($this->getUpdatedAt(), new DateTimeZone($timezone));
    }