Skip to content

QiyangStudio/SwiftFourPillars

Repository files navigation

SwiftFourPillars

A Swift Package for calculating the Four Pillars of Destiny (年柱, 月柱, 日柱, 时柱).

The package currently provides:

  • sexagenary stem and branch models
  • Four Pillars calculation from Date or DateComponents
  • minute-aware pillar transitions
  • true solar time adjustment by default
  • optional longitude override via CLLocationDegrees

Requirements

  • Swift 6.0+
  • iOS 13+
  • macOS 10.15+
  • tvOS 13+
  • watchOS 6+
  • visionOS 1+

Installation

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")
]

Usage

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.

Notes

  • 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.

Development

Build:

swift build

Test:

swift test

License

MIT. See LICENSE.

About

A Swift Package for calculating the Four Pillars of Destiny.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages