libretime/legacy/application/common/DateHelper.php

514 lines
16 KiB
PHP
Raw Permalink Normal View History

2011-02-05 00:22:15 +01:00
<?php
class Application_Common_DateHelper
2011-02-05 00:22:15 +01:00
{
private $_dateTime;
2021-10-11 16:10:47 +02:00
public function __construct()
{
2021-10-11 16:10:47 +02:00
$this->_dateTime = date('U');
}
/**
* Get time of object construction in the format
2021-10-11 16:10:47 +02:00
* YYYY-MM-DD HH:mm:ss.
*/
2021-10-11 16:10:47 +02:00
public function getTimestamp()
{
return date(DEFAULT_TIMESTAMP_FORMAT, $this->_dateTime);
}
/**
* Get time of object construction in the format
2021-10-11 16:10:47 +02:00
* YYYY-MM-DD HH:mm:ss.
*/
2021-10-11 16:10:47 +02:00
public function getUtcTimestamp()
{
return gmdate(DEFAULT_TIMESTAMP_FORMAT, $this->_dateTime);
}
/**
* Get date of object construction in the format
2021-10-11 16:10:47 +02:00
* YYYY-MM-DD.
*/
2021-10-11 16:10:47 +02:00
public function getDate()
{
2021-10-11 16:10:47 +02:00
return gmdate('Y-m-d', $this->_dateTime);
}
/**
* Get time of object construction in the format
2021-10-11 16:10:47 +02:00
* HH:mm:ss.
*/
2021-10-11 16:10:47 +02:00
public function getTime()
{
2021-10-11 16:10:47 +02:00
return gmdate('H:i:s', $this->_dateTime);
}
2021-10-11 16:10:47 +02:00
/** Get the abbreviated timezone for the currently logged in user.
* @return string A string containing the short form of the timezone set in the preferences for the current user (eg. EST, CEST, etc.)
*/
public static function getUserTimezoneAbbreviation()
{
return self::getTimezoneAbbreviation(Application_Model_Preference::GetUserTimezone());
}
2021-10-11 16:10:47 +02:00
/** Get the abbreviated timezone string of the timezone the station is set to.
* @return string A string containing the short form of the station's timezone (eg. EST, CEST, etc.)
*/
public static function getStationTimezoneAbbreviation()
{
return self::getTimezoneAbbreviation(Application_Model_Preference::GetDefaultTimezone());
}
2021-10-11 16:10:47 +02:00
private static function getTimezoneAbbreviation($fullTimeZoneName)
{
$timeZone = new DateTimeZone($fullTimeZoneName);
2021-10-11 16:10:47 +02:00
$now = new DateTime('now', $timeZone);
return $now->format('T');
}
2021-10-11 16:10:47 +02:00
public static function getUserTimezoneOffset()
{
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
2021-10-11 16:10:47 +02:00
$now = new DateTime('now', $userTimezone);
return $now->format('Z');
}
2021-10-11 16:10:47 +02:00
public static function getStationTimezoneOffset()
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
2021-10-11 16:10:47 +02:00
$now = new DateTime('now', $stationTimezone);
return $now->format('Z');
}
2021-10-11 16:10:47 +02:00
/**
* @return DateTime - YYYY-MM-DD 00:00 in station timezone of today
*/
public static function getTodayStationStartDateTime()
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
2021-10-11 16:10:47 +02:00
$now = new DateTime('now', $stationTimezone);
$now->setTime(0, 0, 0);
2021-10-11 16:10:47 +02:00
return $now;
}
2021-10-11 16:10:47 +02:00
/**
* @return DateTime - YYYY-MM-DD 00:00 in station timezone of tomorrow
*/
public static function getTodayStationEndDateTime()
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
2021-10-11 16:10:47 +02:00
$now = new DateTime('now', $stationTimezone);
$now->add(new DateInterval('P1D'));
$now->setTime(0, 0, 0);
2021-10-11 16:10:47 +02:00
return $now;
}
2021-10-11 16:10:47 +02:00
/**
* @return DateTime - YYYY-MM-DD 00:00 in station timezone
*/
public static function getWeekStartDateTime()
{
$now = self::getTodayStationStartDateTime();
2021-10-11 16:10:47 +02:00
// our week starts on monday, but php week starts on sunday.
$day = $now->format('w');
if ($day == 0) {
$day = 7;
}
2021-10-11 16:10:47 +02:00
$dayDiff = $day - 1;
if ($dayDiff > 0) {
$now->sub(new DateInterval("P{$dayDiff}D"));
}
2021-10-11 16:10:47 +02:00
return $now;
}
/**
2021-10-11 16:10:47 +02:00
* This function formats a time by removing seconds.
*
* When we receive a time from the database we get the
* format "hh:mm:ss". But when dealing with show times, we
* do not care about the seconds.
*
* @param int $p_dateTime
2021-10-11 16:10:47 +02:00
* The value which to format
*
* @return int
2021-10-11 16:10:47 +02:00
* The timestamp with the new format "hh:mm", or
* the original input parameter, if it does not have
* the correct format
*/
public static function removeSecondsFromTime($p_dateTime)
{
// Format is in hh:mm:ss. We want hh:mm
2021-10-11 16:10:47 +02:00
$timeExplode = explode(':', $p_dateTime);
if (count($timeExplode) == 3) {
return $timeExplode[0] . ':' . $timeExplode[1];
}
2021-10-11 16:10:47 +02:00
return $p_dateTime;
}
/* Given a track length in the format HH:MM:SS.mm, we want to
* convert this to seconds. This is useful for Liquidsoap which
* likes input parameters give in seconds.
* For example, 00:06:31.444, should be converted to 391.444 seconds
* @param int $p_time
* The time interval in format HH:MM:SS.mm we wish to
* convert to seconds.
* @return float
* The input parameter converted to seconds.
*/
2021-10-11 16:10:47 +02:00
public static function calculateLengthInSeconds($p_time)
{
if (2 !== substr_count($p_time, ':')) {
return false;
}
2021-10-11 16:10:47 +02:00
if (1 === substr_count($p_time, '.')) {
[$hhmmss, $ms] = explode('.', $p_time);
} else {
$hhmmss = $p_time;
$ms = 0;
}
[$hours, $minutes, $seconds] = explode(':', $hhmmss);
2021-10-11 16:10:47 +02:00
$totalSeconds = ($hours * 3600 + $minutes * 60 + $seconds) . ".{$ms}";
return round($totalSeconds, 3);
}
2021-10-11 16:10:47 +02:00
/**
* returns true or false depending on input is wether in
2021-10-11 16:10:47 +02:00
* valid range of SQL date/time.
*
* @param string $p_datetime
2021-10-11 16:10:47 +02:00
* should be in format of '0000-00-00 00:00:00'
*/
2021-10-11 16:10:47 +02:00
public static function checkDateTimeRangeForSQL($p_datetime)
{
$info = explode(' ', $p_datetime);
$dateInfo = explode('-', $info[0]);
if (isset($info[1])) {
$timeInfo = explode(':', $info[1]);
}
2021-10-11 16:10:47 +02:00
$retVal = [];
$retVal['success'] = true;
$year = $dateInfo[0];
$month = $dateInfo[1];
$day = $dateInfo[2];
// if year is < 1753 or > 9999 it's out of range
if ($year < 1753) {
$retVal['success'] = false;
2021-10-11 16:10:47 +02:00
$retVal['errMsg'] = sprintf(_('The year %s must be within the range of 1753 - 9999'), $year);
} elseif (!checkdate($month, $day, $year)) {
$retVal['success'] = false;
2021-10-11 16:10:47 +02:00
$retVal['errMsg'] = sprintf(_('%s-%s-%s is not a valid date'), $year, $month, $day);
} else {
// check time
if (isset($timeInfo)) {
2021-10-11 16:10:47 +02:00
if (isset($timeInfo[0]) && $timeInfo[0] != '') {
$hour = intval($timeInfo[0]);
} else {
$hour = -1;
}
2021-10-11 16:10:47 +02:00
if (isset($timeInfo[1]) && $timeInfo[1] != '') {
$min = intval($timeInfo[1]);
} else {
$min = -1;
}
2021-10-11 16:10:47 +02:00
if (isset($timeInfo[2]) && $timeInfo[2] != '') {
$sec = intval($timeInfo[2]);
} else {
$sec = -1;
}
2021-10-11 16:10:47 +02:00
if (($hour < 0 || $hour > 23) || ($min < 0 || $min > 59) || ($sec < 0 || $sec > 59)) {
$retVal['success'] = false;
2021-10-11 16:10:47 +02:00
$retVal['errMsg'] = sprintf(_('%s:%s:%s is not a valid time'), $timeInfo[0], $timeInfo[1], $timeInfo[2]);
}
}
}
2021-10-11 16:10:47 +02:00
return $retVal;
}
2021-10-11 16:10:47 +02:00
/*
* @param $datetime string Y-m-d H:i:s in UTC timezone
2021-10-11 16:10:47 +02:00
*
* @return string in $format default Y-m-d H:i:s in station timezone
*/
2021-10-11 16:10:47 +02:00
public static function UTCStringToStationTimezoneString($datetime, $format = DEFAULT_TIMESTAMP_FORMAT)
{
$stationTimezone = new DateTimeZone(Application_Model_Preference::GetDefaultTimezone());
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone('UTC');
$d = new DateTime($datetime, $utcTimezone);
$d->setTimezone($stationTimezone);
2021-10-11 16:10:47 +02:00
return $d->format($format);
}
2021-10-11 16:10:47 +02:00
/*
* @param $datetime string Y-m-d H:i:s in UTC timezone
*
* @return string Y-m-d H:i:s in user's timezone
*/
2021-10-11 16:10:47 +02:00
public static function UTCStringToUserTimezoneString($datetime, $format = DEFAULT_TIMESTAMP_FORMAT)
{
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone('UTC');
$d = new DateTime($datetime, $utcTimezone);
$d->setTimezone($userTimezone);
2021-10-11 16:10:47 +02:00
return $d->format($format);
}
2021-10-11 16:10:47 +02:00
/*
* @param $datetime string Y-m-d H:i:s in user timezone
*
* @return string Y-m-d H:i:s in UTC timezone
*/
2021-10-11 16:10:47 +02:00
public static function UserTimezoneStringToUTCString($datetime, $format = DEFAULT_TIMESTAMP_FORMAT)
{
$userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone('UTC');
$d = new DateTime($datetime, $userTimezone);
$d->setTimezone($utcTimezone);
2021-10-11 16:10:47 +02:00
return $d->format($format);
}
2021-10-11 16:10:47 +02:00
/**
* Convert the columns given in the array $columnsToConvert in the
* database result $rows to local timezone.
*
* @param array $rows arrays of arrays containing database query result
* @param array $columnsToConvert array of column names to convert
2021-10-11 16:10:47 +02:00
* @param string (station|user) convert to either station or user timezone
* @param mixed $domain
*/
2021-10-11 16:10:47 +02:00
public static function convertTimestamps(&$rows, $columnsToConvert, $domain = 'station')
{
if (!is_array($rows)) {
return;
}
2021-10-11 16:10:47 +02:00
$converter = 'UTCStringTo' . ucfirst($domain) . 'TimezoneString';
foreach ($rows as &$row) {
foreach ($columnsToConvert as $column) {
$row[$column] = self::$converter($row[$column]);
}
}
}
2021-10-11 16:10:47 +02:00
/**
* Convert the columns given in the array $columnsToConvert in the
* database result $rows to local timezone.
*
2021-10-11 16:10:47 +02:00
* @param array $rows arrays of arrays containing database query result
* @param array $columnsToConvert array of column names to convert
* @param string $timezone convert to the given timezone
* @param string $format time format to convert to
*/
2021-10-11 16:10:47 +02:00
public static function convertTimestampsToTimezone(&$rows, $columnsToConvert, $timezone, $format = DEFAULT_TIMESTAMP_FORMAT)
{
$timezone = strtolower($timezone);
// Check that the timezone is valid and rows is an array
if (!is_array($rows)) {
return;
}
2021-10-11 16:10:47 +02:00
foreach ($rows as &$row) {
if (is_array($row)) {
foreach ($columnsToConvert as $column) {
if (array_key_exists($column, $row)) {
$newTimezone = new DateTimeZone($timezone);
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone('UTC');
$d = new DateTime($row[$column], $utcTimezone);
$d->setTimezone($newTimezone);
$row[$column] = $d->format($format);
}
}
self::convertTimestampsToTimezone($row, $columnsToConvert, $timezone, $format);
}
}
}
2021-10-11 16:10:47 +02:00
/**
2021-10-11 16:10:47 +02:00
* Return the end date time in the given timezone.
*
* @param mixed $timezoneString
* @param mixed $days
*
* @return DateTime
*/
public static function getEndDateTime($timezoneString, $days)
{
$timezone = new DateTimeZone($timezoneString);
2021-10-11 16:10:47 +02:00
$now = new DateTime('now', $timezone);
$now->add(new DateInterval('P' . $days . 'D'));
$now->setTime(0, 0, 0);
2021-10-11 16:10:47 +02:00
return $now;
}
2021-10-11 16:10:47 +02:00
/**
* Return a formatted string representing the
2021-10-11 16:10:47 +02:00
* given datetime in the given timezone.
*
2021-10-11 16:10:47 +02:00
* @param unknown $datetime the time to convert
* @param unknown $timezone the timezone to convert to
* @param string $format the formatted string
*/
2021-10-11 16:10:47 +02:00
public static function UTCStringToTimezoneString($datetime, $timezone, $format = DEFAULT_TIMESTAMP_FORMAT)
{
$d = new DateTime($datetime, new DateTimeZone('UTC'));
$timezone = strtolower($timezone);
$newTimezone = new DateTimeZone($timezone);
$d->setTimezone($newTimezone);
2021-10-11 16:10:47 +02:00
return $d->format($format);
}
2021-10-11 16:10:47 +02:00
/**
2021-10-11 16:10:47 +02:00
* Return the timezone offset in seconds for the given timezone.
*
* @param unknown $userDefinedTimezone the timezone used to determine the offset
*/
2021-10-11 16:10:47 +02:00
public static function getTimezoneOffset($userDefinedTimezone)
{
$now = new DateTimeZone($userDefinedTimezone);
2021-10-11 16:10:47 +02:00
$d = new DateTime('now', $now);
return $d->format('Z');
}
2021-10-11 16:10:47 +02:00
/**
* This function is used for calculations! Don't modify for display purposes!
*
* Convert playlist time value to float seconds
*
* @param string $plt
2021-10-11 16:10:47 +02:00
* playlist interval value (HH:mm:ss.dddddd)
*
* @return int
2021-10-11 16:10:47 +02:00
* seconds
*/
public static function playlistTimeToSeconds($plt)
{
2021-10-11 16:10:47 +02:00
$arr = preg_split('/:/', $plt);
if (isset($arr[2])) {
2021-10-11 16:10:47 +02:00
return (intval($arr[0]) * 60 + intval($arr[1])) * 60 + floatval($arr[2]);
}
if (isset($arr[1])) {
2021-10-11 16:10:47 +02:00
return intval($arr[0]) * 60 + floatval($arr[1]);
}
2021-10-11 16:10:47 +02:00
return floatval($arr[0]);
}
2021-10-11 16:10:47 +02:00
/**
* This function is used for calculations! Don't modify for display purposes!
*
* Convert float seconds value to playlist time format
*
2021-10-11 16:10:47 +02:00
* @param mixed $p_seconds
*
* @return string
2021-10-11 16:10:47 +02:00
* interval in playlist time format (HH:mm:ss.d)
*/
public static function secondsToPlaylistTime($p_seconds)
{
$info = explode('.', $p_seconds);
$seconds = $info[0];
if (!isset($info[1])) {
$milliStr = 0;
} else {
$milliStr = $info[1];
}
$hours = floor($seconds / 3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
2021-10-11 16:10:47 +02:00
return sprintf('%02d:%02d:%02d.%s', $hours, $minutes, $seconds, $milliStr);
}
/**
* Returns date fields from give start and end teimstamp strings
2021-10-11 16:10:47 +02:00
* if no start or end parameter is passed start will be set to 1
* in the past and end to now.
*
fix(deps): update dependency friendsofphp/php-cs-fixer to <3.42.1 (main) (#2765) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [friendsofphp/php-cs-fixer](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer) | `<3.41.2` -> `<3.42.1` | [![age](https://developer.mend.io/api/mc/badges/age/packagist/friendsofphp%2fphp-cs-fixer/3.42.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/friendsofphp%2fphp-cs-fixer/3.42.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/friendsofphp%2fphp-cs-fixer/3.41.1/3.42.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/friendsofphp%2fphp-cs-fixer/3.41.1/3.42.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>PHP-CS-Fixer/PHP-CS-Fixer (friendsofphp/php-cs-fixer)</summary> ### [`v3.42.0`](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/HEAD/CHANGELOG.md#Changelog-for-v3420) [Compare Source](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.41.1...v3.42.0) - chore: aim to not rely on internal array pointer but use array_key_first ([#&#8203;7613](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7613)) - chore: deprecate Token::isKeyCaseSensitive ([#&#8203;7599](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7599)) - chore: deprecate Token::isKeyCaseSensitive, 2nd part ([#&#8203;7601](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7601)) - chore: do not check PHP_VERSION_ID ([#&#8203;7602](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7602)) - chore: FileFilterIteratorTest - more accurate type in docs ([#&#8203;7542](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7542)) - chore: minor code cleanup ([#&#8203;7607](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7607)) - chore: more types ([#&#8203;7598](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7598)) - chore: PHPDoc key-value spacing ([#&#8203;7592](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7592)) - chore: PHPUnit - run defects first ([#&#8203;7570](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7570)) - chore: ProjectCodeTest - DRY on Tokens creation ([#&#8203;7574](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7574)) - chore: ProjectCodeTest - prepare for symfony/console v7 ([#&#8203;7605](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7605)) - chore: ProjectCodeTest::provide\*ClassCases to return iterable with key for better tests execution log ([#&#8203;7572](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7572)) - chore: ProjectCodeTest::testDataProvidersDeclaredReturnType - use better DataProvider to simplify test logic ([#&#8203;7573](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7573)) - chore: TokensAnalyzer - string-enum for better typehinting ([#&#8203;7571](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7571)) - chore: unify tests not agnostic of PHP version ([#&#8203;7581](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7581)) - chore: use ::class more ([#&#8203;7545](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7545)) - CI: Introduce `composer-unused` ([#&#8203;7536](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7536)) - DX: add types to anonymous functions ([#&#8203;7561](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7561)) - DX: Allow running smoke tests within Docker runtime ([#&#8203;7608](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7608)) - DX: check fixer's options for wording ([#&#8203;7543](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7543)) - DX: cleanup deprecation message ([#&#8203;7576](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7576)) - DX: do not allow overriding constructor of `PHPUnit\Framework\TestCase` ([#&#8203;7563](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7563)) - DX: do not import ExpectDeprecationTrait in UtilsTest ([#&#8203;7562](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7562)) - DX: Enforce consistent naming in tests ([#&#8203;7556](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7556)) - DX: fix checking test class extends `PhpCsFixer\Tests\TestCase` ([#&#8203;7567](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7567)) - DX: make sure that exceptions in `AbstractFixerTestCase::testProperMethodNaming` are not already fixed ([#&#8203;7588](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7588)) - DX: remove recursion from AbstractIntegrationTestCase::testIntegration ([#&#8203;7577](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7577)) - DX: remove `PhpUnitNamespacedFixerTest::testClassIsFixed` ([#&#8203;7564](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7564)) - DX: remove `symfony/phpunit-bridge` ([#&#8203;7578](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7578)) - DX: replace fixture classes with anonymous ones ([#&#8203;7533](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7533)) - DX: Unify Docker mount points and paths ([#&#8203;7549](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7549)) - DX: unify fixer's test method names - quick wins ([#&#8203;7584](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7584)) - DX: unify tests for casing fixers ([#&#8203;7558](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7558)) - DX: use anonymous function over concrete classes ([#&#8203;7553](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7553)) - feat(EXPERIMENTAL): ClassKeywordFixer ([#&#8203;2918](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/2918)) - feat(EXPERIMENTAL): ClassKeywordFixer, part 2 ([#&#8203;7550](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7550)) - feat(PhpdocToCommentFixer): Add option to handle return as valid docblock usage ([#&#8203;7401](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7401)) ([#&#8203;7402](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7402)) - feat: Ability to import FQCNs found during analysis ([#&#8203;7597](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7597)) - feat: add phpDoc support for `fully_qualified_strict_types` fixer ([#&#8203;5620](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/5620)) - feat: Handle deprecated rule sets similarly to deprecated fixers ([#&#8203;7288](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7288)) - feat: PhpUnitTestCaseStaticMethodCallsFixer - cover PHPUnit v10 methods ([#&#8203;7604](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7604)) - feat: Support more FQCNs cases in `fully_qualified_strict_types` ([#&#8203;7459](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7459)) - fix: AbstractFixerTestCase - fix checking for correct casing ([#&#8203;7540](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7540)) - fix: Better OS detection in integration tests ([#&#8203;7547](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7547)) - fix: NativeTypeDeclarationCasingFixe - handle static property without type ([#&#8203;7589](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7589)) - test: AutoReview - unify data provider returns ([#&#8203;7544](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7544)) - test: check to have DataProviders code agnostic of PHP version ([#&#8203;7575](https://togithub.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7575)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/libretime/libretime). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMS41IiwidXBkYXRlZEluVmVyIjoiMzcuMTAzLjEiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: jo <ljonas@riseup.net>
2023-12-27 13:40:15 +01:00
* @param string startTimestamp Y-m-d H:i:s
* @param string endTImestamp Y-m-d H:i:s
* @param string timezone (ex UTC) of the start and end parameters
2021-10-11 16:10:47 +02:00
* @param mixed $startTimestamp
* @param mixed $endTimestamp
* @param mixed $timezone
*
* @return array (start DateTime, end DateTime) in UTC timezone
*/
public static function getStartEnd($startTimestamp, $endTimestamp, $timezone)
{
$prefTimezone = Application_Model_Preference::GetTimezone();
2021-10-11 16:10:47 +02:00
$utcTimezone = new DateTimeZone('UTC');
$utcNow = new DateTime('now', $utcTimezone);
if (empty($timezone)) {
$userTimezone = new DateTimeZone($prefTimezone);
} else {
$userTimezone = new DateTimeZone($timezone);
}
// default to 1 day
if (empty($startTimestamp) || empty($endTimestamp)) {
$startsDT = clone $utcNow;
2021-10-11 16:10:47 +02:00
$startsDT->sub(new DateInterval('P1D'));
$endsDT = clone $utcNow;
} else {
try {
$startsDT = new DateTime($startTimestamp, $userTimezone);
$startsDT->setTimezone($utcTimezone);
2021-10-11 16:10:47 +02:00
$endsDT = new DateTime($endTimestamp, $userTimezone);
$endsDT->setTimezone($utcTimezone);
2021-10-11 16:10:47 +02:00
if ($startsDT > $endsDT) {
2021-10-11 16:10:47 +02:00
throw new Exception('start greater than end');
}
2021-10-11 16:10:47 +02:00
} catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
2021-10-11 16:10:47 +02:00
$startsDT = clone $utcNow;
2021-10-11 16:10:47 +02:00
$startsDT->sub(new DateInterval('P1D'));
$endsDT = clone $utcNow;
}
}
2021-10-11 16:10:47 +02:00
return [$startsDT, $endsDT];
}
2011-02-05 00:22:15 +01:00
}