Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104173460
PhutilLunarPhase.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
Fri, Mar 7, 00:06
Size
859 B
Mime Type
text/x-php
Expires
Sun, Mar 9, 00:06 (2 d)
Engine
blob
Format
Raw Data
Handle
24540301
Attached To
rPHU libphutil
PhutilLunarPhase.php
View Options
<?php
/**
* Compute the phase of the terran moon for a given epoch.
*
* $moon = new PhutilLunarPhase(time());
* $moon->isFull();
*/
final
class
PhutilLunarPhase
{
private
$epoch
;
public
function
__construct
(
$epoch
)
{
$this
->
epoch
=
$epoch
;
}
private
function
getPhase
()
{
// (Aug 11, 1999) A new moon.
$new_moon_epoch
=
934354800
;
// Number of seconds in the lunar phase.
$phase_length
=
2551442.8768992
;
return
fmod
(
$this
->
epoch
-
$new_moon_epoch
,
$phase_length
)
/
$phase_length
;
}
public
function
isFull
()
{
return
abs
(
$this
->
getPhase
()
-
0.5
)
<
0.02
;
}
public
function
isNew
()
{
return
$this
->
getPhase
()
<
0.02
||
$this
->
getPhase
()
>
0.98
;
}
public
function
isWaxing
()
{
return
$this
->
getPhase
()
<
0.5
;
}
public
function
isWaning
()
{
return
$this
->
getPhase
()
>
0.5
;
}
}
Event Timeline
Log In to Comment