Created
February 24, 2012 16:46
-
-
Save jyokyoku/1901958 to your computer and use it in GitHub Desktop.
NineStarKi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NineStarKi | |
{ | |
protected static $_names = array( | |
1 => '一白水星', | |
2 => '二黒土星', | |
3 => '三碧木星', | |
4 => '四緑木星', | |
5 => '五黄土星', | |
6 => '六白金星', | |
7 => '七赤金星', | |
8 => '八白土星', | |
9 => '九紫火星' | |
); | |
protected static $_monthStartDay = array( | |
1 => 5, | |
2 => 4, | |
3 => 6, | |
4 => 5, | |
5 => 6, | |
6 => 6, | |
7 => 7, | |
8 => 7, | |
9 => 8, | |
10 => 8, | |
11 => 7, | |
12 => 7 | |
); | |
protected static $_numberTable = array( | |
0 => array( | |
1 => 9, | |
2 => 2, | |
3 => 1, | |
4 => 9, | |
5 => 8, | |
6 => 7, | |
7 => 6, | |
8 => 5, | |
9 => 4, | |
10 => 3, | |
11 => 2, | |
12 => 1 | |
), | |
1 => array( | |
1 => 6, | |
2 => 8, | |
3 => 7, | |
4 => 6, | |
5 => 5, | |
6 => 4, | |
7 => 3, | |
8 => 2, | |
9 => 1, | |
10 => 9, | |
11 => 8, | |
12 => 7 | |
), | |
2 => array( | |
1 => 3, | |
2 => 5, | |
3 => 4, | |
4 => 3, | |
5 => 2, | |
6 => 1, | |
7 => 9, | |
8 => 8, | |
9 => 7, | |
10 => 6, | |
11 => 5, | |
12 => 4 | |
), | |
); | |
public static function yearly($year, $month, $day) | |
{ | |
if (!in_array($month, range(1, 12)) || !in_array($day, range(1, 31))) { | |
return false; | |
} | |
if ($month <= 2 && $day <= 3) { | |
$year = (int)$year - 1; | |
} | |
if ($year < 1) { | |
return false; | |
} | |
$sum = $year; | |
do { | |
$sum = array_sum(str_split((int)$sum)); | |
} while ($sum >= 10); | |
if ($sum == 1) { | |
$sum = 10; | |
} | |
$num = 11 - $sum; | |
return self::$_names[$num]; | |
} | |
public static function monthly($year, $month, $day) | |
{ | |
if (!in_array($month, range(1, 12)) || !in_array($day, range(1, 31))) { | |
return false; | |
} | |
$eto = ((int)$year + 9) % 12; | |
if ($eto == 0) { | |
$eto = 12; | |
} | |
if (self::$_monthStartDay[$month] > $day) { | |
$month = $month == 1 ? 12 : $month - 1; | |
} | |
$etoGroup = $eto % 3; | |
$num = self::$_numberTable[$etoGroup][$month]; | |
return self::$_names[$num]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment