VietnameseLunarDateSwift

GitHub release (release name instead of tag name) actions codecov

用于将日期转换为越南农历日期的库。 该库使用 Hồ Ngọc Đức 的算法。 更多详情请访问以下链接:http://www.informatik.uni-leipzig.de/~duc/amlich/

特性

安装

Swift Package Manager

Swift Package Manager 是一种用于自动化 Swift 代码分发的工具。

您可以通过选择 File - Swift Packages - Add Package Dependency 选项将 Telegraph 添加到您的项目中。 使用下面指定的存储库 URL 并选择您要使用的版本。

或者您可以手动添加一个 Package.swift 文件到您的项目中,内容如下:

dependencies: [
    .package(url: "https://github.com/HoaPham98/VietnameseLunarDateSwift.git")
]

用法

将日期从公历转换为越南农历日期

import VietnameseLunarDateSwift
....

let date = Date() // 17/09/2024
let lunarDate = LunarDate(from: date)
// or
let newDate = date.lunarDate // 15/08/2024

检查此日期是否在闰月

import VietnameseLunarDateSwift
....

let date = calendar.date(from: DateComponents(year: 2023, month: 3, day: 22))! // 01/02/2023 (leap month)
let lunarDate = date.lunarDate

print(lunarDate.day) // 1
print(lunarDate.month) // 2
print(lunarDate.isLeap) // true

获取信息

import VietnameseLunarDateSwift
....

et date = Date() // 17/09/2024
let lunarDate = date.lunarDate // 15/08/2024

let info = date.info
// date: Giap than
// month: Quy Dau
// year: Giap Thin

待办事项