iTranslated by AI
Calculating the 'Day of the Ox' (Doyo no Ushi no Hi) in Go
I should write something here once in a while (lol). Here's a quick little tip.
July 28, 2021, was "Doyo no Ushi no Hi" (the Day of the Ox during the Doyo period). In the current calendar, the "Beginning of Doyo" (Doyo no Iri) is defined as one of the Zassetsu (miscellaneous solar terms), specifically the days when the ecliptic longitude of the sun reaches 297°, 27°, 117°, and 207°. Additionally, the "End of Doyo" (Doyo no Aké) is the day before Risshun (Beginning of Spring, 315°), Rikka (Beginning of Summer, 45°), Risshu (Beginning of Autumn, 135°), and Ritto (Beginning of Winter, 225°).
Therefore, we just need to find the "Day of the Ox" within this period. For example, since January 1, 2001, was Koushi (Metal Rat), or the "Day of the Rat", we can count up from that day as Rat, Ox, Tiger, and so on.
So, let's check the period from the beginning of Doyo (July 19, 2021) to the day before Risshu (August 7, 2021).
// +build run
package main
import (
"fmt"
"time"
)
var (
jst = time.FixedZone("Asia/Tokyo", int((9 * time.Hour).Seconds()))
zodiacNames = []string{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
baseDay = time.Date(2001, time.January, 1, 0, 0, 0, 0, jst)
)
func zodiacName(t time.Time) string {
d := int64(t.Sub(baseDay).Hours()) / 24 % 12
if d < 0 {
d += 12
}
return zodiacNames[d]
}
func main() {
day := time.Date(2021, time.July, 18, 0, 0, 0, 0, jst)
for i := 0; i < 19; i++ {
day = day.Add(time.Hour * 24)
fmt.Printf("%v is %v\n", day.Format("2006-01-02"), zodiacName(day))
}
}
Sorry for the quick-and-dirty code. The execution result is as follows:
$ go run sample.go
2021-07-19 is 辰
2021-07-20 is 巳
2021-07-21 is 午
2021-07-22 is 未
2021-07-23 is 申
2021-07-24 is 酉
2021-07-25 is 戌
2021-07-26 is 亥
2021-07-27 is 子
2021-07-28 is 丑
2021-07-29 is 寅
2021-07-30 is 卯
2021-07-31 is 辰
2021-08-01 is 巳
2021-08-02 is 午
2021-08-03 is 未
2021-08-04 is 申
2021-08-05 is 酉
2021-08-06 is 戌
Therefore, we can see that July 28, 2021, is indeed the Day of the Ox.
That's all for now.
[Update: 2021-08-07]
I got a bit carried away and turned it into a package.
Discussion