A Swift Package for calculating the Four Pillars of Destiny (年柱, 月柱, 日柱, 时柱).
The package currently provides:
- sexagenary stem and branch models
- Four Pillars calculation from
DateorDateComponents - minute-aware pillar transitions
- true solar time adjustment by default
- optional longitude override via
CLLocationDegrees
- Swift 6.0+
- iOS 13+
- macOS 10.15+
- tvOS 13+
- watchOS 6+
- visionOS 1+
Add the package to your project with Swift Package Manager:
dependencies: [
.package(url: "https://github.com/wangqiyangX/SwiftFourPillars.git", from: "0.1.0")
]Then add the product to your target:
dependencies: [
.product(name: "SwiftFourPillars", package: "SwiftFourPillars")
]import Foundation
import CoreLocation
import SwiftFourPillars
let calculator = FourPillarsCalculator()
let pillars = calculator.pillars(
for: DateComponents(
calendar: Calendar(identifier: .gregorian),
timeZone: TimeZone(identifier: "Asia/Shanghai"),
year: 2025,
month: 2,
day: 3,
hour: 20,
minute: 23
),
longitude: 121.4737
)longitude uses CLLocationDegrees. If you do not pass it, the calculator uses true solar time based on the time zone's standard meridian.
- Year and month pillars are determined by solar-term boundaries.
- Day and hour pillars are calculated using the adjusted true solar time.
- The current solar-term implementation uses an offline approximation suitable for app-side calculation.
Build:
swift buildTest:
swift testMIT. See LICENSE.