Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F35155994
PhabricatorTime.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
1 KB
Subscribers
None
PhabricatorTime.php
View Options
<?php
final
class
PhabricatorTime
{
private
static
$stack
=
array
();
private
static
$originalZone
;
public
static
function
pushTime
(
$epoch
,
$timezone
)
{
if
(
empty
(
self
::
$stack
))
{
self
::
$originalZone
=
date_default_timezone_get
();
}
$ok
=
date_default_timezone_set
(
$timezone
);
if
(!
$ok
)
{
throw
new
Exception
(
"Invalid timezone '{$timezone}'!"
);
}
self
::
$stack
[]
=
array
(
'epoch'
=>
$epoch
,
'timezone'
=>
$timezone
,
);
return
new
PhabricatorTimeGuard
(
last_key
(
self
::
$stack
));
}
public
static
function
popTime
(
$key
)
{
if
(
$key
!==
last_key
(
self
::
$stack
))
{
throw
new
Exception
(
"PhabricatorTime::popTime with bad key."
);
}
array_pop
(
self
::
$stack
);
if
(
empty
(
self
::
$stack
))
{
date_default_timezone_set
(
self
::
$originalZone
);
}
else
{
$frame
=
end
(
self
::
$stack
);
date_default_timezone_set
(
$frame
[
'timezone'
]);
}
}
public
static
function
getNow
()
{
if
(
self
::
$stack
)
{
$frame
=
end
(
self
::
$stack
);
return
$frame
[
'epoch'
];
}
return
time
();
}
public
static
function
parseLocalTime
(
$time
,
PhabricatorUser
$user
)
{
$old_zone
=
date_default_timezone_get
();
date_default_timezone_set
(
$user
->
getTimezoneIdentifier
());
$timestamp
=
(
int
)
strtotime
(
$time
,
PhabricatorTime
::
getNow
());
if
(
$timestamp
<=
0
)
{
$timestamp
=
null
;
}
date_default_timezone_set
(
$old_zone
);
return
$timestamp
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Feb 2, 8:11 AM (1 d, 16 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
18/47/21daaacf1ef522baacdf5a87a909
Attached To
rPHAB Phabricator
Event Timeline
Log In to Comment