Documentation ¶
Index ¶
- Constants
- func B2i(b bool) int
- func BeginningOfMonth(t time.Time) time.Time
- func DayChinese(d int) string
- func EndOfMonth(t time.Time) time.Time
- func GregorianMonthDays(year, month int) int
- func I2b(i int) bool
- func IsLeapYear(year int) bool
- func JdToTime(jd float64, loc *time.Location) time.Time
- func JdToTimeMap(jd float64) map[string]int
- func JulianDay(year, month, day float64, timeParts ...float64) float64
- func Mjd(year, month, day float64, timeParts ...float64) float64
- func MjdToTimeMap(mjd float64) map[string]int
- func Pow(x float64, n int) float64
- func Round(n float64, prec int) float64
- func StarSign(month, day int) (int, string, error)
- func StringSplice(str ...string) string
- func TimeMapToTime(tm map[string]int, loc *time.Location) time.Time
- type Calendar
- func (c *Calendar) ChineseSexagenaryCycle(t time.Time) GZ
- func (c *Calendar) Clone() *Calendar
- func (c *Calendar) Generate() []*CalendarItem
- func (c *Calendar) GenerateWithDate(year, month, day int, timeParts ...int) []*CalendarItem
- func (c *Calendar) GetConfig() CalendarConfig
- func (c *Calendar) GetRawTime() time.Time
- func (c *Calendar) GregorianToLunar(year, month, day int) LunarDate
- func (c *Calendar) LunarLeap(lunarYear int) int
- func (c *Calendar) LunarMonthDays(lunarYear, lunarMonth int, isLeap bool) (int, error)
- func (c *Calendar) LunarToGregorian(lunarYear, lunarMonth, lunarDay int, isLeap bool) (time.Time, error)
- func (c *Calendar) NextMonth() []*CalendarItem
- func (c *Calendar) NextYear() []*CalendarItem
- func (c *Calendar) PreviousMonth() []*CalendarItem
- func (c *Calendar) PreviousYear() []*CalendarItem
- func (c *Calendar) SetRawTime(year, month, day int, timeParts ...int) *Calendar
- func (c *Calendar) SolarTerms(year int) []*SolarTermItem
- type CalendarConfig
- type CalendarItem
- type CalendarTempData
- type FestivalItem
- type GZ
- type GZItem
- type LunarDate
- type SolarTermItem
- type StarSignItem
Constants ¶
const ( GridDay int = iota GridWeek GridMonth )
取日历方式
const Author = "[email protected]"
const Version = "1.1.0"
Variables ¶
This section is empty.
Functions ¶
func GregorianMonthDays ¶ added in v1.1.0
GregorianMonthDays 公历某月的总天数
func JdToTime ¶ added in v1.1.0
JdToTime 将儒略日转成loc时区的 *time.Time
该方法未将TT转为UTC,而是将TT等于UTC,如需TT日期,请使用 JdToTimeMap 方法
func JdToTimeMap ¶ added in v1.1.0
JdToTimeMap 儒略日计算对应的日期时间(TT)
(特别提醒,我们将一个日期时间转为儒略日时,其实使用的并不是真正的TT时间,而是我们常用的UTC或当地时区时间,故此无需考虑TT与UTC之间的转换)
func JulianDay ¶ added in v1.1.0
JulianDay 计算日期时间(TT)的儒略日
(特别提醒,我们将一个日期时间转为儒略日时,其实使用的并不是真正的TT时间,而是我们常用的UTC或当地时区时间,故此无需考虑TT与UTC之间的转换)
func Mjd ¶ added in v1.1.0
Mjd 计算日期时间(TT)的简化儒略日
简化儒略日(Modified Julian Day, MJD)是将儒略日(Julian Day, JD)进行简化后得到的新计时法。 1957年,简化儒略日由史密松天体物理台(Smithsonian Astrophysical Observatory)引入。 1957年史密松天体物理台为便用于记录“伴侣号”人造卫星的轨道,将儒略日进行了简化,并将其命名为简化儒略日,其定义为: MJD=JD-2400000.5 儒略日2400000是1858年11月16日,因为JD从中午开始计算,所以简化儒略日的定义中引入偏移量0.5, 这意味着MJD 0相当于1858年11月17日的凌晨,并且每一个简化儒略日都在世界时午夜开始和结束.
func MjdToTimeMap ¶ added in v1.1.0
MjdToTimeMap 简化儒略日计算对应的日期时间(TT)
Types ¶
type Calendar ¶
type Calendar struct { Items []*CalendarItem `json:"items"` // 日历表中所有的日期单元 // contains filtered or unexported fields }
type Calendar struct 日历表
func (*Calendar) ChineseSexagenaryCycle ¶ added in v1.1.0
(*Calendar) ChineseSexagenaryCycle 日期时间对应的干支
特别提醒:干支推算的日干支存在早晚子时的区别 NightZiHour默认为false是不区分早晚子时00:00-02:00为子时,NightZiHour为true时,23:00-24:00 00:00-01:00为子时
func (*Calendar) Generate ¶ added in v1.1.0
func (c *Calendar) Generate() []*CalendarItem
(*Calendar) Generate 生成日历表
func (*Calendar) GenerateWithDate ¶ added in v1.1.0
func (c *Calendar) GenerateWithDate(year, month, day int, timeParts ...int) []*CalendarItem
(*Calendar) GenerateWithDate 用指定的年月日时分秒生成日历表
func (*Calendar) GetConfig ¶ added in v1.1.0
func (c *Calendar) GetConfig() CalendarConfig
(*Calendar) GetConfig 读取配置 返回的是一个clone
func (*Calendar) GetRawTime ¶ added in v1.1.0
(*Calendar) GetRawTime 取出rawTime
返回的将是c.rawTime的一个clone
func (*Calendar) GregorianToLunar ¶ added in v1.1.0
(*Calendar) GregorianToLunar 公历转农历
@param int year 公历年份 @param int month 公历月份 @param int day 公历日
func (*Calendar) LunarMonthDays ¶ added in v1.1.0
(*Calendar) LunarMonthDay 农历某个月有多少天
@param int lunarYear 农历年数字 @param int lunarMonth 农历月数字 @param bool isLeap 是否是闰月
func (*Calendar) LunarToGregorian ¶ added in v1.1.0
func (c *Calendar) LunarToGregorian(lunarYear, lunarMonth, lunarDay int, isLeap bool) (time.Time, error)
(*Calendar) LunarToGregorian 农历转公历
demo:
c := DefaultCalendar() gd,_ := dc.LunarToGregorian(2020,4,14,true) fmt.Println(gd.Format(time.RFC3339))
@param int lunarYear 农历年份 @param int lunarMonth 农历月份 @param int lunarDay 农历日 @param bool isLeap 输入的日期是否是闰月的农历日期
func (*Calendar) NextMonth ¶ added in v1.1.0
func (c *Calendar) NextMonth() []*CalendarItem
(*Calendar) NextMonth 下一个月
func (*Calendar) NextYear ¶ added in v1.1.0
func (c *Calendar) NextYear() []*CalendarItem
(*Calendar) NextYear 下一年
func (*Calendar) PreviousMonth ¶ added in v1.1.0
func (c *Calendar) PreviousMonth() []*CalendarItem
(*Calendar) PreviousMonth 上一个月
func (*Calendar) PreviousYear ¶ added in v1.1.0
func (c *Calendar) PreviousYear() []*CalendarItem
(*Calendar) PreviousYear 上一年
func (*Calendar) SetRawTime ¶ added in v1.1.0
(*Calendar) SetRawTime 设置rawTime
该方法返回的*Calendar是清除与rawTime相关值的c *Calendar,这样做是为了支持链接使用, 因此该方法必需在相关取值之前使用
func (*Calendar) SolarTerms ¶ added in v1.1.0
func (c *Calendar) SolarTerms(year int) []*SolarTermItem
(*Calendar) SolarTerms 一整年的节气
从上一年的冬至开始到下一年的小寒共26个节气对应的日期时间, 设置c.stMap的值 map[string]*SolarTerm是一个以"年-月-日"为索引的map, 返回[]*SolarTerm是一个有序切片
type CalendarConfig ¶ added in v1.1.0
type CalendarConfig struct { Grid int // 取日历方式,GridDay按天取日历,GridWeek按周取日历,GridMonth按月取日历 FirstWeek int // 日历显示时第一列显示周几,(日历表第一列是周几,0周日,依次最大值6) TimeZoneName string // 时区名称,需php支持的时区名称 SolarTerms bool // 读取节气 bool Lunar bool // 读取农历 bool HeavenlyEarthly bool // 读取干支 bool NightZiHour bool // 区分早晚子时,true则 23:00-24:00 00:00-01:00为子时,否则00:00-02:00为子时 StarSign bool // 读取星座 }
type CalendarConfig struct 配置
type CalendarItem ¶ added in v1.1.0
type CalendarItem struct { Time *time.Time `json:"time"` // 格里高历(公历)时间 IsAccidental int `json:"isam"` // 0为本月日期,-1为上一个月的日期,1为下一个月的日期, IsToday int `json:"istoday"` // 是否是今天,0不是,1是 Festival *FestivalItem `json:"festival"` // 公历节日 SolarTerm *SolarTermItem `json:"st"` // 节气 GZ *GZ `json:"gz"` // 干支 LunarDate *LunarDate `json:"ld"` // 农历 StarSign *StarSignItem `json:"ss"` // 星座 }
type CalendarItem struct 日历单元
func (CalendarItem) String ¶ added in v1.1.0
func (ci CalendarItem) String() string
(CalendarItem) String 日历单元显示
type CalendarTempData ¶ added in v1.1.0
type CalendarTempData struct {
// contains filtered or unexported fields
}
Calendar的一些临时数据
type FestivalItem ¶ added in v1.1.0
type FestivalItem struct { Show []string `json:"show"` // 在日历表上显示的节日 Secondary []string `json:"scdr"` // 其它次要节日 }
type FestivalItem struct 节日单元
type GZ ¶ added in v1.1.0
type GZ struct { Year *GZItem `json:"ygz"` // 年天干地支 Month *GZItem `json:"mgz"` // 月天干地支 Day *GZItem `json:"dgz"` // 日天干地支 Hour *GZItem `json:"hgz"` // 时天干地支 }
type GZ 日期时间干支
type GZItem ¶ added in v1.1.0
type GZItem struct { HSI int `json:"hsi"` // 天干索引 HSN string `json:"hsn"` // 天干名称 EBI int `json:"ebi"` // 地支索引 EBN string `json:"ebn"` // 地支名称 }
type GZItem 天干地支单元
type LunarDate ¶
type LunarDate struct { Year int `json:"year"` // 年 Month int `json:"month"` // 月 Day int `json:"day"` // 日 MonthName string `json:"monthName"` // 月份名称 DayName string `json:"dayName"` // 日名称 LeapStr string `json:"leapStr"` // 闰字,可以用该值是否为空来判断该月是否为闰月 YearLeapMonth int `json:"ylm"` // 该年闰几月,如果该年无闰月,则0,该年闰几月该值就是几,也可以用LeapMonth == Month判断该月是否闰月 AnimalIndex int `json:"sai"` // 年生肖索引 AnimalName string `json:"san"` // 年生肖名称 YearGZ *GZItem `json:"ygz"` // 年干支 Festival *FestivalItem `json:"festival"` // 农历节日 }
type LunarDate 农历
type SolarTermItem ¶ added in v1.1.0
type SolarTermItem struct { Index int `json:"index"` // 节气索引 Name string `json:"name"` // 节气名称 Time *time.Time `json:"time"` // 定节气时间 }
type SolarTermItem struct 节气
func (SolarTermItem) String ¶ added in v1.1.0
func (st SolarTermItem) String() string
(SolarTermItem) String 节气显示
type StarSignItem ¶ added in v1.1.0
type StarSignItem struct 星座单元