warrially / bazigo Goto Github PK
View Code? Open in Web Editor NEWGO语言的八字库
License: Other
GO语言的八字库
License: Other
代码如下
func bz(t time.Time) string {
pBazi := bazi.GetBazi(t.Year(), int(t.Month()), t.Day(), t.Hour(), t.Minute(), t.Second(), 0)
sz := pBazi.SiZhu()
s := sz.YearZhu().GanZhi().ToString() + sz.MonthZhu().GanZhi().ToString() + sz.DayZhu().GanZhi().ToString() + sz.HourZhu().GanZhi().ToString()
return s
}
begin := time.Date(1931, 9, 18, 0, 0, 0, 0, time.Local)
end := time.Date(2020, 1, 1, 0, 0, 0, 0, time.Local)
for t := begin; end.After(t); t = t.AddDate(0, 1, 0) {
println(t.Format("2006-01-02 15:04:05"), bz(t))
}
出现如下错误
PS D:\lab\go\bazi> go run .\main.go
1931-09-18 00:00:00
1931-09-18 00:00:00 辛未丁酉丙子戊子
1931-10-18 00:00:00 辛未戊戌丙午戊子
1931-11-18 00:00:00 辛未己亥丁丑庚子
1931-12-18 00:00:00 辛未庚子丁未庚子
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xac8caa]
goroutine 1 [running]:
github.com/warrially/BaziGo.(*TLunarDate).GetAllDays(...)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/lunardate.go:851
github.com/warrially/BaziGo.(*TLunarDate).Get64TimeStamp(...)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/lunardate.go:335
github.com/warrially/BaziGo.(*TLunarDate).GetMonthFrom64TimeStamp(0xc000052050, 0xe30318100)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/lunardate.go:306 +0xaa
github.com/warrially/BaziGo.NewLunarDateFrom64TimeStamp(0xe30318100, 0xe30318100)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/lunardate.go:60 +0x6d
github.com/warrially/BaziGo.(*TSolarDate).ToLunarDate(0xc000050a50, 0xfe7540)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/solardate.go:328 +0x45
github.com/warrially/BaziGo.(*TBazi).init(0xc00001a780, 0xc00001a780)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/bazi.go:59 +0x2b5
github.com/warrially/BaziGo.NewBazi(...)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/bazi.go:12
github.com/warrially/BaziGo.GetBazi(0x78c, 0x1, 0x12, 0x0, 0x0, 0x0, 0x0, 0x11)
d:/dev/gopath/pkg/mod/github.com/warrially/[email protected]/bazi.go:33 +0xb2
main.bz(0x0, 0xe302d1c00, 0xfe6c00, 0xb2de88, 0x13)
D:/lab/go/bazi/main.go:19 +0x26d
main.main()
D:/lab/go/bazi/main.go:57 +0x205
exit status 2
寿星万年历查询结果:
1993年11月13日
癸酉年 九月大 三十日
程序测试 bazi.LunarDate是{1993 10 30 21 10 0 0}。
之前想翻译个Go版的寿星万年历算法,放弃了。
八字,五行强度计算我也写了。加个微信共同交流一下,LongZhou588。
比如 bazi.GetBazi(1995, 1, 20, 7, 0, 0, 1),会触发panic
goroutine 1 [running]:
github.com/warrially/BaziGo.(*TLunarDate).GetAllDays(...)
/go/pkg/mod/github.com/warrially/[email protected]/lunardate.go:903
github.com/warrially/BaziGo.(*TLunarDate).Get64TimeStamp(...)
/go/pkg/mod/github.com/warrially/[email protected]/lunardate.go:387
github.com/warrially/BaziGo.(*TLunarDate).GetMonthFrom64TimeStamp(0xc00016e000, 0xea6b54af0)
/go/pkg/mod/github.com/warrially/[email protected]/lunardate.go:358 +0x85
github.com/warrially/BaziGo.NewLunarDateFrom64TimeStamp(0xc0001301b0?)
/go/pkg/mod/github.com/warrially/[email protected]/lunardate.go:58 +0x3d
github.com/warrially/BaziGo.(*TSolarDate).ToLunarDate(0x1153700?)
/go/pkg/mod/github.com/warrially/[email protected]/solardate.go:328 +0x18
github.com/warrially/BaziGo.(*TBazi).init(0xc0001522c0)
/go/pkg/mod/github.com/warrially/[email protected]/bazi.go:58 +0x6b
lunardate.go
159 行 if m.nLeapMonth == 0 {
// 没有闰月的话 nMonth 只能是 1 ~ 12
if m.nMonth == 13 {
return false // 输入 2020-01-01 会走到这里!
}
}
大佬。可以把流年,四柱的的神煞,大运的神煞,流年的神煞加上么?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.