### Example: Using SixtyCycleDay Source: https://github.com/6tail/tyme4swift Example code showing how to create a SixtyCycleDay from a SolarDay and access its properties. ```APIDOC ## [EXAMPLE] Using SixtyCycleDay ### Description Example code showing how to create a SixtyCycleDay from a SolarDay and access its properties. ### Code ```swift import Tyme4Swift let gd = try SolarDay.fromYmd(2020, 5, 29).getSixtyCycleDay() print(gd.description) // 干支月 + 干支日 print(gd.year.getName(), gd.month.getName(), gd.sixtyCycle.getName()) print(gd.threePillars.getName()) // 年柱 月柱 日柱 ``` ``` -------------------------------- ### HijriDay usage example Source: https://github.com/6tail/tyme4swift Shows how to create a HijriDay from a SolarDay and access its properties. The example prints the Hijri description, the corresponding solar day, and the day count of the Hijri month. ```swift import Tyme4Swift let h = try SolarDay.fromYmd(1986, 5, 29).getHijriDay() print(h.description) // 1406年赖买丹月20日 print(h.getSolarDay().description) // 1986年5月29日(来回转换) print(h.hijriMonth.dayCount) // 赖买丹月为 30 或 29 视闰年而定 ``` -------------------------------- ### Phase usage example with fromIndex and next Source: https://github.com/6tail/tyme4swift Shows how to create a Phase via fromIndex(2020, 5, 3) for the 2020 fifth lunar month's waxing gibbous moon, print its name and solar day description, advance to the next phase with next(1), and get the phase of a specific solar day. The output demonstrates the phase name and approximate solar date. ```swift import Tyme4Swift let p = try Phase.fromIndex(2020, 5, 3) // 2020年五月盈凸月 print(p.getName(), p.solarDay.description) // 盈凸月 2020年6月29日前后 print(try p.next(1).getName()) // 满月 print(try SolarDay.fromYmd(2020, 5, 29).phase.getName()) ``` -------------------------------- ### HeavenStem Usage Example Source: https://github.com/6tail/tyme4swift Example usage of HeavenStem from the source documentation. ```APIDOC ## [EXAMPLE] HeavenStem Usage ### Description Example usage of HeavenStem from the source documentation. ### Code ```swift import Tyme4Swift let hs = HeavenStem.fromIndex(0) // 甲 print(hs.element.getName()) // 木 print(hs.yinYang.getName()) // 阳 print(hs.combine.getName()) // 己 print(hs.combine(HeavenStem.fromIndex(5))?.getName() ?? "nil") // 土(合化) print(hs.getTenStar(HeavenStem.fromIndex(1)).getName()) // 十神 ``` ``` -------------------------------- ### EventManager usage example Source: https://github.com/6tail/tyme4swift Shows how to create an event, update it in the manager, retrieve it by name, and remove it. ```swift import Tyme4Swift let e = Event.builder().name("建党").solarDay(7, 1, 0).build() EventManager.update("建党", e) let found = Event.fromName("建党") print(found?.getName() ?? "nil") EventManager.remove("建党") ``` -------------------------------- ### LegalHoliday usage example Source: https://github.com/6tail/tyme4swift Shows how to query the holiday status for a given solar day and how to move to the next holiday entry. The first example prints the description and isWork for 2024-10-01 (国庆节(休) false). The second retrieves the 春节 holiday for 2024-02-10 and prints the next entry's description. ```swift import Tyme4Swift // 遍历某公历日的假日状态 let d = try SolarDay.fromYmd(2024, 10, 1) if let h = d.legalHoliday { print(h.description, h.isWork) // 2024年10月1日 国庆节(休) false } // 前后推移 let h2 = try SolarDay.fromYmd(2024, 2, 10).legalHoliday // 春节 print(h2?.next(1)?.description ?? "nil") ``` -------------------------------- ### Tyme Swift Usage Example Source: https://github.com/6tail/tyme4swift/blob/master/README.md Shows how to create a SolarDay and print its descriptions in different calendars (Gregorian, Lunar, RabByung, Hijri). ```swift let solarDay: SolarDay = SolarDay.fromYmd(1986, 5, 29) // 1986年5月29日 print(solarDay.description) // 农历丙寅年四月廿一 print(solarDay.getLunarDay().description) // 第十七饶迥火虎年四月廿一 print(solarDay.getRabByungDay().description) // 1406年赖买丹月20日 print(solarDay.getHijriDay().description) ``` -------------------------------- ### Usage example for SixtyCycleDay Source: https://github.com/6tail/tyme4swift Shows how to obtain a SixtyCycleDay from a SolarDay and print its description, year/month/day names, and three pillars. Requires importing Tyme4Swift and using try with fromYmd and getSixtyCycleDay. ```swift import Tyme4Swift let gd = try SolarDay.fromYmd(2020, 5, 29).getSixtyCycleDay() print(gd.description) // 干支月 + 干支日 print(gd.year.getName(), gd.month.getName(), gd.sixtyCycle.getName()) print(gd.threePillars.getName()) // 年柱 月柱 日柱 ``` -------------------------------- ### SolarMonth usage example Source: https://github.com/6tail/tyme4swift Creates a SolarMonth for February 2024 and prints day count, day list count, week count with Monday start, and the next month's description. Outputs 29, 29, the week count, and 2024年3月. ```swift import Tyme4Swift let m = try SolarMonth.fromYm(2024, 2) print(m.dayCount) // 29(闰年) print(m.days.count) // 29 print(m.getWeekCount(1)) // 该月以周一为起始的周数 print(try m.next(1).description) // 2024年3月 ``` -------------------------------- ### SolarWeek usage example Source: https://github.com/6tail/tyme4swift Creates a SolarWeek for May 2020, first week, with Monday as the start day. Prints the week description, the number of days (7), and the first day of the week containing May 29, 2020. ```swift import Tyme4Swift let w = try SolarWeek.fromYm(2020, 5, 0, 1) // 2020年5月第1周,周一为起始 print(w.description) print(w.days.count) // 7 print(try SolarDay.fromYmd(2020, 5, 29).getSolarWeek(1).firstDay.description) ``` -------------------------------- ### Event.startYear Source: https://github.com/6tail/tyme4swift Gets the start year, decoded from the last three characters of the data string. ```APIDOC ## Event.startYear ### Description Gets the start year, decoded from the last three characters of the data string. ### Property public var startYear: Int ### Returns - **Int** - The start year. ``` -------------------------------- ### LoopTyme usage example with Week Source: https://github.com/6tail/tyme4swift Shows how to use a LoopTyme subclass: `fromIndex` returns a value, `fromName` throws on invalid names, `next` advances the index, and `size` gives the count. ```swift import Tyme4Swift let week = Week.fromIndex(1) // 一 let week2 = try Week.fromName("三") // 三 let next = week2.next(5) // 一 print(week2.size) // 7 ``` -------------------------------- ### SolarSeason usage example Source: https://github.com/6tail/tyme4swift Creates a SolarSeason for 2024 index 0 (Q1) and prints its description and month numbers. ```swift import Tyme4Swift let s = try SolarSeason.fromIndex(2024, 0) print(s.description) // 2024年一季度 print(s.months.map { $0.month }) // [1, 2, 3] ``` -------------------------------- ### RabByungDay usage example Source: https://github.com/6tail/tyme4swift Shows how to create a RabByungDay from a SolarDay, print its description, convert back to SolarDay, and handle invalid day values (e.g., day 0) with error handling. ```swift import Tyme4Swift let rb = try SolarDay.fromYmd(2022, 1, 1).getRabByungDay() print(rb.description) // 藏历日描述 print(rb.getSolarDay().description) // 转回公历 do { _ = try RabByungDay.fromYmd(1951, 1, 0) // day 为 0 } catch { print("非法藏历日:\(error)") } ``` -------------------------------- ### SolarTerm usage example Source: https://github.com/6tail/tyme4swift Shows how to create a SolarTerm by index, access its name, jie/qi flags, solar day, precise julian day time, and next term. ```swift import Tyme4Swift let t = SolarTerm.fromIndex(2020, 3) // 立春 print(t.getName(), t.isJie, t.isQi) // 立春 true false print(t.getSolarDay().description) // 2020年2月4日 print(t.julianDay.getSolarTime().description) // 精确到秒的节气时刻 print(t.next(1).getName()) // 雨水 ``` -------------------------------- ### SolarHalfYear usage example Source: https://github.com/6tail/tyme4swift Creates a SolarHalfYear for 2024 index 1 (second half) and prints its description and month numbers. ```swift import Tyme4Swift let h = try SolarHalfYear.fromIndex(2024, 1) print(h.description) // 2024年下半年 print(h.months.map { $0.month }) // [7, 8, 9, 10, 11, 12] ``` -------------------------------- ### KitchenGodSteed usage example Source: https://github.com/6tail/tyme4swift Shows how to create a KitchenGodSteed instance for a lunar year and access its properties. The example uses lunar year 2023 and prints the mouse, Dragon, Field, and Cake values. ```swift import Tyme4Swift let ks = try KitchenGodSteed.fromLunarYear(2023) print(ks.mouse) // n鼠偷粮 print(ks.Dragon) // n龙治水 print(ks.Field, ks.Cake) ``` -------------------------------- ### EventBuilder.startYear(_:) Source: https://github.com/6tail/tyme4swift Sets the starting year for the event. The year is encoded into the event data using a base-63 encoding. ```APIDOC ## EventBuilder.startYear(_:) ### Description Sets the starting year for the event. The year is encoded into the event data using a base-63 encoding. ### Method startYear ### Parameters - **year** (Int) - Required - The starting year. ### Returns - **Self** - The builder instance for chaining. ``` -------------------------------- ### HeavenStem usage example Source: https://github.com/6tail/tyme4swift Example usage of HeavenStem: creates a stem from index 0 (甲), prints its element (木), yin-yang (阳), combine (己), combine with index 5 (土), and ten-star for index 1. ```swift import Tyme4Swift let hs = HeavenStem.fromIndex(0) // 甲 print(hs.element.getName()) // 木 print(hs.yinYang.getName()) // 阳 print(hs.combine.getName()) // 己 print(hs.combine(HeavenStem.fromIndex(5))?.getName() ?? "nil") // 土(合化) print(hs.getTenStar(HeavenStem.fromIndex(1)).getName()) // 十神 ``` -------------------------------- ### SolarWeek.fromYm(_:_:_:_:) Source: https://github.com/6tail/tyme4swift Creates a SolarWeek instance for a given year, month, week index, and start day. Validates the parameters and throws an error if the week index is out of range. ```APIDOC ## SolarWeek.fromYm(_:_:_:_:) ### Description Creates a SolarWeek instance for a given year, month, week index, and start day. Validates the parameters and throws an error if the week index is out of range. ### Method class func fromYm(_ year: Int, _ month: Int, _ index: Int, _ start: Int) throws -> Self ### Parameters - **year** (Int) - Required - The Gregorian year. - **month** (Int) - Required - The Gregorian month (1-12). - **index** (Int) - Required - The week index (0-5), must be less than the number of weeks in the month. - **start** (Int) - Required - The start day of the week (0-6, where 0=Monday, 6=Sunday). ### Response Returns a SolarWeek instance. ### Error Handling Throws `ArgumentError` if the week index is out of range (e.g., "illegal solar week index: \(index) in month: \(m)"). ### Request Example ```swift import Tyme4Swift let w = try SolarWeek.fromYm(2020, 5, 0, 1) // 2020年5月第1周,周一为起始 print(w.description) print(w.days.count) // 7 print(try SolarDay.fromYmd(2020, 5, 29).getSolarWeek(1).firstDay.description) ``` ``` -------------------------------- ### WeekUnit Source: https://github.com/6tail/tyme4swift Represents a week unit within a month. Provides the week index, start day, and a static list of week names. ```APIDOC ## WeekUnit ### Description Represents a week unit. Provides the week index and start day. ### Properties - **NAMES** ([String]) - Static list of week names: ["第一周", "第二周", "第三周", "第四周", "第五周", "第六周"] - **index** (Int) - Index, 0-5. - **startIndex** (Int) - Start day, 1234560 representing Monday to Sunday. - **start** (Week) - The start day as a Week enum, derived from startIndex. ### Methods - **validate(_ index: Int, _ start: Int)** - Validates the week index and start day. ``` -------------------------------- ### Week usage example Source: https://github.com/6tail/tyme4swift Creates a Week from index 1 (Monday), prints its name and the name after moving 6 days forward (Sunday), and retrieves the associated SevenStar (lunar mansion) name, which is '月' (Moon) for Monday. ```swift import Tyme4Swift let w = Week.fromIndex(1) // 一 print(w.getName(), w.next(6).getName()) // 一 日 print(w.getSevenStar().getName()) // 月(七曜) ``` -------------------------------- ### LunarWeek usage example Source: https://github.com/6tail/tyme4swift Shows how to create a LunarWeek instance using fromYm with year 2023, month 2, index 0, and start day 1. The example prints the week description and the number of days, which outputs '农历癸卯年二月第1周 7'. Requires importing Tyme4Swift. ```swift import Tyme4Swift let w = try LunarWeek.fromYm(2023, 2, 0, 1) print(w.description, w.days.count) // 农历癸卯年二月第1周 7 ``` -------------------------------- ### Package.swift 依赖配置 Source: https://github.com/6tail/tyme4swift 在 Package.swift 中添加 Tyme4Swift 依赖,版本从 1.5.0 开始。 ```swift .package(url: "https://github.com/6tail/tyme4swift.git", from: "1.5.0") ``` -------------------------------- ### Consumer Integration with SwiftPM Source: https://github.com/6tail/tyme4swift Shows how a consumer project adds Tyme4Swift as a dependency and imports the product. Use version 1.5.0 or later. ```swift dependencies: [ .package(url: "https://github.com/6tail/tyme4swift.git", from: "1.5.0"), ], targets: [ .target(name: "MyApp", dependencies: [.product(name: "Tyme4Swift", package: "tyme4swift")]), ] ``` -------------------------------- ### SolarWeek class declaration Source: https://github.com/6tail/tyme4swift Declaration of the SolarWeek class, a WeekUnit subclass. Week index starts at 0 for the first week of the month, with the start day determined by the 'start' parameter (0=Monday ... 6=Sunday). The index must be less than the month's week count, otherwise an ArgumentError is thrown. ```swift public class SolarWeek: WeekUnit { required override init(_ year: Int, _ month: Int, _ index: Int, _ start: Int) throws public class func validate(_ year: Int, _ month: Int, _ index: Int, _ start: Int) throws public class func fromYm(_ year: Int, _ month: Int, _ index: Int, _ start: Int) throws -> Self public var firstDay: SolarDay // 本周第1天 public var indexInYear: Int // 今年第几周(从1月第1周计) public var solarMonth: SolarMonth public override func getName() -> String // "第N周" public override var description: String public override func next(_ n: Int) throws -> Self public override func isEqual(_ t: Any?) -> Bool // 按 firstDay 比较 /// 本周公历日列表 public var days: [SolarDay] } ``` -------------------------------- ### LunarFestival usage example Source: https://github.com/6tail/tyme4swift Shows how to retrieve a lunar festival from a LunarDay and from an index. The first example prints the festival name and day description for 2020-01-01 (春节). The second prints the name for the first festival of 2021 (春节). ```swift import Tyme4Swift if let f = try LunarDay.fromYmd(2020, 1, 1).festival { print(f.getName(), f.getDay().description) // 春节 农历庚子年一月初一 } if let f2 = LunarFestival.fromIndex(2021, 0) { print(f2.getName()) // 春节 } ``` -------------------------------- ### SolarDay.fromYmd Source: https://github.com/6tail/tyme4swift Creates a SolarDay instance from a Gregorian year, month, and day. This is a primary entry point for the library. ```APIDOC ## SolarDay.fromYmd ### Description Creates a SolarDay instance from a Gregorian year, month, and day. This is a primary entry point for the library. ### Method Factory method (throws) ### Signature `static func fromYmd(_ year: Int, _ month: Int, _ day: Int) throws -> SolarDay` ### Parameters - **year** (Int) - Required - Gregorian year - **month** (Int) - Required - Gregorian month - **day** (Int) - Required - Gregorian day ### Return - **SolarDay** - The solar day instance ### Throws - `ArgumentError` if the date is illegal (e.g., 2021-2-30) ### Example ```swift let solarDay: SolarDay = try SolarDay.fromYmd(1986, 5, 29) print(solarDay.description) // 1986年5月29日 ``` ``` -------------------------------- ### LoopTyme.fromIndex(_:) Source: https://github.com/6tail/tyme4swift Creates an instance of a LoopTyme subclass from a given index. The index is safe due to modulo operation, so it never throws an error. ```APIDOC ## LoopTyme.fromIndex(_:) ### Description Creates an instance of a LoopTyme subclass from a given index. The index is safe due to modulo operation, so it never throws an error. ### Method fromIndex ### Signature `public class func fromIndex(_ index: Int) -> Self` ### Parameters - **index** (Int) - Required - The index to create the instance from. Any integer is allowed; it is normalized internally. ### Returns - **Self** - The created instance. ``` -------------------------------- ### Event.type Source: https://github.com/6tail/tyme4swift Gets the event type, decoded from the second character of the data string. ```APIDOC ## Event.type ### Description Gets the event type, decoded from the second character of the data string. ### Property public var type: EventType? ### Returns - **EventType?** - The event type, or nil if decoding fails. ``` -------------------------------- ### SixtyCycleMonth.fromYm(_:_:) Source: https://github.com/6tail/tyme4swift Creates a SixtyCycleMonth instance from a sixty-cycle year and a month index (0-11, with 寅月 as 0). The year is validated via SixtyCycleYear.fromYear. ```APIDOC ## [CLASS_METHOD] SixtyCycleMonth.fromYm(_:_:) ### Description Creates a SixtyCycleMonth instance from a sixty-cycle year and a month index (0-11, with 寅月 as 0). The year is validated via SixtyCycleYear.fromYear. ### Method class func ### Signature `public class func fromYm(_ year: Int, _ index: Int) throws -> Self` ### Parameters - `year` (Int) - Required - 干支年(经 `SixtyCycleYear.fromYear` 校验) - `index` (Int) - Required - 0–11 的月序(寅月=0,自 `year.firstMonth` 推移) ### Return - `Self` - A new SixtyCycleMonth instance. ### Throws - `ArgumentError` if the year is out of range (-1–9999). ``` -------------------------------- ### SolarWeek.indexInYear Source: https://github.com/6tail/tyme4swift The index of this week within the year (starting from the first week of January). ```APIDOC ## SolarWeek.indexInYear ### Description The index of this week within the year (starting from the first week of January). ### Property var indexInYear: Int ``` -------------------------------- ### Event.getSolarDay(_:) Source: https://github.com/6tail/tyme4swift Returns the solar day for the given year that corresponds to this event. Returns nil if the year is earlier than the start year. ```APIDOC ## Event.getSolarDay(_:) ### Description Returns the solar day for the given year that corresponds to this event. Returns nil if the year is earlier than the start year. ### Method getSolarDay ### Signature public func getSolarDay(_ year: Int) -> SolarDay? ### Parameters - **year** (Int) - Required - The year to query. ### Returns - **SolarDay?** - The corresponding solar day, or nil if year < startYear. ``` -------------------------------- ### LoopTyme.fromName(_:) Source: https://github.com/6tail/tyme4swift Creates an instance of a LoopTyme subclass from a given name. Throws an ArgumentError if the name is not in the sequence. ```APIDOC ## LoopTyme.fromName(_:) ### Description Creates an instance of a LoopTyme subclass from a given name. Throws an ArgumentError if the name is not in the sequence. ### Method fromName ### Signature `public class func fromName(_ name: String) throws -> Self` ### Parameters - **name** (String) - Required - The name to create the instance from. Must be in the sequence's names array. ### Returns - **Self** - The created instance. ### Throws - **ArgumentError** - If the name is not in the sequence. ``` -------------------------------- ### SolarMonth.getWeekCount(_:) Source: https://github.com/6tail/tyme4swift Returns the number of weeks in this month, given the start day of the week (1=Monday, 7=Sunday). ```APIDOC ## SolarMonth.getWeekCount(_:) ### Description Returns the number of weeks in this month, given the start day of the week (1=Monday, 7=Sunday). ### Method getWeekCount ### Parameters - **start** (Int) - Required - The start day of the week (1=Monday, 7=Sunday). ### Response Returns an Int representing the number of weeks. ### Request Example ```swift let m = try SolarMonth.fromYm(2024, 2) let weekCount = m.getWeekCount(1) ``` ### Response Example ```swift print(weekCount) // 该月以周一为起始的周数 ``` ``` -------------------------------- ### LoopTyme.next(_:) Source: https://github.com/6tail/tyme4swift Moves the sequence forward or backward by a given number of steps. This is a public override that returns a new instance of the same type. ```APIDOC ## LoopTyme.next(_:) ### Description Moves the sequence forward or backward by a given number of steps. This is a public override that returns a new instance of the same type. ### Method next ### Signature `public override func next(_ n: Int) -> Self` ### Parameters - **n** (Int) - Required - The number of steps to move. Positive moves forward, negative moves backward. ### Returns - **Self** - The resulting instance. ``` -------------------------------- ### SolarMonth.getWeeks(_:) Source: https://github.com/6tail/tyme4swift Returns an array of SolarWeek objects for this month, given the start day of the week (1=Monday, 7=Sunday). ```APIDOC ## SolarMonth.getWeeks(_:) ### Description Returns an array of SolarWeek objects for this month, given the start day of the week (1=Monday, 7=Sunday). ### Method getWeeks ### Parameters - **start** (Int) - Required - The start day of the week (1=Monday, 7=Sunday). ### Response Returns an array of SolarWeek instances. ### Request Example ```swift let m = try SolarMonth.fromYm(2024, 2) let weeks = m.getWeeks(1) ``` ### Response Example ```swift print(weeks.count) // 该月的周数 ``` ``` -------------------------------- ### HijriDay.init(_:_:_:) Source: https://github.com/6tail/tyme4swift Initializes a HijriDay instance with the given year, month, and day. Throws an error if the day is invalid for the specified month. ```APIDOC ## [INIT] HijriDay.init(_:_:_:) ### Description Initializes a HijriDay instance with the given year, month, and day. ### Method init ### Parameters #### Parameters - **year** (Int) - Required - The Hijri year. - **month** (Int) - Required - The Hijri month. - **day** (Int) - Required - The day of the month. ### Throws - `ArgumentError` if the day is not in the range 1 to `hijriMonth.dayCount`. ``` -------------------------------- ### SixtyCycleDay.fromSolarDay(_:) Source: https://github.com/6tail/tyme4swift Creates a SixtyCycleDay instance from a SolarDay. The solar day's term is used to locate the correct sixty-cycle month. ```APIDOC ## [CLASS_METHOD] SixtyCycleDay.fromSolarDay(_:) ### Description Creates a SixtyCycleDay instance from a SolarDay. The solar day's term is used to locate the correct sixty-cycle month. ### Method class func ### Signature `public class func fromSolarDay(_ solarDay: SolarDay) throws -> Self` ### Parameters - `solarDay` (SolarDay) - Required - 公历日(`fromSolarDay` 经 `solarDay.term` 定位节令月) ### Return - `Self` - A new SixtyCycleDay instance. ### Throws - `ArgumentError` if the year is out of range (-1–9999). ``` -------------------------------- ### SixtyCycle.fromIndex(_:) Source: https://github.com/6tail/tyme4swift Creates a SixtyCycle instance from a zero-based index into the sexagenary cycle. The index determines the heavenly stem and earthly branch combination. ```APIDOC ## [CLASS_METHOD] SixtyCycle.fromIndex(_:) ### Description Creates a SixtyCycle instance from a zero-based index into the sexagenary cycle. The index determines the heavenly stem and earthly branch combination. ### Method class func fromIndex(_ index: Int) -> Self ### Parameters - **index** (Int) - Required - The zero-based index (0-59) into the sexagenary cycle. ### Response Returns a SixtyCycle instance. ### Request Example ```swift let g = SixtyCycle.fromIndex(0) ``` ### Response Example ```swift print(g.getName()) // 甲子 print(g.heavenStem.getName(), g.earthBranch.getName()) // 甲 子 print(g.sound.getName(), g.ten.getName()) // 海中金 甲子 print(g.extraEarthBranches.map { $0.getName() }) // 戌 亥 print(g.pengZu.getName()) // 甲不开仓财物耗散 子不问卜自惹祸殃 ``` ``` -------------------------------- ### LunarMonth.getWeeks(_:) Source: https://github.com/6tail/tyme4swift Returns an array of LunarWeek objects representing the weeks in this lunar month, given the start day of the week. ```APIDOC ## [INSTANCE METHOD] LunarMonth.getWeeks(_:) ### Description Returns an array of LunarWeek objects representing the weeks in this lunar month, given the start day of the week. ### Method Instance method ### Signature ```swift public func getWeeks(_ start: Int) -> [LunarWeek] ``` ### Parameters - **start** (Int) - Required - The start day of the week (1 for Monday, 7 for Sunday). ### Return Value An array of LunarWeek objects. ``` -------------------------------- ### SwiftPM Package.swift for Tyme4Swift Source: https://github.com/6tail/tyme4swift Defines the Tyme4Swift package with no third-party dependencies, a single library product, and a test target. Requires swift-tools-version 5.5 or later. ```swift // swift-tools-version:5.5 import PackageDescription let package = Package( name: "Tyme4Swift", products: [ .library(name: "Tyme4Swift", targets: ["Tyme4Swift"]), ], dependencies: [], // 无第三方依赖 targets: [ .target(name: "Tyme4Swift", dependencies: []), .testTarget(name: "Tyme4SwiftTests", dependencies: ["Tyme4Swift"]), ] ) ``` -------------------------------- ### LunarMonth.getWeekCount(_:) Source: https://github.com/6tail/tyme4swift Returns the number of weeks in this lunar month, given the start day of the week (1 for Monday, 7 for Sunday). ```APIDOC ## [INSTANCE METHOD] LunarMonth.getWeekCount(_:) ### Description Returns the number of weeks in this lunar month, given the start day of the week (1 for Monday, 7 for Sunday). ### Method Instance method ### Signature ```swift public func getWeekCount(_ start: Int) -> Int ``` ### Parameters - **start** (Int) - Required - The start day of the week (1 for Monday, 7 for Sunday). ### Return Value The number of weeks in this lunar month. ``` -------------------------------- ### SixtyCycle.next(_:) Source: https://github.com/6tail/tyme4swift Returns a new SixtyCycle instance shifted by the given number of steps in the cycle. Negative values move backward. ```APIDOC ## [INSTANCE_METHOD] SixtyCycle.next(_:) ### Description Returns a new SixtyCycle instance shifted by the given number of steps in the cycle. Negative values move backward. ### Method override func next(_ n: Int) -> Self ### Parameters - **n** (Int) - Required - The number of steps to move forward (positive) or backward (negative). ### Response Returns a new SixtyCycle instance. ``` -------------------------------- ### fromLunarYear(_:) Source: https://github.com/6tail/tyme4swift Creates a KitchenGodSteed instance for the given lunar year. The instance is used to access various agricultural proverbs derived from the first day's sexagenary cycle. ```APIDOC ## [CLASS METHOD] fromLunarYear ### Description Creates a KitchenGodSteed instance for the given lunar year. The instance is used to access various agricultural proverbs derived from the first day's sexagenary cycle. ### Method Class method ### Signature `public class func fromLunarYear(_ lunarYear: Int) throws -> Self` ### Parameters - **lunarYear** (Int) - Required - The lunar year. The first day of the year is inferred via `LunarDay.fromYmd(lunarYear, 1, 1)`. Throws an error if the year is invalid. ### Return Value A new `KitchenGodSteed` instance. ### Example ```swift import Tyme4Swift let ks = try KitchenGodSteed.fromLunarYear(2023) print(ks.mouse) // n鼠偷粮 print(ks.Dragon) // n龙治水 print(ks.Field, ks.Cake) ``` ``` -------------------------------- ### EventType enum definition Source: https://github.com/6tail/tyme4swift Enum with raw Int values representing event types. Provides methods to get name, code, and convert from code or name. ```swift public enum EventType: Int { case SOLAR_DAY = 0 // 公历日期 case SOLAR_WEEK = 1 // 几月第几个星期几 case LUNAR_DAY = 2 // 农历日期 case TERM_DAY = 3 // 节气日期 case TERM_HS = 4 // 节气天干 case TERM_EB = 5 // 节气地支 public func getName() -> String public func getCode() -> Int public static func fromCode(_ code: Int) -> Self? public static func fromName(_ name: String) -> Self? public var description: String } ``` -------------------------------- ### SolarFestival.fromIndex(_:_:) Source: https://github.com/6tail/tyme4swift Returns the solar festival instance for the given year and festival index. Returns nil if the index is out of bounds or the year is earlier than the festival's start year. ```APIDOC ## SolarFestival.fromIndex(_:_:) ### Description Returns the solar festival instance for the given year and festival index. Returns nil if the index is out of bounds or the year is earlier than the festival's start year. ### Method class func fromIndex(_ year: Int, _ index: Int) -> Self? ### Parameters - **year** (Int) - Required - The year of the festival. - **index** (Int) - Required - The index of the festival (0-based). ### Response #### Success Response - **festival** (SolarFestival?) - The festival instance if the index is valid and the year is not earlier than the start year, otherwise nil. ### Request Example ```swift if let f2 = SolarFestival.fromIndex(2021, 1) { print(f2.getName()) // 妇女节 } ``` ``` -------------------------------- ### AbstractTyme.next(_:) Source: https://github.com/6tail/tyme4swift Moves the calendar type forward or backward by a given number of steps. This is the root method for all calendar types, overridden by public subclasses to provide concrete behavior. ```APIDOC ## AbstractTyme.next(_:) ### Description Moves the calendar type forward or backward by a given number of steps. This is the root method for all calendar types, overridden by public subclasses to provide concrete behavior. ### Method next ### Signature `func next(_ n: Int) throws -> Self?` ### Parameters - **n** (Int) - Required - The number of steps to move. Positive moves forward, negative moves backward. ### Returns - **Self?** - The resulting calendar type, or nil for festival types. ### Notes - Internal in the base class; public subclasses override as `public override func next(_ n: Int) throws -> Self` (non-optional) or `throws -> Self?` (festival types). ``` -------------------------------- ### Phase.fromIndex(_:_:_:) Source: https://github.com/6tail/tyme4swift Creates a Phase instance from a lunar year, lunar month, and a 0-7 phase index. The index can be extended arbitrarily and automatically crosses months. ```APIDOC ## Phase.fromIndex(_:_:_:) ### Description Creates a Phase instance from a lunar year, lunar month, and a 0-7 phase index. The index can be extended arbitrarily and automatically crosses months. ### Method Class method ### Signature `public class func fromIndex(_ lunarYear: Int, _ lunarMonth: Int, _ index: Int) throws -> Self` ### Parameters - **lunarYear** (Int) - Required - Lunar year. The month is automatically advanced by `index/8`. - **lunarMonth** (Int) - Required - Lunar month (negative indicates leap month). - **index** (Int) - Required - Phase index 0-7, can be extended arbitrarily (auto-crosses months). ### Throws `LunarMonth` validation errors for invalid lunar year/month or leap month. ### Example ```swift import Tyme4Swift let p = try Phase.fromIndex(2020, 5, 3) // 2020年五月盈凸月 print(p.getName(), p.solarDay.description) // 盈凸月 2020年6月29日前后 print(try p.next(1).getName()) // 满月 print(try SolarDay.fromYmd(2020, 5, 29).phase.getName()) ``` ``` -------------------------------- ### ThreePillars.getSolarDays(_:_:) Source: https://github.com/6tail/tyme4swift Returns an array of SolarDay objects that match this ThreePillars within the given year range. The search starts from the beginning of spring (立春) and steps by 60 years. ```APIDOC ## ThreePillars.getSolarDays(_:_:) ### Description Returns an array of SolarDay objects that match this ThreePillars within the given year range. The search starts from the beginning of spring (立春) and steps by 60 years. ### Method func getSolarDays(_ startYear: Int, _ endYear: Int) -> [SolarDay] ### Parameters - **startYear** (Int) - Required - The start year of the search range (inclusive). - **endYear** (Int) - Required - The end year of the search range (inclusive). ### Returns - **[SolarDay]** - An array of SolarDay objects that match this ThreePillars. ``` -------------------------------- ### SixtyCycleMonth.next(_:) Source: https://github.com/6tail/tyme4swift Returns a new SixtyCycleMonth offset by n months. The offset can be positive or negative. ```APIDOC ## [METHOD] SixtyCycleMonth.next(_:) ### Description Returns a new SixtyCycleMonth offset by n months. The offset can be positive or negative. ### Method instance method ### Signature `public override func next(_ n: Int) throws -> Self` ### Parameters - `n` (Int) - Required - The number of months to offset. ### Return - `Self` - The new SixtyCycleMonth instance. ### Throws - `ArgumentError` if the resulting year is out of range. ``` -------------------------------- ### SixtyCycleDay.next(_:) Source: https://github.com/6tail/tyme4swift Returns a new SixtyCycleDay offset by n days. The offset can be positive or negative. ```APIDOC ## [METHOD] SixtyCycleDay.next(_:) ### Description Returns a new SixtyCycleDay offset by n days. The offset can be positive or negative. ### Method instance method ### Signature `public override func next(_ n: Int) throws -> Self` ### Parameters - `n` (Int) - Required - The number of days to offset. ### Return - `Self` - The new SixtyCycleDay instance. ### Throws - `ArgumentError` if the resulting year is out of range. ``` -------------------------------- ### EarthBranch.fromIndex(_:) Source: https://github.com/6tail/tyme4swift Creates an EarthBranch instance from a zero-based index into the NAMES array. ```APIDOC ## EarthBranch.fromIndex(_:) ### Description Creates an EarthBranch instance from a zero-based index into the NAMES array. ### Method class func fromIndex(_ index: Int) -> Self ### Parameters - **index** (Int) - Required - The zero-based index into the NAMES array. ### Returns - **Self** - An EarthBranch instance corresponding to the given index. ``` -------------------------------- ### LunarWeek.fromYm Source: https://github.com/6tail/tyme4swift Creates a LunarWeek instance for the given lunar year, month, week index, and week start day. Throws an error if the week index is out of range. ```APIDOC ## [CLASS_METHOD] LunarWeek.fromYm ### Description Creates a LunarWeek instance for the given lunar year, month, week index, and week start day. Throws an error if the week index is out of range. ### Method class func fromYm ### Signature ```swift public class func fromYm(_ year: Int, _ month: Int, _ index: Int, _ start: Int) throws -> Self ``` ### Parameters - **year** (Int) - Required - Lunar year - **month** (Int) - Required - Lunar month (can be negative for leap months) - **index** (Int) - Required - Week index, 0–5 and less than `m.getWeekCount(start)`. Throws `"illegal lunar week index: \(index) in month: \(m)"` if out of range. - **start** (Int) - Required - Week start day, 0–6 ### Return Value - **Self** - A LunarWeek instance ### Request Example ```swift import Tyme4Swift let w = try LunarWeek.fromYm(2023, 2, 0, 1) print(w.description, w.days.count) // 农历癸卯年二月第1周 7 ``` ``` -------------------------------- ### SolarWeek.days Source: https://github.com/6tail/tyme4swift The list of SolarDay instances for this week. ```APIDOC ## SolarWeek.days ### Description The list of SolarDay instances for this week. ### Property var days: [SolarDay] ``` -------------------------------- ### SolarTerm.next(_:) Source: https://github.com/6tail/tyme4swift 返回当前节气偏移 n 个节气后的新实例。 ```APIDOC ## SolarTerm.next(_:) ### Description 返回当前节气偏移 n 个节气后的新实例。 ### Method instance method ### Signature ```swift public override func next(_ n: Int) -> Self ``` ### Parameters - **n** (Int) - Required - 偏移量,正数向后,负数向前 ### Return Value - **Self** - 偏移后的节气实例 ``` -------------------------------- ### SolarYear usage example Source: https://github.com/6tail/tyme4swift Creates a SolarYear for 2024 and prints leap status, day count, month count, and the previous year. Outputs true 366, 12, and 2023 respectively. ```swift import Tyme4Swift let y = try SolarYear.fromYear(2024) print(y.isLeap, y.dayCount) // true 366 print(y.months.count) // 12 print(try y.next(-1).year) // 2023 ``` -------------------------------- ### AbstractCulture 类声明 Source: https://github.com/6tail/tyme4swift 公开基类,提供 description、isEqual、indexOf、floorDiv 和 validateRange 等基础设施方法。validateRange 在值越界时抛出 ArgumentError。 ```swift public class AbstractCulture: NSObject, Culture { public override var description: String func getName() -> String // internal,子类公开覆写 public override func isEqual(_ t: Any?) -> Bool public func indexOf(_ index: Int, _ size: Int) -> Int public func floorDiv(_ a: Int, _ b: Int) -> Int public class func validateRange(_ value: Int, _ min: Int, _ max: Int, _ field: String) throws } ``` -------------------------------- ### SolarWeek.firstDay Source: https://github.com/6tail/tyme4swift The first day of this solar week as a SolarDay instance. ```APIDOC ## SolarWeek.firstDay ### Description The first day of this solar week as a SolarDay instance. ### Property var firstDay: SolarDay ```