PHP 클래스 Piwik\Date

### Performance concerns The helper methods in this class are instance methods and thus Date instances need to be constructed before they can be used. The memory allocation can result in noticeable performance degradation if you construct thousands of Date instances, say, in a loop. ### Examples **Basic usage** $date = Date::factory('2007-07-24 14:04:24', 'EST'); $date->addHour(5); echo $date->getLocalized("EEE, d. MMM y 'at' HH:mm:ss");
파일 보기 프로젝트 열기: piwik/piwik 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$timestamp integer | null The returned timestamp via getTimestamp() will have the conversion applied
$timezone string Timezone will only affect the returned timestamp via getTimestamp()
$tokens

공개 메소드들

메소드 설명
__toString ( ) : string See {@link toString()}.
addDay ( integer $n ) : Date Adds $n days to $this date and returns the result in a new Date.
addHour ( integer $n ) : Date Adds $n hours to $this date and returns the result in a new Date.
addHourTo ( integer $timestamp, number $n ) : integer Adds N number of hours to a UNIX timestamp and returns the result. Using this static function instead of {@link addHour()} will be faster since a Date instance does not have to be created.
addPeriod ( integer $n, string $period ) : Date Adds a period to $this date and returns the result in a new Date instance.
adjustForTimezone ( integer $timestamp, string $timezone ) : integer Converts a timestamp from UTC to a timezone.
compareMonth ( Date $date ) : integer Performs three-way comparison of the month of the current date against the given $date's month.
compareWeek ( Date $date ) : integer Performs three-way comparison of the week of the current date against the given $date's week.
compareYear ( Date $date ) : integer Performs three-way comparison of the month of the current date against the given $date's year.
factory ( string | integer $dateString, string $timezone = null ) : Date Creates a new Date instance using a string datetime value. The timezone of the Date result will be in UTC.
getDateEndUTC ( ) : string Returns the end of the day of the current timestamp in UTC. For example, if the current timestamp is '2007-07-24 14:03:24' in UTC, the result will be '2007-07-24 23:59:59'.
getDateStartUTC ( ) : string Returns the start of the day of the current timestamp in UTC. For example, if the current timestamp is '2007-07-24 14:04:24' in UTC, the result will be '2007-07-24'.
getDatetime ( ) : string Returns the current timestamp as a string with the following format: 'YYYY-MM-DD HH:MM:SS'.
getDatetimeFromTimestamp ( integer $timestamp ) : string Returns the date in the "Y-m-d H:i:s" PHP format
getHourUTC ( ) : string Returns the current hour in UTC timezone.
getLocalized ( string $template ) : string Returns a localized date string using the given template.
getTimestamp ( ) : integer Returns the unix timestamp of the date in UTC, converted from the current timestamp timezone.
getTimestampUTC ( ) : integer Returns the Unix timestamp of the date in UTC.
getUtcOffset ( $timezone ) : integer Returns the offset to UTC time for the given timezone
isEarlier ( Date $date ) : boolean Returns true if the current date is earlier than the given $date.
isLater ( Date $date ) : boolean Returns true if the current date is older than the given $date.
isLeapYear ( ) : boolean Returns true if the current year is a leap year, false otherwise.
isToday ( ) : boolean Returns true if current date is today.
now ( ) : Date Returns a date object set to now in UTC (same as {@link today()}, except that the time is also set).
secondsToDays ( integer $secs ) : float Returns the number of days represented by a number of seconds.
setDay ( integer $day ) : Date Returns a new Date instance with $this date's time of day and the day specified by $day.
setTime ( string $time ) : Date Returns a new Date instance with $this date's day and the specified new time of day.
setTimezone ( string $timezone ) : Date Returns a new date object with the same timestamp as $this but with a new timezone.
setYear ( integer $year ) : Date Returns a new Date instance with $this date's time of day, month and day, but with a new year (specified by $year).
subDay ( integer $n ) : Date Subtracts $n number of days from $this date and returns a new Date object.
subHour ( integer $n ) : Date Subtracts $n hours from $this date and returns the result in a new Date.
subMonth ( integer $n ) : Date Subtracts $n months from $this date and returns the result as a new Date object.
subPeriod ( integer $n, string $period ) : Date Subtracts a period from $this date and returns the result in a new Date instance.
subSeconds ( integer $n ) : Date Subtracts $n seconds from $this date and returns the result in a new Date.
subWeek ( integer $n ) : Date Subtracts $n weeks from $this date and returns a new Date object.
subYear ( integer $n ) : Date Subtracts $n years from $this date and returns the result as a new Date object.
toString ( string $format = 'Y-m-d' ) : string Converts this date to the requested string format. See {@link http://php.net/date} for the list of format strings.
today ( ) : Date Returns a date object set to today at midnight in UTC.
yesterday ( ) : Date Returns a date object set to yesterday at midnight in UTC.
yesterdaySameTime ( ) : Date Returns a date object set to yesterday with the current time of day in UTC.

보호된 메소드들

메소드 설명
__construct ( integer $timestamp, string $timezone = 'UTC' ) Constructor.
extractUtcOffset ( string $timezone ) : integer | boolean Helper function that returns the offset in the timezone string 'UTC+14' Returns false if the timezone is not UTC+X or UTC-X
formatToken ( $token )
parseFormat ( string $pattern ) : array Parses the datetime format pattern and returns a tokenized result array

비공개 메소드들

메소드 설명
getInvalidDateFormatException ( $dateString )
getMaxDaysInMonth ( $timestamp )

메소드 상세

__construct() 보호된 메소드

Constructor.
protected __construct ( integer $timestamp, string $timezone = 'UTC' )
$timestamp integer The number in seconds since the unix epoch.
$timezone string The timezone of the datetime.

__toString() 공개 메소드

See {@link toString()}.
public __toString ( ) : string
리턴 string The current date in `'YYYY-MM-DD'` format.

addDay() 공개 메소드

instance.
public addDay ( integer $n ) : Date
$n integer Number of days to add, must be > 0.
리턴 Date

addHour() 공개 메소드

Adds $n hours to $this date and returns the result in a new Date.
public addHour ( integer $n ) : Date
$n integer Number of hours to add. Can be less than 0.
리턴 Date

addHourTo() 공개 정적인 메소드

Adds N number of hours to a UNIX timestamp and returns the result. Using this static function instead of {@link addHour()} will be faster since a Date instance does not have to be created.
public static addHourTo ( integer $timestamp, number $n ) : integer
$timestamp integer The timestamp to add to.
$n number Number of hours to add, must be > 0.
리턴 integer The result as a UNIX timestamp.

addPeriod() 공개 메소드

Adds a period to $this date and returns the result in a new Date instance.
public addPeriod ( integer $n, string $period ) : Date
$n integer The number of periods to add. Can be negative.
$period string The type of period to add (YEAR, MONTH, WEEK, DAY, ...)
리턴 Date

adjustForTimezone() 공개 정적인 메소드

Converts a timestamp from UTC to a timezone.
public static adjustForTimezone ( integer $timestamp, string $timezone ) : integer
$timestamp integer The UNIX timestamp to adjust.
$timezone string The timezone to adjust to.
리턴 integer The adjusted time as seconds from EPOCH.

compareMonth() 공개 메소드

Performs three-way comparison of the month of the current date against the given $date's month.
public compareMonth ( Date $date ) : integer
$date Date Month to compare
리턴 integer Returns `0` if the current month is equal to `$date`'s, `-1` if the current month is earlier or `1` if the current month is later.

compareWeek() 공개 메소드

Performs three-way comparison of the week of the current date against the given $date's week.
public compareWeek ( Date $date ) : integer
$date Date
리턴 integer Returns `0` if the current week is equal to `$date`'s, `-1` if the current week is earlier or `1` if the current week is later.

compareYear() 공개 메소드

Performs three-way comparison of the month of the current date against the given $date's year.
public compareYear ( Date $date ) : integer
$date Date Year to compare
리턴 integer Returns `0` if the current year is equal to `$date`'s, `-1` if the current year is earlier or `1` if the current year is later.

extractUtcOffset() 보호된 정적인 메소드

Helper function that returns the offset in the timezone string 'UTC+14' Returns false if the timezone is not UTC+X or UTC-X
protected static extractUtcOffset ( string $timezone ) : integer | boolean
$timezone string
리턴 integer | boolean utc offset or false

factory() 공개 정적인 메소드

Creates a new Date instance using a string datetime value. The timezone of the Date result will be in UTC.
public static factory ( string | integer $dateString, string $timezone = null ) : Date
$dateString string | integer `'today'`, `'yesterday'`, `'now'`, `'yesterdaySameTime'`, a string with `'YYYY-MM-DD HH:MM:SS'` format or a unix timestamp.
$timezone string The timezone of the result. If specified, `$dateString` will be converted from UTC to this timezone before being used in the Date return value.
리턴 Date

formatToken() 보호된 메소드

protected formatToken ( $token )

getDateEndUTC() 공개 메소드

Returns the end of the day of the current timestamp in UTC. For example, if the current timestamp is '2007-07-24 14:03:24' in UTC, the result will be '2007-07-24 23:59:59'.
public getDateEndUTC ( ) : string
리턴 string

getDateStartUTC() 공개 메소드

Returns the start of the day of the current timestamp in UTC. For example, if the current timestamp is '2007-07-24 14:04:24' in UTC, the result will be '2007-07-24'.
public getDateStartUTC ( ) : string
리턴 string

getDatetime() 공개 메소드

Returns the current timestamp as a string with the following format: 'YYYY-MM-DD HH:MM:SS'.
public getDatetime ( ) : string
리턴 string

getDatetimeFromTimestamp() 공개 정적인 메소드

Returns the date in the "Y-m-d H:i:s" PHP format
public static getDatetimeFromTimestamp ( integer $timestamp ) : string
$timestamp integer
리턴 string

getHourUTC() 공개 메소드

Returns the current hour in UTC timezone.
public getHourUTC ( ) : string
리턴 string

getLocalized() 공개 메소드

The template should contain tags that will be replaced with localized date strings.
public getLocalized ( string $template ) : string
$template string eg. `"MMM y"`
리턴 string eg. `"Aug 2009"`

getTimestamp() 공개 메소드

Returns the unix timestamp of the date in UTC, converted from the current timestamp timezone.
public getTimestamp ( ) : integer
리턴 integer

getTimestampUTC() 공개 메소드

Returns the Unix timestamp of the date in UTC.
public getTimestampUTC ( ) : integer
리턴 integer

getUtcOffset() 공개 정적인 메소드

Returns the offset to UTC time for the given timezone
public static getUtcOffset ( $timezone ) : integer
$timezone
리턴 integer offest in minutes

isEarlier() 공개 메소드

Returns true if the current date is earlier than the given $date.
public isEarlier ( Date $date ) : boolean
$date Date
리턴 boolean

isLater() 공개 메소드

Returns true if the current date is older than the given $date.
public isLater ( Date $date ) : boolean
$date Date
리턴 boolean

isLeapYear() 공개 메소드

Returns true if the current year is a leap year, false otherwise.
public isLeapYear ( ) : boolean
리턴 boolean

isToday() 공개 메소드

Returns true if current date is today.
public isToday ( ) : boolean
리턴 boolean

now() 공개 정적인 메소드

Returns a date object set to now in UTC (same as {@link today()}, except that the time is also set).
public static now ( ) : Date
리턴 Date

parseFormat() 보호된 정적인 메소드

Examples: Input Output 'dd.mm.yyyy' array(array('dd'), '.', array('mm'), '.', array('yyyy')) 'y?M?d?EEEE ah:mm:ss' array(array('y'), '?', array('M'), '?', array('d'), '?', array('EEEE'), ' ', array('a'), array('h'), ':', array('mm'), ':', array('ss'))
protected static parseFormat ( string $pattern ) : array
$pattern string the pattern to be parsed
리턴 array tokenized parsing result

secondsToDays() 공개 정적인 메소드

Returns the number of days represented by a number of seconds.
public static secondsToDays ( integer $secs ) : float
$secs integer
리턴 float

setDay() 공개 메소드

Returns a new Date instance with $this date's time of day and the day specified by $day.
public setDay ( integer $day ) : Date
$day integer The day eg. `31`.
리턴 Date

setTime() 공개 메소드

Returns a new Date instance with $this date's day and the specified new time of day.
public setTime ( string $time ) : Date
$time string String in the `'HH:MM:SS'` format.
리턴 Date The new date with the time of day changed.

setTimezone() 공개 메소드

See {@link getTimestamp()} to see how the timezone is used.
public setTimezone ( string $timezone ) : Date
$timezone string eg, `'UTC'`, `'Europe/London'`, etc.
리턴 Date

setYear() 공개 메소드

Returns a new Date instance with $this date's time of day, month and day, but with a new year (specified by $year).
public setYear ( integer $year ) : Date
$year integer The year, eg. `2010`.
리턴 Date

subDay() 공개 메소드

Subtracts $n number of days from $this date and returns a new Date object.
public subDay ( integer $n ) : Date
$n integer An integer > 0.
리턴 Date

subHour() 공개 메소드

Subtracts $n hours from $this date and returns the result in a new Date.
public subHour ( integer $n ) : Date
$n integer Number of hours to subtract. Can be less than 0.
리턴 Date

subMonth() 공개 메소드

Subtracts $n months from $this date and returns the result as a new Date object.
public subMonth ( integer $n ) : Date
$n integer An integer > 0.
리턴 Date new date

subPeriod() 공개 메소드

Subtracts a period from $this date and returns the result in a new Date instance.
public subPeriod ( integer $n, string $period ) : Date
$n integer The number of periods to add. Can be negative.
$period string The type of period to add (YEAR, MONTH, WEEK, DAY, ...)
리턴 Date

subSeconds() 공개 메소드

Subtracts $n seconds from $this date and returns the result in a new Date.
public subSeconds ( integer $n ) : Date
$n integer Number of seconds to subtract. Can be less than 0.
리턴 Date

subWeek() 공개 메소드

Subtracts $n weeks from $this date and returns a new Date object.
public subWeek ( integer $n ) : Date
$n integer An integer > 0.
리턴 Date

subYear() 공개 메소드

Subtracts $n years from $this date and returns the result as a new Date object.
public subYear ( integer $n ) : Date
$n integer An integer > 0.
리턴 Date

toString() 공개 메소드

Converts this date to the requested string format. See {@link http://php.net/date} for the list of format strings.
public toString ( string $format = 'Y-m-d' ) : string
$format string
리턴 string

today() 공개 정적인 메소드

Returns a date object set to today at midnight in UTC.
public static today ( ) : Date
리턴 Date

yesterday() 공개 정적인 메소드

Returns a date object set to yesterday at midnight in UTC.
public static yesterday ( ) : Date
리턴 Date

yesterdaySameTime() 공개 정적인 메소드

Returns a date object set to yesterday with the current time of day in UTC.
public static yesterdaySameTime ( ) : Date
리턴 Date

프로퍼티 상세

$timestamp 보호되어 있는 프로퍼티

The returned timestamp via getTimestamp() will have the conversion applied
protected int|null $timestamp
리턴 integer | null

$timezone 보호되어 있는 프로퍼티

Timezone will only affect the returned timestamp via getTimestamp()
protected string $timezone
리턴 string

$tokens 보호되어 있는 정적으로 프로퍼티

protected static $tokens