<div class="container" ng-controller="ctrl" ng-app>
<div class="page-header">
<h2>春分・秋分の日計算</h2>
</div>
<h4><input type="number" max="2099" min="1981" ng-model="year" ng-change="update();"/> 年の</h4>
<h4>春分の日は「3月{{springEquinoxDay}}日」です。</h4>
<p>springEquinox={{springEquinox}}</p>
<h4>秋分の日は「9月{{autumnEquinoxDay}}日」です。</h4>
<p>autumnEquinox={{autumnEquinox}}</p>
</div>
/**
* AngularJSアプリケーションコントローラー
*/
function ctrl($scope) {
var date = new Date();
$scope.year = date.getFullYear();
$scope.update = function() {
$scope.springEquinox = getDayOfSpringEquinox($scope.year);
$scope.springEquinoxDay = Math.round($scope.springEquinox);
$scope.autumnEquinox = getDayOfAutumnEquinox($scope.year);
$scope.autumnEquinoxDay = Math.round($scope.autumnEquinox);
}
$scope.update(); //初回アップデート
}
/**
* @param year
* @return 春分の日が3月の何日か(2099年までの正確な値)
*/
function getDayOfSpringEquinox(year) {
var springEquinox = 99;
if (year <= 2099) {
var UNIT = 1000000;
var yearDiff = year - 1980;
springEquinox = (20843100 + (242194 * yearDiff)) / UNIT - (yearDiff / 4);
}
return springEquinox;
}
/**
* @param year
* @return 秋分の日が9月の何日か(2099年までの正確な値)
*/
function getDayOfAutumnEquinox(year) {
var autumnEquinox = 99;
if (year <= 2099) {
var UNIT = 1000000;
var yearDiff = year - 1980;
autumnEquinox = (23248800 + (242194 * yearDiff)) / UNIT - (yearDiff / 4);
}
return autumnEquinox;
}
External resources loaded into this fiddle: