MediaWiki REL1_37
MediaWiki\User\UserTimeCorrection Class Reference

Utility class to parse the TimeCorrection string value. More...

Public Member Functions

 __construct (string $timeCorrection, DateTime $relativeToDate=null, int $offset=0)
 
 __toString ()
 
 getCorrectionType ()
 Get time offset for a user.
 
 getTimeOffset ()
 Get corresponding time offset for this correction Note: When correcting dates/times, apply only the offset OR the time zone, not both.
 
 getTimeOffsetInterval ()
 Get corresponding time offset for this correction Note: When correcting dates/times, apply only the offset OR the time zone, not both.
 
 getTimeZone ()
 The time zone if known Note: When correcting dates/times, apply only the offset OR the time zone, not both.
 
 isValid ()
 Was the original correction specification valid.
 
 toString ()
 Note: The string value of this object might not be equal to the original value.
 

Private Member Functions

 parse (string $timeCorrection)
 Parse the timecorrection string as stored in the database for a user or as entered into the Preferences form field.
 

Private Attributes

 $correctionType
 
 $date
 
 $offset
 
 $timeZone
 
 $valid
 

Detailed Description

Utility class to parse the TimeCorrection string value.

These values are used to specify the time offset for a user and are stored in the database as a user preference and returned by the preferences APIs

The class will correct invalid input and adjusts timezone offsets to applicable dates, taking into account DST etc.

Since
1.37

Definition at line 41 of file UserTimeCorrection.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserTimeCorrection::__construct ( string  $timeCorrection,
DateTime  $relativeToDate = null,
int  $offset = 0 
)
Parameters
string$timeCorrectionOriginal time correction string
DateTime | null$relativeToDateThe date used to calculate the time zone offset of. This defaults to the current date and time.
int$offsetAn offset in minutes (default 0)

Definition at line 76 of file UserTimeCorrection.php.

References MediaWiki\User\UserTimeCorrection\$offset, and MediaWiki\User\UserTimeCorrection\parse().

Member Function Documentation

◆ __toString()

MediaWiki\User\UserTimeCorrection::__toString ( )

Definition at line 249 of file UserTimeCorrection.php.

◆ getCorrectionType()

MediaWiki\User\UserTimeCorrection::getCorrectionType ( )

Get time offset for a user.

Returns
string Offset that was applied to the user

Definition at line 92 of file UserTimeCorrection.php.

◆ getTimeOffset()

MediaWiki\User\UserTimeCorrection::getTimeOffset ( )

Get corresponding time offset for this correction Note: When correcting dates/times, apply only the offset OR the time zone, not both.

Returns
int Offset in minutes

Definition at line 101 of file UserTimeCorrection.php.

◆ getTimeOffsetInterval()

MediaWiki\User\UserTimeCorrection::getTimeOffsetInterval ( )

Get corresponding time offset for this correction Note: When correcting dates/times, apply only the offset OR the time zone, not both.

Returns
DateInterval Offset in minutes as a DateInterval

Definition at line 110 of file UserTimeCorrection.php.

◆ getTimeZone()

MediaWiki\User\UserTimeCorrection::getTimeZone ( )

The time zone if known Note: When correcting dates/times, apply only the offset OR the time zone, not both.

Returns
DateTimeZone|null

Definition at line 124 of file UserTimeCorrection.php.

◆ isValid()

MediaWiki\User\UserTimeCorrection::isValid ( )

Was the original correction specification valid.

Returns
bool

Definition at line 132 of file UserTimeCorrection.php.

◆ parse()

MediaWiki\User\UserTimeCorrection::parse ( string  $timeCorrection)
private

Parse the timecorrection string as stored in the database for a user or as entered into the Preferences form field.

There can be two forms of these strings:

  1. A pipe separated tuple of a maximum of 3 fields
    • Field 1 is the type of offset definition
    • Field 2 is the offset in minutes from UTC (optional for System type)
    • Field 3 is a timezone identifier from the tz database (only required for ZoneInfo type)
    • The offset for a ZoneInfo type is unreliable because of DST. After retrieving it from the database, it should be recalculated based on the TZ identifier. Examples:
    • System
    • System|60
    • Offset|60
    • ZoneInfo|60|Europe/Amsterdam
  2. The following form provides an offset in hours and minutes This currently should only be used by the preferences input field, but historically they were present in the database. TODO: write a maintenance script to migrate these old db values Examples:
    • 16:00
    • 10
Parameters
string$timeCorrection

Definition at line 163 of file UserTimeCorrection.php.

Referenced by MediaWiki\User\UserTimeCorrection\__construct().

◆ toString()

MediaWiki\User\UserTimeCorrection::toString ( )

Note: The string value of this object might not be equal to the original value.

Returns
string a timecorrection string representing this value

Definition at line 235 of file UserTimeCorrection.php.

Member Data Documentation

◆ $correctionType

MediaWiki\User\UserTimeCorrection::$correctionType
private

Definition at line 62 of file UserTimeCorrection.php.

◆ $date

MediaWiki\User\UserTimeCorrection::$date
private
Initial value:
=
public const ZONEINFO 'ZoneInfo'

Definition at line 56 of file UserTimeCorrection.php.

◆ $offset

MediaWiki\User\UserTimeCorrection::$offset
private

◆ $timeZone

MediaWiki\User\UserTimeCorrection::$timeZone
private

Definition at line 68 of file UserTimeCorrection.php.

◆ $valid

MediaWiki\User\UserTimeCorrection::$valid
private

Definition at line 59 of file UserTimeCorrection.php.


The documentation for this class was generated from the following file: