mirror of
https://github.com/acamarata/pray-calc.git
synced 2026-06-30 19:04:26 +00:00
Computes the midpoint of the night (Maghrib to Fajr), commonly used as the Isha prayer endpoint. Also works with sunrise as the second anchor for the astronomical variant. Closes #1
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* Formatted prayer times using the PrayCalc Dynamic Method.
|
|
*/
|
|
|
|
import { formatTime } from 'nrel-spa';
|
|
import { getTimes } from './getTimes.js';
|
|
import type { FormattedPrayerTimes } from './types.js';
|
|
|
|
/**
|
|
* Compute prayer times formatted as HH:MM:SS strings.
|
|
*
|
|
* Uses the dynamic twilight angle algorithm. See getTimes() for full parameter
|
|
* documentation.
|
|
*
|
|
* @returns Prayer times as HH:MM:SS strings. Returns "N/A" for any time that
|
|
* cannot be computed (polar night, unreachable angle, etc.).
|
|
*/
|
|
export function calcTimes(
|
|
date: Date,
|
|
lat: number,
|
|
lng: number,
|
|
tz: number = -date.getTimezoneOffset() / 60,
|
|
elevation = 0,
|
|
temperature = 15,
|
|
pressure = 1013.25,
|
|
hanafi = false,
|
|
): FormattedPrayerTimes {
|
|
const raw = getTimes(date, lat, lng, tz, elevation, temperature, pressure, hanafi);
|
|
|
|
// Sort by fractional hour value so output reflects chronological order.
|
|
// Angles are preserved as-is (not time values).
|
|
return {
|
|
Qiyam: formatTime(raw.Qiyam),
|
|
Fajr: formatTime(raw.Fajr),
|
|
Sunrise: formatTime(raw.Sunrise),
|
|
Noon: formatTime(raw.Noon),
|
|
Dhuhr: formatTime(raw.Dhuhr),
|
|
Asr: formatTime(raw.Asr),
|
|
Maghrib: formatTime(raw.Maghrib),
|
|
Isha: formatTime(raw.Isha),
|
|
Midnight: formatTime(raw.Midnight),
|
|
angles: raw.angles,
|
|
};
|
|
}
|