加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
calendar.go 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
package carbon
import (
"gitee.com/dromara/carbon/v2/calendar/julian"
"gitee.com/dromara/carbon/v2/calendar/lunar"
"gitee.com/dromara/carbon/v2/calendar/persian"
)
// Lunar converts Carbon instance to Lunar instance.
// 将 Carbon 实例转化为 Lunar 实例
func (c Carbon) Lunar() (l lunar.Lunar) {
if c.Error != nil {
l.Error = c.Error
return
}
return lunar.FromGregorian(c.StdTime()).ToLunar()
}
// CreateFromLunar creates a Carbon instance from Lunar date and time.
// 从 农历日期 创建 Carbon 实例
func CreateFromLunar(year, month, day, hour, minute, second int, isLeapMonth bool) Carbon {
t := lunar.FromLunar(year, month, day, hour, minute, second, isLeapMonth).ToGregorian().Time
return CreateFromStdTime(t)
}
// Julian converts Carbon instance to Julian instance.
// 将 Carbon 实例转化为 Julian 实例
func (c Carbon) Julian() (j julian.Julian) {
if c.Error != nil {
return
}
return julian.FromGregorian(c.StdTime()).ToJulian()
}
// CreateFromJulian creates a Carbon instance from Julian Day or Modified Julian Day.
// 从 儒略日/简化儒略日 创建 Carbon 实例
func CreateFromJulian(f float64) Carbon {
t := julian.FromJulian(f).ToGregorian().Time
return CreateFromStdTime(t)
}
// Persian converts Carbon instance to Persian instance.
// 将 Carbon 实例转化为 Persian 实例
func (c Carbon) Persian() (p persian.Persian) {
if c.Error != nil {
return
}
return persian.FromGregorian(c.StdTime()).ToPersian()
}
// CreateFromPersian creates a Carbon instance from Persian date and time.
// 从 波斯日期 创建 Carbon 实例
func CreateFromPersian(year, month, day, hour, minute, second int) Carbon {
t := persian.FromPersian(year, month, day, hour, minute, second).ToGregorian().Time
return CreateFromStdTime(t)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化