You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currentDate = calendar.date(byAdding:.day, value:1, to: currentDate)!
109
125
}else{
110
-
currentJulianDay +=1
111
126
daysUntilNewMoon +=1
127
+
currentDate = calendar.date(byAdding:.day, value:1, to: currentDate)!
112
128
}
113
129
}
114
130
115
131
return daysUntilNewMoon -1
116
132
}
117
133
118
134
119
-
/// Determines the moon phase for a given Julian day, considering both major and minor moon phases.
135
+
/// Determines the moon phase for a given date, considering both major and minor moon phases.
120
136
///
121
-
/// This function first checks if the specified Julian day includes one of the major moon phases (new moon, first quarter, full moon, last quarter).
137
+
/// This function first checks if the specified date includes one of the major moon phases (new moon, first quarter, full moon, last quarter) within it's 24 hours.
122
138
/// If a major moon phase occurs within the day, that phase is returned. Otherwise, the function calculates the minor moon phase based on the given phase fraction.
123
139
///
124
140
/// - Parameters:
125
-
/// - julianDay: A `Double` representing the Julian day for which to determine the moon phase.
126
141
/// - phaseFraction: A `Double` representing the fractional part of the moon's phase, used to calculate the minor moon phase if no major moon phase occurs on the given day.
142
+
/// - date: The day for which to determine the moon phase.
143
+
/// - timeZone: The timezone to use when calculating the date. Defaults to the system's current timezone.
127
144
///
128
145
/// - Returns: A `MoonPhase` indicating either the major moon phase occurring on the specified day or the minor moon phase calculated from the phase fraction.
129
146
///
130
147
/// Example Usage:
131
148
///
132
149
/// ```swift
133
-
/// let julianDay = 2451545.0 // An example Julian day
134
150
/// let phaseFraction = 0.1 // An example phase fraction
135
-
/// let moonPhase = moonPhase(julianDay: julianDay, phaseFraction: phaseFraction)
151
+
/// let utcTimeZone = TimeZone(identifier: "UTC")!
152
+
/// let moonPhase = moonPhase(phaseFraction: phaseFraction, date: Date(), timeZone: utcTimeZone)
136
153
/// print(moonPhase) // Output depends on the calculated or determined moon phase
/// Checks if a given Julian day includes one of the major moon phases.
168
+
/// Checks if a given date includes one of the major moon phases.
147
169
///
148
-
/// This function evaluates whether the specified Julian day encompasses any of the major moon phases: new moon, first quarter, full moon, or last quarter.
149
-
/// It does so by calculating the moon phase fraction at the start and end of the Julian day and checking if the exact point of a major moon phase falls within this range.
170
+
/// This function evaluates whether the specified date encompasses any of the major moon phases: new moon, first quarter, full moon, or last quarter.
171
+
/// It does so by calculating the moon phase fraction at the start and end of the day and checking if the exact point of a major moon phase falls within this range.
150
172
///
151
-
/// - Parameter julianDay: A `Double` representing the Julian day to check for major moon phases.
173
+
/// - Parameters:
174
+
/// - date: Day to check for major moon phases.
175
+
/// - timeZone: The timezone to use when calculating the date. Defaults to the system's current timezone.
152
176
///
153
177
/// - Returns: An optional `MoonPhase` representing the major moon phase occurring on the specified day, if any. Returns `nil` if no major moon phase occurs on that day.
154
178
///
155
179
/// - Note: The determination of major moon phases is based on predefined thresholds for phase fractions that correspond to the significant points in a lunar cycle
/// Calculates Julian days for a 00:00 UT and 23:00 UT centered around the given Julian day.
191
+
/// Calculates Julian day values for the beginning of the day, 00:00, and 24 hours from there, representing a day's full Julian value range.
164
192
///
165
-
/// - Parameter julianDay: The Julian day around which to calculate the 24-hour period. The fractional part of this parameter determines the starting point of the period.
193
+
/// - Parameters:
194
+
/// - date: The date around which to calculate the 24-hour period.
195
+
/// - timeZone: The timezone to use when calculating the date. Defaults to the system's current timezone.
166
196
///
167
-
/// - Returns: An array of two Julian days representing the start of the 24-hour period at 00:00 UT and the end point at 23:59 UT.
197
+
/// - Returns: A tuple of two Julian days representing the start of the 24-hour period at 00:00 and the end point at 00:00 the next day.
168
198
///
169
199
/// Example Usage:
170
200
///
171
201
/// ```swift
172
-
/// let jd = 2460320.5 // Represents January 11, 2024 at 00:00 UT
173
-
/// let julianDays = startAndEndOfJulianDay(julianDay: jd)
174
-
/// print(julianDays)
175
-
/// // Output: [2460320.5, 2460321.4993]
176
-
/// // Where:
177
-
/// // 2460320.5 = January 11, 2024 at 00:00 UT
178
-
/// // 2460321.25 = January 11, 2024 at 23:59 UT
202
+
/// let date = Date()
203
+
/// let utcTimeZone = TimeZone(identifier: "UTC")!
204
+
/// let (start, end) = julianStartAndEndOfDay(date: date, timeZone: utcTimeZone)
Copy file name to clipboardExpand all lines: Sources/TinyMoon/TinyMoon.swift
+30-15Lines changed: 30 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,8 @@ public enum TinyMoon {
13
13
/// If no major moon phase occurs within the date's 24 hours (starting at 00:00 and ending at 23:59), the object will represent the moon phase closest to the specified date and time.
14
14
///
15
15
/// - Note: Unlike `ExactMoon`, this object will prioritize major moon phases occurring at any point within a 24-hour period.
0 commit comments