From 6e2d28f03a3a624827ae7ad8869b98b1dade208b Mon Sep 17 00:00:00 2001 From: Elyahu Date: Mon, 30 Sep 2024 00:38:55 -0400 Subject: [PATCH] added a few methods --- .../KosherSwift/ComplexZmanimCalendar.swift | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/Sources/KosherSwift/ComplexZmanimCalendar.swift b/Sources/KosherSwift/ComplexZmanimCalendar.swift index 6663781..3abdfff 100644 --- a/Sources/KosherSwift/ComplexZmanimCalendar.swift +++ b/Sources/KosherSwift/ComplexZmanimCalendar.swift @@ -498,6 +498,23 @@ public class ComplexZmanimCalendar : ZmanimCalendar { return getShaahZmanisMGA(); } + /** + * Method to return a shaah zmanis (solar hour) according to the opinion of the Magen Avraham (MGA). This calculation divides the day + * based on the opinion of the MGA that the day runs from dawn to dusk. Dawn for this calculation is 72 zmaniyos minutes + * before sunrise and dusk is 72 zmaniyos minutes after sunset. This day is split into 12 equal parts with each part + * being a shaah zmanis. Alternate methods of calculating a shaah zmanis are available in the + * subclass `` ComplexZmanimCalendar`` + * + * @return the long millisecond length of a shaah zmanis. If the calculation can't be computed + * such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one + * where it does not set, a ``Int64.min`` will be returned. See detailed explanation on top of the + * ``AstronomicalCalendar`` documentation. + */ + public func getShaahZmanisMGAZmanis() -> Int64 { + return getTemporalHour(startOfDay: getAlos72Zmanis(), endOfDay: getTzais72Zmanis()); + } + /** * Method to return a shaah zmanis (temporal hour) according to the opinion of the Magen Avraham (MGA) based on alos being @@ -4217,7 +4234,7 @@ public class ComplexZmanimCalendar : ZmanimCalendar { * Yalkut Yosef holds that the time for Plag Hamincha is calculated by taking 1.25 "seasonal hours" (Sha'ot Zmaniot) from tzait hacochavim. * This is how Rabbi Dahan calculates Plag Hamincha in his Amudei Horaah calendar with his own algorithm for tzait hacochavim. * Note: The Amudei Horaah calendar provides both the Yalkut Yosef and Halacha Berurah times for Plag Hamincha. (No elevation adjustment is used) - * - Warning: This zman should NOT be used in Israel. + * - Warning: This zman should NOT be used in Israel! The regular ``getPlagHaminchaYalkutYosef()`` method is preferred in Israel. * @return the time for Plag Hamincha as calculated by the Amudei Horaah calendar and Yalkut Yosef. */ public func getPlagHaminchaYalkutYosefAmudeiHoraah() -> Date? { @@ -4347,22 +4364,31 @@ public class ComplexZmanimCalendar : ZmanimCalendar { return ComplexZmanimCalendar.getTimeOffset(time: getSeaLevelSunset(), offset: percentage * shaahZmanit); } - public func getTzaisShabbatAmudeiHoraah() -> Date? { - return getSunsetOffsetByDegrees(offsetZenith: ComplexZmanimCalendar.GEOMETRIC_ZENITH + 7.14) + public func getTzaisShabbosAmudeiHoraah() -> Date? { + let tzait = getSunsetOffsetByDegrees(offsetZenith: ComplexZmanimCalendar.GEOMETRIC_ZENITH + 7.14); + if tzait != nil && getTzaisAteretTorah(minutes: 20) != nil { + if getTzaisAteretTorah(minutes: 20)!.timeIntervalSince1970 > tzait!.timeIntervalSince1970 { // if shabbat ends before 20 minutes after sunset, use 20 minutes + return getTzaisAteretTorah(minutes: 20) + } + if (getSolarMidnight()!.timeIntervalSince1970 < tzait!.timeIntervalSince1970) { // if chatzot is before when shabbat ends, just use chatzot + return getSolarMidnight(); + } + } + return tzait } /** This is only for display purposes, it should not be used to calculate zmanim. - - Returns: The earlier of ``getTzaisAteretTorah()`` or ``getTzaisShabbatAmudeiHoraah()`` + - Returns: The earlier of ``getTzaisAteretTorah()`` or ``getTzaisShabbosAmudeiHoraah()`` */ - public func getTzaisShabbatAmudeiHoraahLesserThan40() -> Date? { - if getTzaisAteretTorah() == nil || getTzaisShabbatAmudeiHoraah() == nil { + public func getTzaisShabbosAmudeiHoraahLesserThan40() -> Date? { + if getTzaisAteretTorah() == nil || getTzaisShabbosAmudeiHoraah() == nil { return nil } - if getTzaisShabbatAmudeiHoraah()?.compare(getTzaisAteretTorah()!) == .orderedDescending { + if getTzaisShabbosAmudeiHoraah()?.compare(getTzaisAteretTorah()!) == .orderedDescending { return getTzaisAteretTorah() } else { - return getTzaisShabbatAmudeiHoraah() + return getTzaisShabbosAmudeiHoraah() } }