Calculate Ayanamsha (Lahiri) Via PHP

In case you ever get some of the crazy ideas and ambitions I do, you might want to calculate ayanamsha via PHP. In that case, you might save time by using the code I wrote (it’s approximate, obviously – to be exact why would anyone use PHP?):

	public function ayanamsha( $workingDate, $tropicalLong ){	

		// convert $tropicalLong to MINUTES
		$tropicalLong *= 60;

		define( "AYAN_AT_REF", (23.43333*60) );	// Lahiri at reference date, in MINUTES
		define( "DAILY_PRECESSION", (50.3/365.2422) ); // in SECONDS

		// subtract the working date from the reference date
		// [UNIX TIMESTAMP LIMITATION: This will break when birthtimes are after 2038]
		$refDate = mktime(0,0,0,7,27,1970);
		$workingDate = strtotime(str_replace(":","/",$workingDate)); 
		$diff = $workingDate - $refDate; // in seconds
		$diff = $diff/60/60/24; // days		

		// adjust the ayanamsha to the date
		$precessionDrift = (DAILY_PRECESSION * $diff) / 60;
		$workingAyana = AYAN_AT_REF + $precessionDrift; 

		// adjust tropical longitude
		$siderealLong = $tropicalLong - $workingAyana;

		// Convert sidereal longitude to degrees
		$siderealLong /= 60;

		// Make sure it's in zodiac boundaries
		if( $siderealLong > 360 ) 	$siderealLong -= 360;
		if( $siderealLong < 0 ) 	$siderealLong += 360;		// return it
		return( $siderealLong );
	}

- Vic DiCara
www.vicdicara.com
Advertisements