\NetCommonsTime

Class NetCommonsTime

タイムゾーンを考慮した日時を算出します。 コンポーネントとヘルパーを提供しています。

NetCommonsTimeComponent
NetCommonsTimeHelper

テストで時刻を差し替えたいときのサンプルコード

   $nowProperty = new ReflectionProperty('NetCommonsTime', '_now');
   $nowProperty->setAccessible(true);
   $nowProperty->setValue(strtotime('2000-01-01 00:00:00'));
   // test code ..
   $nowProperty->setValue(null); // 現在日時変更が他のテストに影響を与えないようにnullにもどしておく

現在時刻を得る

$nowDatetime = (new NetCommonsTime())->getNowDatetime();

Summary

Methods
Properties
Constants
getSiteTimezone()
toUserDatetime()
toUserDatetimeArray()
toServerDatetime()
toServerDatetimeArray()
getNowDatetime()
getUserTimezone()
No public properties found
No constants found
No protected methods found
$_now
$_siteTimezone
N/A
No private methods found
No private properties found
N/A

Properties

$_now

$_now : integer

Type

integer — 現在日時 unixtime

$_siteTimezone

$_siteTimezone : string

Type

string — サイトデフォルトタイムゾーン

Methods

getSiteTimezone()

getSiteTimezone() : string

サイトのデフォルトタイムゾーンを返す

Returns

string —

タイムゾーン

toUserDatetime()

toUserDatetime(string  $serverDatetime) : string

サーバタイムゾーンの日時をユーザタイムゾーンの日時に変換する

Parameters

string $serverDatetime

server timezone datetime

Returns

string —

ユーザタイムゾーンの日時

toUserDatetimeArray()

toUserDatetimeArray(array  $data, array  $convertKeyNameList) : array

サーバタイムゾーンの日時が含まれる連想配列から指定された配列添え字の値だけをユーザタイムゾーンに変換した配列を返す

Parameters

array $data

サーバタイムゾーンの日時が含まれた配列

array $convertKeyNameList

ユーザタイムゾーンに変換する配列添え字

Returns

array —

ユーザタイムゾーンに変換済みの配列

toServerDatetime()

toServerDatetime(string  $userDatetime, null|string  $userTimezone = null) : string

ユーザタイムゾーンからサーバタイムゾーンに日時を変換する

Parameters

string $userDatetime

ユーザタイムゾーンの日時

null|string $userTimezone

ユーザタイムゾーンを指定したい時にユーザタイムゾーンを渡す。指定しないとアクセスユーザのタイムゾーンを対象に変換する

Returns

string —

サーバタイムゾーンに変換された日時

toServerDatetimeArray()

toServerDatetimeArray(array  $data, array  $convertKeyNameList, null|string  $userTimezone = null) : array

ユーザタイムゾーンの日時が含まれる連想配列から指定された配列添え字の値だけをサーバタイムゾーンに変換した配列を返す

Parameters

array $data

ユーザタイムゾーンの日時が含まれた配列

array $convertKeyNameList

サーバタイムゾーンに変換する配列添え字

null|string $userTimezone

ユーザタイムゾーンを指定したい時にユーザタイムゾーンを渡す。指定しないとアクセスユーザのタイムゾーンを対象に変換する

Returns

array —

サーバタイムゾーンに変換済みの配列

getNowDatetime()

getNowDatetime() : string

現在日時を返す

Returns

string

getUserTimezone()

getUserTimezone() : string

アクセスしたユーザのタイムゾーンを返す ゲストならサイトタイムゾーンを返す

Returns

string —

タイムゾーン