Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -69,9 +69,9 @@ class _Date extends \IPS\DateTime
|
||||
public static $dateFormats = array(
|
||||
'locale' => "%x",
|
||||
'd_sm_y' => "%d %b %Y",
|
||||
'd_lm_y' => "%d %B %Y",
|
||||
'd_lm_y' => "%d {monthName} %Y",
|
||||
'sm_d_y' => "%b %d, %Y",
|
||||
'lm_d_y' => "%B %d, %Y",
|
||||
'lm_d_y' => "{monthName} %d, %Y",
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ class _Date extends \IPS\DateTime
|
||||
|
||||
/* Store the information and return the object */
|
||||
$obj = static::ts( $timeStamp - $offset );
|
||||
$obj->dateInformation = getdate( $timeStamp );
|
||||
$obj->getDateInformation( $timeStamp );
|
||||
$obj->offset = $offset;
|
||||
|
||||
return $obj;
|
||||
@@ -152,7 +152,7 @@ class _Date extends \IPS\DateTime
|
||||
$result = parent::__construct( $time );
|
||||
}
|
||||
|
||||
$this->dateInformation = getdate( $this->getTimestamp() );
|
||||
$this->getDateInformation( $this->getTimestamp() );
|
||||
$this->offset = $this->getOffset();
|
||||
|
||||
return $result;
|
||||
@@ -169,12 +169,36 @@ class _Date extends \IPS\DateTime
|
||||
{
|
||||
$result = parent::setTimezone( $timezone );
|
||||
|
||||
$this->dateInformation = getdate( $this->getTimestamp() );
|
||||
$this->getDateInformation( $this->getTimestamp() );
|
||||
$this->offset = $this->getOffset();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date information
|
||||
*
|
||||
* @note This is basically a timezone aware wrapper for getdate
|
||||
* @param int $time Timestamp
|
||||
* @return void
|
||||
*/
|
||||
public function getDateInformation( $time )
|
||||
{
|
||||
$this->dateInformation = array(
|
||||
'seconds' => (int) $this->strFormat( '%S' ),
|
||||
'minutes' => (int) $this->strFormat( '%M' ),
|
||||
'hours' => (int) $this->strFormat( '%H' ),
|
||||
'mday' => (int) $this->strFormat( '%d' ),
|
||||
'wday' => (int) $this->strFormat( '%w' ),
|
||||
'mon' => (int) $this->strFormat( '%m' ),
|
||||
'year' => (int) $this->strFormat( '%Y' ),
|
||||
'yday' => (int) $this->strFormat( '%j' ) - 1,
|
||||
'weekday' => $this->strFormat( '%A' ),
|
||||
'month' => $this->strFormat( '%B' ),
|
||||
0 => $time
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a date object created based on an arbitrary string. Used for both relative time strings and SQL datetime values.
|
||||
*
|
||||
@@ -186,7 +210,47 @@ class _Date extends \IPS\DateTime
|
||||
public static function parseTime( $datetime, $forceUTC=FALSE )
|
||||
{
|
||||
/* Create an \IPS\DateTime object from the datetime value passed in */
|
||||
$timezone = ( $forceUTC === TRUE ) ? new \DateTimeZone( 'UTC' ) : ( \IPS\Member::loggedIn()->timezone ? new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) : NULL );
|
||||
if ( !$forceUTC AND \IPS\Dispatcher::hasInstance() )
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->timezone )
|
||||
{
|
||||
$timezone = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$validTimezone = TRUE;
|
||||
if( in_array( \IPS\Member::loggedIn()->timezone, static::getTimezoneIdentifiers() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$timezone = new \DateTimeZone( \IPS\Member::loggedIn()->timezone );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$validTimezone = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$validTimezone = FALSE;
|
||||
}
|
||||
|
||||
if( ! $validTimezone )
|
||||
{
|
||||
\IPS\Member::loggedIn()->timezone = null;
|
||||
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
\IPS\Member::loggedIn()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$timezone = new \DateTimeZone( 'UTC' );
|
||||
}
|
||||
|
||||
$datetime = new \IPS\DateTime( $datetime, $timezone );
|
||||
|
||||
/* Now correct it back if necessary */
|
||||
@@ -444,7 +508,7 @@ class _Date extends \IPS\DateTime
|
||||
}
|
||||
elseif( isset( static::$dateFormats[ \IPS\Settings::i()->calendar_date_format ] ) )
|
||||
{
|
||||
return static::$dateFormats[ \IPS\Settings::i()->calendar_date_format ];
|
||||
return str_replace( '{monthName}', static::setMonthModifier(), static::$dateFormats[ \IPS\Settings::i()->calendar_date_format ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -455,18 +519,25 @@ class _Date extends \IPS\DateTime
|
||||
/**
|
||||
* Return the MySQL-style datetime value
|
||||
*
|
||||
* @param bool $includeTime Whether to include time or not
|
||||
* @param bool $includeTime Whether to include time or not
|
||||
* @param bool $timezoned Whether to adjust for timezone or not. This will usually be FALSE for database purposes, but set to TRUE if you're using this to compare if two dates are on the same day
|
||||
* @return string
|
||||
*/
|
||||
public function mysqlDatetime( $includeTime=TRUE )
|
||||
public function mysqlDatetime( $includeTime=TRUE, $timezoned = FALSE )
|
||||
{
|
||||
$timeStamp = isset( $this->dateInformation[0] ) ? $this->dateInformation[0] : $this->getTimestamp();
|
||||
if ( $timezoned )
|
||||
{
|
||||
$timeStamp += $this->getTimezone()->getOffset( $this );
|
||||
}
|
||||
|
||||
if( $includeTime )
|
||||
{
|
||||
return date( 'Y-m-d H:i:s', isset( $this->dateInformation[0] ) ? $this->dateInformation[0] : $this->getTimestamp() );
|
||||
return date( 'Y-m-d H:i:s', $timeStamp );
|
||||
}
|
||||
else
|
||||
{
|
||||
return date( 'Y-m-d', isset( $this->dateInformation[0] ) ? $this->dateInformation[0] : $this->getTimestamp() );
|
||||
return date( 'Y-m-d', $timeStamp );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,7 +827,7 @@ class _Date extends \IPS\DateTime
|
||||
|
||||
if( $key == 'monthName' AND isset( $data[0] ) )
|
||||
{
|
||||
return mb_convert_case( \IPS\Member::loggedIn()->language()->convertString( strftime( '%B', $data[0] ) ), MB_CASE_TITLE );
|
||||
return mb_convert_case( \IPS\Member::loggedIn()->language()->convertString( strftime( static::setMonthModifier(), $data[0] ) ), MB_CASE_TITLE );
|
||||
}
|
||||
|
||||
if( $key == 'monthNameShort' AND isset( $data[0] ) )
|
||||
@@ -777,6 +848,36 @@ class _Date extends \IPS\DateTime
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief strftime-compatible modifier for month name
|
||||
*/
|
||||
protected static $monthNameModifier = NULL;
|
||||
|
||||
/**
|
||||
* Sets the month name modifier
|
||||
*
|
||||
* @note Some languages on some OS's (e.g. FreeBSD) require using a different modifier for full month name
|
||||
* @return void
|
||||
*/
|
||||
static protected function setMonthModifier()
|
||||
{
|
||||
if( static::$monthNameModifier === NULL )
|
||||
{
|
||||
$test = @strftime( '%OB' );
|
||||
|
||||
if( $test === FALSE OR $test == '%OB' )
|
||||
{
|
||||
static::$monthNameModifier = '%B';
|
||||
}
|
||||
else
|
||||
{
|
||||
static::$monthNameModifier = '%OB';
|
||||
}
|
||||
}
|
||||
|
||||
return static::$monthNameModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the time according to the user's locale (without the date)
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user