(isSunrise: boolean)
| 138 | const lnHour = longitude / 15; |
| 139 | |
| 140 | function getTime(isSunrise: boolean) { |
| 141 | const t = dayOfYear + (((isSunrise ? 6 : 18) - lnHour) / 24); |
| 142 | |
| 143 | // calculate the Sun's mean anomaly |
| 144 | const M = (0.9856 * t) - 3.289; |
| 145 | |
| 146 | // calculate the Sun's true longitude |
| 147 | let L = M + (1.916 * Math.sin(M * D2R)) + (0.020 * Math.sin(2 * M * D2R)) + 282.634; |
| 148 | if (L > 360) { |
| 149 | L -= 360; |
| 150 | } else if (L < 0) { |
| 151 | L += 360; |
| 152 | } |
| 153 | |
| 154 | // calculate the Sun's right ascension |
| 155 | let RA = R2D * Math.atan(0.91764 * Math.tan(L * D2R)); |
| 156 | if (RA > 360) { |
| 157 | RA -= 360; |
| 158 | } else if (RA < 0) { |
| 159 | RA += 360; |
| 160 | } |
| 161 | |
| 162 | // right ascension value needs to be in the same qua |
| 163 | const Lquadrant = (Math.floor(L / (90))) * 90; |
| 164 | const RAquadrant = (Math.floor(RA / 90)) * 90; |
| 165 | RA += (Lquadrant - RAquadrant); |
| 166 | |
| 167 | // right ascension value needs to be converted into hours |
| 168 | RA /= 15; |
| 169 | |
| 170 | // calculate the Sun's declination |
| 171 | const sinDec = 0.39782 * Math.sin(L * D2R); |
| 172 | const cosDec = Math.cos(Math.asin(sinDec)); |
| 173 | |
| 174 | // calculate the Sun's local hour angle |
| 175 | const cosH = (Math.cos(zenith * D2R) - (sinDec * Math.sin(latitude * D2R))) / (cosDec * Math.cos(latitude * D2R)); |
| 176 | if (cosH > 1) { |
| 177 | // always night |
| 178 | return { |
| 179 | alwaysDay: false, |
| 180 | alwaysNight: true, |
| 181 | time: 0, |
| 182 | }; |
| 183 | } else if (cosH < -1) { |
| 184 | // always day |
| 185 | return { |
| 186 | alwaysDay: true, |
| 187 | alwaysNight: false, |
| 188 | time: 0, |
| 189 | }; |
| 190 | } |
| 191 | |
| 192 | const H = (isSunrise ? (360 - R2D * Math.acos(cosH)) : (R2D * Math.acos(cosH))) / 15; |
| 193 | |
| 194 | // calculate local mean time of rising/setting |
| 195 | const T = H + RA - (0.06571 * t) - 6.622; |
| 196 | |
| 197 | // adjust back to UTC |
no test coverage detected