0
0
mirror of https://github.com/crazy-max/diun.git synced 2024-12-22 19:38:28 +00:00
crazy-max_diun/vendor/github.com/dromara/carbon/v2/calendar.go

62 lines
1.8 KiB
Go

package carbon
import (
"github.com/dromara/carbon/v2/calendar/julian"
"github.com/dromara/carbon/v2/calendar/lunar"
"github.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) (c Carbon) {
p := persian.FromPersian(year, month, day, hour, minute, second)
if p.Error != nil {
c.Error = p.Error
return
}
t := p.ToGregorian().Time
return CreateFromStdTime(t)
}