Added phase symbol lookup

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2019-09-07 13:58:00 -07:00
parent 419b77af26
commit 21dcee96c7
2 changed files with 26 additions and 1 deletions

View File

@ -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())

View File

@ -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: 🌗
}