[3.0.0] Add more metadata to Moon and ExactMoon. Update to API.
Breaking change
If your app uses the Moon.moonDetail
property to access any of the following properties
public struct MoonDetail: Hashable {
public let julianDay: Double
/// Number of days elapsed into the synodic cycle, represented as a fraction
public let daysElapsedInCycle: Double
/// Age of the moon in days, minutes, hours
public let ageOfMoon: (days: Int, hours: Int, minutes: Int)
/// Illuminated portion of the Moon, where 0.0 = new and 0.99 = full
public let illuminatedFraction: Double
/// Distance of moon from the center of the Earth, in kilometers
public let distanceFromCenterOfEarth: Double
/// Phase of the Moon, represented as a fraction
///
/// Varies between `0.0` to `0.99`.
/// `0.0` new moon,
/// `0.25` first quarter,
/// `0.5` full moon,
/// `0.75` last quarter
public let phase: Double
}
these properties can now be accessed directly via Moon
public struct Moon: Hashable {
init() {...}
// MARK: Public
/// Represents where the phase is in the current synodic cycle. Varies between `0.0` to `0.99`.
///
/// `0.0` new moon, `0.25` first quarter, `0.5` full moon, `0.75` last
public let phaseFraction: Double
/// Illuminated fraction of Moon's disk, between `0.0` and `1.0`.
///
/// `0` indicates a new moon and `1.0` indicates a full moon.
public let illuminatedFraction: Double
public let moonPhase: MoonPhase
public let name: String
public let emoji: String
public let date: Date
/// Returns `0` if the current `date` is a full moon
public var daysTillFullMoon: Int
/// Returns `0` if the current `date` is a new moon
public var daysTillNewMoon: Int
public var moonDetail: TinyMoon.MoonDetail
public var fullMoonName: String? {
if isFullMoon() {
let calendar = Calendar.current
let components = calendar.dateComponents([.month], from: date)
if let month = components.month {
return fullMoonName(month: month)
}
}
return nil
}
public func isFullMoon() -> Bool {
switch moonPhase {
case .fullMoon: true
default: false
}
}
}
What's Changed
- Refactor ExactMoon by @mannylopez in #40
- Moon: Refactor to include MoonDetail properties directly in Moon by @mannylopez in #41
Full Changelog: 2.4.1...3.0.0