Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82577422
PhabricatorTime.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Sep 12, 05:37
Size
2 KB
Mime Type
text/x-php
Expires
Sat, Sep 14, 05:37 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20717644
Attached To
rPH Phabricator
PhabricatorTime.php
View Options
<?php
final
class
PhabricatorTime
extends
Phobject
{
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
(
pht
(
"Invalid timezone '%s'!"
,
$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
(
pht
(
'%s with bad key.'
,
__METHOD__
));
}
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
,
self
::
getNow
());
if
(
$timestamp
<=
0
)
{
$timestamp
=
null
;
}
date_default_timezone_set
(
$old_zone
);
return
$timestamp
;
}
public
static
function
getTodayMidnightDateTime
(
$viewer
)
{
$timezone
=
new
DateTimeZone
(
$viewer
->
getTimezoneIdentifier
());
$today
=
new
DateTime
(
'@'
.
time
());
$today
->
setTimeZone
(
$timezone
);
$year
=
$today
->
format
(
'Y'
);
$month
=
$today
->
format
(
'm'
);
$day
=
$today
->
format
(
'd'
);
$today
=
new
DateTime
(
"{$year}-{$month}-{$day}"
,
$timezone
);
return
$today
;
}
public
static
function
getDateTimeFromEpoch
(
$epoch
,
PhabricatorUser
$viewer
)
{
$datetime
=
new
DateTime
(
'@'
.
$epoch
);
$datetime
->
setTimeZone
(
$viewer
->
getTimeZone
());
return
$datetime
;
}
}
Event Timeline
Log In to Comment