antony Hmm, it appears to have been dropped from bsdgames.
pom is a small, simple app. Here, I wrote this in Go to help.
Installation:
- Install Go.
- Save the following code as pom.go.
- Run: go build -o pom pom.go
- As root, copy the pom
binary to /usr/local/bin/.
'
package main
import (
"flag"
"fmt"
"math"
"time"
)
func moonPhase(t time.Time) float64 {
reference := time.Date(2000, 1, 6, 18, 14, 0, 0, time.UTC)
daysSinceReference := t.Sub(reference).Hours() / 24.0
lunarCycle := 29.53058867
phase := math.Mod(daysSinceReference, lunarCycle) / lunarCycle * 100.0
if phase < 0 {
phase += 100
}
return phase
}
func main() {
var dateStr string
var timeStr string
var percentageOnly bool
flag.BoolVar(&percentageOnly, "p", false, "Print just the phase as a percentage")
flag.StringVar(&dateStr, "d", "", "Specify a date in yyyy.mm.dd format")
flag.StringVar(&timeStr, "t", "", "Specify a time in hh:mm:ss format")
flag.Parse()
var t time.Time
var err error
if dateStr != "" {
layoutDate := "2006.01.02"
t, err = time.Parse(layoutDate, dateStr)
if err != nil {
fmt.Println("Invalid date format. Use yyyy.mm.dd.")
return
}
if timeStr != "" {
layoutTime := "15:04:05"
timeParsed, err := time.Parse(layoutTime, timeStr)
if err != nil {
fmt.Println("Invalid time format. Use hh:mm:ss.")
return
}
t = time.Date(t.Year(), t.Month(), t.Day(), timeParsed.Hour(), timeParsed.Minute(), timeParsed.Second(), 0, time.UTC)
} else {
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.UTC)
}
} else {
t = time.Now().UTC()
}
phase := moonPhase(t)
if percentageOnly {
fmt.Printf("%.2f\n", phase)
} else {
fmt.Printf("Moon phase on %s: %.2f%%\n", t.Format("2006-01-02 15:04:05 UTC"), phase)
}
}