calendar

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2022 License: Apache-2.0, MIT Imports: 9 Imported by: 0

README

calendar

Chinese Lunar Calendar, Solar Calendar and cron time rules.

About

//Solar structure
type Solar struct {
	time.Time
}

//Luanr structure
type Lunar struct {
	year        int
	month       int
	day         int
	hour        int
	minute      int
	second      int
	nanosecond  int
	leapMonth   int
	isLeapMonth bool
}
func NewSolar(year, month, day, hour, min, sec, nsec int) *Solar
func NewSolarNow() *Solar
func NewLunar(year, month, day, hour, min, sec, nsec int, leapFirst bool) *Lunar
func NewLunarNow() *Lunar

Lunar or Solar has a method Convert to convert itself to the opposite one.

func (s *Solar) Convert() *Lunar
func (l *Lunar) Convert() *Solar
func (l Lunar) Add(years, months, days, hours, mins, secs, nsecs int) *Lunar

NOTICE

This package's year range is [1900,2050] and month range is [1,12].

Example

package main

import "github.com/38888/go-tagexpr-new/goutil/calendar"
import "fmt"

func main() {
	l0 := lunar.NewLunar(1988, 2, 11, 9, 9, 9, 0, false)
	fmt.Println(l0)
	s0 := l0.Convert()
	fmt.Println(s0)

	s1 := lunar.NewSolar(1988, 3, 28, 9, 9, 9, 0)
	fmt.Println(s1)
	l1 := s0.Convert()
	fmt.Println(l1)

	s := lunar.NewSolarNow()
	fmt.Println(s)

	l := lunar.NewLunarNow()
	fmt.Println(l)

	s2l := s.Convert()
	fmt.Println(s2l)

	l2s := l.Convert()
	fmt.Println(l2s)
}

Cron

cron

Documentation

Index

Constants

View Source
const (
	// MinYear smallest year of support
	MinYear = 1900
	// MaxYear largest year of support
	MaxYear = 2050
)

Variables

View Source
var (
	SolarFestivals = FestivalMap{
		"0101": "元旦",
		"0214": "情人节",
		"0308": "妇女节",
		"0312": "植树节",
		"0401": "愚人节",
		"0422": "地球日",
		"0501": "劳动节",
		"0504": "青年节",
		"0531": "无烟日",
		"0601": "儿童节",
		"0606": "爱眼日",
		"0701": "建党日",
		"0707": "抗战纪念日",
		"0801": "建军节",
		"0910": "教师节",
		"0918": "九·一八事变纪念日",
		"1001": "国庆节",
		"1031": "万圣节",
		"1111": "光棍节",
		"1201": "艾滋病日",
		"1213": "南京大屠杀纪念日",
		"1224": "平安夜",
		"1225": "圣诞节",
	}
	LunarFestivals = FestivalMap{
		"0101": "春节",
		"0115": "元宵节",
		"0202": "龙抬头",
		"0505": "端午节",
		"0707": "七夕",
		"0715": "中元节",
		"0815": "中秋节",
		"0909": "重阳节",
		"1208": "腊八节",
		"1223": "小年",
		"0100": "除夕",
	}
)
View Source
var (
	// 1900 2月春分后为 庚子年
	GanTable    = []string{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
	ZhiTable    = []string{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
	AnimalTable = []string{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}
)
View Source
var (

	// CST  CST China Standard Time UT 8:00
	CST = time.FixedZone("CST", 3600*8)
)
View Source
var JieQiCTable = [2][24]float64{
	{6.11, 20.84, 4.6295, 19.4599, 6.3826, 21.4155, 5.59, 20.888, 6.318, 21.86,
		6.5, 22.2, 7.928, 23.65, 8.35, 23.95, 8.44, 23.822, 9.098, 24.218, 8.218, 23.08, 7.9, 22.6},
	{5.4055, 20.12, 3.87, 18.73, 5.63, 20.646, 4.81, 20.1, 5.52, 21.04, 5.678,
		21.37, 7.108, 22.83, 7.5, 23.13, 7.646, 23.042, 8.318, 23.438, 7.438, 22.36, 7.18, 21.94},
}
View Source
var JieQiTable = []string{
	"小寒", "大寒", "立春", "雨水", "惊蛰", "春分",
	"清明", "谷雨", "立夏", "小满", "芒种", "夏至",
	"小暑", "大暑", "立秋", "处暑", "白露", "秋分",
	"寒露", "霜降", "立冬", "小雪", "大雪", "冬至",
}
View Source
var JieQiTableBase = []int{4, 19, 3, 18, 4, 19, 4, 19, 4, 20, 4, 20, 6, 22, 6, 22, 6, 22, 7, 22, 6, 21, 6, 21}
View Source
var JieQiTableIdx = "" /* 202-byte string literal not displayed */
View Source
var JieQiTableOffset = "" /* 1656-byte string literal not displayed */
View Source
var LunarZero = NewLunar(MinYear, 1, 1, 0, 0, 0, 0, false)

LunarZero lunar zero time.

Functions

func AnimalYear

func AnimalYear(year int) string

Sheng Xiao

func DiffYMD

func DiffYMD(year, month, day, targetYear, targetMonth, targetDay int) int

DiffYMD returns the number of days that the target time exceeds the specified time.

func Gan

func Gan(x int) string

Tian Gan

func GanZhi

func GanZhi(x int) string

Tian Gan && Di Zhi

func GanZhiYMD

func GanZhiYMD(sYear, sMonth, sDay int) (gzYear, gzMonth, gzDay string)

Input: solar (year,month,day)

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear determines whether it is a leap year.

func IsLunarZero

func IsLunarZero(l *Lunar) bool

IsLunarZero judge whether the lunar time is equal to lunar zero time.

func JieQi

func JieQi(year, n int) int

y年的第n个节气为几日 n range [1,24]

func JieQiDay

func JieQiDay(year, month int) (firstDayName string, firstDay int, secondDayName string, secondDay int)

func JieQisOfMonth

func JieQisOfMonth(year, m int) (first, second int)

month range [1,12]

func JieQisOfYear

func JieQisOfYear(year int) (list [12][2]int)

func LeapDays

func LeapDays(year int) int

LeapDays the days of this year's leap month

func LeapMonth

func LeapMonth(year int) int

LeapMonth which month leaps in this year? return 1-12(if there is one) or 0(no leap month).

func LunarDayString

func LunarDayString(day int) (s string)

LunarDayString used Only by Lunar Object

func LunarMonthDays

func LunarMonthDays(year, month int) int

LunarMonthDays the days of the m-th month of this year.

func LunarMonthString

func LunarMonthString(month int, leap bool) string

LunarMonthString used Only by Lunar Object

func LunarMonths

func LunarMonths(year int) int

LunarMonths the total lunar months of this year

func LunarYearDays

func LunarYearDays(year int) int

LunarYearDays the total days of this year

func LunarYearString

func LunarYearString(year int) string

LunarYearString used Only by Lunar Object

func SolarMonthDays

func SolarMonthDays(year int, month int) int

SolarMonthDays the days of the m-th month of this year.

func SplitDuration

func SplitDuration(second, nanosecond int) (days, hours, minutes, seconds, nsecs int)

SplitDuration split duration, accurate to second.

func Zhi

func Zhi(x int) string

Di Zhi

func ZhiHour

func ZhiHour(hour int) (zHour string)

hour range [0,23] return: start point DiZhi

Types

type FestivalMap

type FestivalMap map[string]string

func NewFestivalMap

func NewFestivalMap() FestivalMap

func NewFestivalsFromFile

func NewFestivalsFromFile(filename string) FestivalMap

func (FestivalMap) Add

func (fm FestivalMap) Add(key, val string)

func (FestivalMap) Del

func (fm FestivalMap) Del(key string)

func (FestivalMap) Get

func (fm FestivalMap) Get(key string) (string, error)

func (FestivalMap) SaveToFile

func (fm FestivalMap) SaveToFile(filename string) error

type Lunar

type Lunar struct {
	// contains filtered or unexported fields
}

Lunar structure

func NewLunar

func NewLunar(year, month, day, hour, min, sec int, nsec int, leapFirst bool) *Lunar

NewLunar creates a lunar time. NOTE:

The time zone is +0800(CST)

func NewLunarNow

func NewLunarNow() *Lunar

NewLunarNow creates current lunar time.

func NewLunarTime

func NewLunarTime(t time.Time) *Lunar

NewLunarTime creates a lunar time from time.Time.

func (Lunar) Add

func (l Lunar) Add(years, months, days, hours, mins, secs, nsecs int) *Lunar

Add adds lunar time, and returns the result of lunar time.

func (*Lunar) AnimalYear

func (l *Lunar) AnimalYear() string

AnimalYear returns the animal year.

func (*Lunar) Convert

func (l *Lunar) Convert() *Solar

Convert converts to a solar calendar time.

func (Lunar) Copy

func (l Lunar) Copy() *Lunar

Copy returns a copy .

func (*Lunar) Day

func (l *Lunar) Day() int

Day returns day.

func (*Lunar) DayStr

func (l *Lunar) DayStr() string

DayStr returns day string.

func (*Lunar) Equal

func (l *Lunar) Equal(lunar *Lunar) bool

Equal returns whether it is equal to the lunar time.

func (*Lunar) Festival

func (l *Lunar) Festival(fm FestivalMap) (string, error)

Festival returns festival.

func (*Lunar) GetTime

func (l *Lunar) GetTime() time.Time

GetTime returns the time.Time

func (*Lunar) Hour

func (l *Lunar) Hour() int

Hour returns hour.

func (*Lunar) IsLeapMonth

func (l *Lunar) IsLeapMonth() bool

IsLeapMonth returns whether it is leap month.

func (*Lunar) LeapMonth

func (l *Lunar) LeapMonth() int

LeapMonth returns leap month number.

func (*Lunar) Minute

func (l *Lunar) Minute() int

Minute returns minute.

func (*Lunar) Month

func (l *Lunar) Month() int

Month returns month.

func (Lunar) MonthFirst

func (l Lunar) MonthFirst() *Lunar

MonthFirst returns lunar time of the month 1 day.

func (Lunar) MonthLast

func (l Lunar) MonthLast() *Lunar

MonthLast returns to the last day of the month.

func (*Lunar) MonthStr

func (l *Lunar) MonthStr() string

MonthStr returns month string

func (*Lunar) Nanosecond

func (l *Lunar) Nanosecond() int

Nanosecond returns nanosecond.

func (*Lunar) Second

func (l *Lunar) Second() int

Second returns second.

func (*Lunar) SetHour

func (l *Lunar) SetHour(hour int) *Lunar

SetHour sets hour. NOTE: hour range [0:23].

func (*Lunar) SetMinute

func (l *Lunar) SetMinute(minute int) *Lunar

SetMinute sets minute. NOTE: minute range [0:59].

func (*Lunar) SetNanosecond

func (l *Lunar) SetNanosecond(nanosecond int) *Lunar

SetNanosecond sets nanosecond. NOTE: nanosecond range [0:999999999].

func (*Lunar) SetSecond

func (l *Lunar) SetSecond(second int) *Lunar

SetSecond sets second. NOTE: second range [0:59].

func (*Lunar) String

func (l *Lunar) String() string

String formats time.

func (Lunar) Truncate

func (l Lunar) Truncate(d time.Duration) *Lunar

Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t unchanged.

Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.

func (*Lunar) Weekday

func (l *Lunar) Weekday() time.Weekday

Weekday returns weekday.

func (*Lunar) WeekdayStr

func (l *Lunar) WeekdayStr() string

WeekdayStr returns weekday.

func (*Lunar) Year

func (l *Lunar) Year() int

Year returns year.

type Solar

type Solar struct {
	time.Time
}

Solar structure

func NewSolar

func NewSolar(year, month, day, hour, min, sec int, nsec int, loc *time.Location) *Solar

NewSolar creates a solar time.

func NewSolarNow

func NewSolarNow() *Solar

NewSolarNow creates current solar time.

func NewSolarTime

func NewSolarTime(t time.Time) *Solar

NewSolarTime creates a solar time from time.Time.

func (Solar) AddMonth

func (s Solar) AddMonth(months int) *Solar

AddMonth add months

func (*Solar) Convert

func (s *Solar) Convert() *Lunar

Convert converts to a lunar calendar time.

func (*Solar) DiffWithYMD

func (s *Solar) DiffWithYMD(year, month, day int) int

DiffWithYMD returns the number of days past the current time.

func (*Solar) Equal

func (s *Solar) Equal(solar *Solar) bool

Equal returns whether it is equal to the solar time.

func (*Solar) Festival

func (s *Solar) Festival(fm FestivalMap) (string, error)

Festival returns festival.

func (*Solar) GanzhiYMD

func (s *Solar) GanzhiYMD() (year, month, day string)

GanzhiYMD returns the year, month and day of "天干地支".

func (*Solar) GetTime

func (s *Solar) GetTime() time.Time

GetTime returns the time.Time

func (*Solar) String

func (s *Solar) String() string

String formats time.

func (Solar) Truncate

func (s Solar) Truncate(d time.Duration) *Solar

Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t unchanged.

Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.

Directories

Path Synopsis
Package cron implements a cron spec parser and job runner.
Package cron implements a cron spec parser and job runner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL