Tools\Utility\Time::ageByHoroscope PHP Method

ageByHoroscope() public static method

Returns age by horoscope info.
public static ageByHoroscope ( integer $year, integer $sign ) : integer | array
$year integer Year
$sign integer Sign
return integer | array Age
    public static function ageByHoroscope($year, $sign)
    {
        App::uses('ZodiacLib', 'Tools.Misc');
        $Zodiac = new ZodiacLib();
        $range = $Zodiac->getRange($sign);
        if ($sign == ZodiacLib::SIGN_CAPRICORN) {
            // undefined
            return [date('Y') - $year - 1, date('Y') - $year];
        }
        if ($range[0][0] > date('m') || $range[0][0] == date('m') && $range[0][1] > date('d')) {
            // not over
            return date('Y') - $year - 1;
        }
        if ($range[1][0] < date('m') || $range[1][0] == date('m') && $range[1][1] <= date('d')) {
            // over
            return date('Y') - $year;
        }
        return [date('Y') - $year - 1, date('Y') - $year];
    }

Usage Example

コード例 #1
0
ファイル: TimeTest.php プロジェクト: alescx/cakephp-tools
 /**
  * TimeTest::testAgeByHoroscop()
  *
  * @return void
  */
 public function testAgeByHoroscop()
 {
     $this->skipIf(PHP_SAPI === 'cli', 'Fix these tests');
     $is = $this->Time->ageByHoroscope(2000, ZodiacLib::SIGN_VIRGO);
     // between xxxx-08-24 and xxxx-09-23 the latter, otherwise the first:
     $this->assertEquals(date('Y') - 2000 - 1, $is);
     $this->assertEquals([date('Y') - 2000 - 1, date('Y') - 2000], $is);
     $is = $this->Time->ageByHoroscope(1991, ZodiacLib::SIGN_LIBRA);
     //pr($is);
     $this->assertEquals(date('Y') - 1991 - 1, $is);
     $is = $this->Time->ageByHoroscope(1986, ZodiacLib::SIGN_CAPRICORN);
     //pr($is);
     $this->assertEquals([date('Y') - 1986 - 1, date('Y') - 1986], $is);
     $is = $this->Time->ageByHoroscope(2000, ZodiacLib::SIGN_SCORPIO);
     //debug($is);
     $this->assertEquals(date('Y') - 2000 - 1, $is);
     //array(10, 11)
 }