Added phase symbol lookup
Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
parent
419b77af26
commit
21dcee96c7
21
moonphase.go
21
moonphase.go
|
@ -358,8 +358,27 @@ func (m *Moon) PhaseName() string {
|
|||
return names[i]
|
||||
}
|
||||
|
||||
// PhaseSymbol returns the Unicode moon symbol
|
||||
// corresponding to the time set in m.
|
||||
func (m *Moon) PhaseSymbol() string {
|
||||
syms := map[int]string{
|
||||
0: "🌑",
|
||||
1: "🌒",
|
||||
2: "🌓",
|
||||
3: "🌔",
|
||||
4: "🌕",
|
||||
5: "🌖",
|
||||
6: "🌗",
|
||||
7: "🌘",
|
||||
8: "🌑",
|
||||
}
|
||||
|
||||
i := int(math.Floor((m.phase + 0.0625) * 8))
|
||||
return syms[i]
|
||||
}
|
||||
|
||||
// Example usage
|
||||
// time := time.Date(2007, 10, 1, 24, 0, 0, 0, time.UTC)
|
||||
// // or //time := time.Now()
|
||||
// m := moonphase.New(time)
|
||||
// fmt.Println(m.PhaseName())
|
||||
// fmt.Println(m.PhaseName()+": "+m.PhaseSymbol())
|
||||
|
|
|
@ -38,3 +38,9 @@ func ExamplePhaseName() {
|
|||
fmt.Println(m.PhaseName())
|
||||
//Output: Third Quarter
|
||||
}
|
||||
|
||||
func ExamplePhaseSymbol() {
|
||||
m := New(time.Date(2007, 10, 1, 24, 0, 0, 0, time.UTC))
|
||||
fmt.Println(m.PhaseSymbol())
|
||||
//Output: 🌗
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue