diff --git a/calendar/vlunar/README.md b/calendar/vlunar/README.md deleted file mode 100644 index 68602a84..00000000 --- a/calendar/vlunar/README.md +++ /dev/null @@ -1,105 +0,0 @@ -# Carbon - -[![Carbon Release](https://img.shields.io/github/release/golang-module/carbon.svg)](https://github.com/golang-module/carbon/releases) -[![Go Test](https://github.com/golang-module/carbon/actions/workflows/test.yml/badge.svg)](https://github.com/golang-module/carbon/actions) -[![Go Report Card](https://goreportcard.com/badge/github.com/golang-module/carbon/v2)](https://goreportcard.com/report/github.com/golang-module/carbon/v2) -[![Go Coverage](https://codecov.io/gh/golang-module/carbon/branch/master/graph/badge.svg)](https://codecov.io/gh/golang-module/carbon) -[![Goproxy.cn](https://goproxy.cn/stats/github.com/golang-module/carbon/badges/download-count.svg)](https://goproxy.cn) -[![Carbon Doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/golang-module/carbon/v2) -[![License](https://img.shields.io/github/license/golang-module/carbon)](https://github.com/golang-module/carbon/blob/master/LICENSE) - -#### Introduction - -A simple, semantic and developer-friendly golang package for time, has been included -by [awesome-go](https://github.com/avelino/awesome-go#date-and-time "awesome-go") - -[github.com/golang-module/carbon](https://github.com/golang-module/carbon "github.com/golang-module/carbon") - -[gitee.com/golang-module/carbon](https://gitee.com/golang-module/carbon "gitee.com/golang-module/carbon") - -#### Vietnamese Lunar - -##### Convert Solar into VLunar - -```go -// Get Lunar year of animal -carbon.Parse("2024-01-25 13:14:15").VLunar().Animal() // Mão - -// Get lunar festival -carbon.Parse("2021-02-12 13:14:15").VLunar().Festivals() // []{{Day: 1, Month: 1, Name: "Tết Nguyên Đán"}} - -// Get lunar luck hours -carbon.Parse("2020-05-01 13:14:15").VLunar().LuckyHours() // []{{Chi: "Dần", From: 3, To: 5}, {Chi: "Thìn", From: 7, To: 9}, {Chi: "Tỵ", From: 9, To: 11}, {Chi: "Thân", From: 15, To: 17}, {Chi: "Dậu", From: 17, To: 19}, {Chi: "Hợi", From: 21, To: 23}}, - -// Get lunar solar term -carbon.Parse("2025-03-10 13:14:15").VLunar().SolarTerm() // {Longitude: 345, Name: "Kinh trập"} - -// Get lunar year, month, day, hour, minute and second -carbon.Parse("2020-08-05 13:14:15").VLunar().DateTime() // 2020, 6, 16, 13, 14, 15 -// Get lunar year, month and day -carbon.Parse("2020-08-05 13:14:15").VLunar().Date() // 2020, 6, 16 -// Get lunar hour, minute and second -carbon.Parse("2020-08-05 13:14:15").VLunar().Time() // 13, 14, 15 - -// Get lunar year -carbon.Parse("2020-08-05 13:14:15").VLunar().Year() // 2020 -// Get lunar month -carbon.Parse("2020-08-05 13:14:15").VLunar().Month() // 6 -// Get lunar leap month -carbon.Parse("2020-08-05 13:14:15").VLunar().LeapMonth() // 4 -// Get lunar day -carbon.Parse("2020-08-05 13:14:15").VLunar().Day() // 16 -// Get lunar date as YYYY-MM-DD HH::ii::ss format string -fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").VLunar()) // 2020-06-16 13:14:15 - -// Get lunar year as string -carbon.Parse("2021-05-01 13:14:15").VLunar().ToYearString() // Tân Sửu -// Get lunar month as string -carbon.Parse("2020-12-01 13:14:15").VLunar().ToMonthString() // Đinh Hợi -// Get lunar day as string -carbon.Parse("2020-08-01 13:14:15").VLunar().ToDayString() // Bính Tý -// Get lunar date as string -carbon.Parse("2020-01-01 13:14:15").VLunar().ToDateString() // Ngày 07 tháng 12 năm 2019 - -// Whether is a lunar leap year -carbon.Parse("2020-08-05 13:14:15").VLunar().IsLeapYear() // true -// Whether is a lunar leap month -carbon.Parse("2020-08-05 13:14:15").VLunar().IsLeapMonth() // false - -// Whether is a lunar year of the rat -carbon.Parse("2020-08-05 13:14:15").VLunar().IsRatYear() // true -// Whether is a lunar year of the ox -carbon.Parse("2020-08-05 13:14:15").VLunar().IsOxYear() // false -// Whether is a lunar year of the tiger -carbon.Parse("2020-08-05 13:14:15").VLunar().IsTigerYear() // false -// Whether is a lunar year of the rabbit -carbon.Parse("2020-08-05 13:14:15").VLunar().IsRabbitYear() // false -// Whether is a lunar year of the dragon -carbon.Parse("2020-08-05 13:14:15").VLunar().IsDragonYear() // false -// Whether is a lunar year of the snake -carbon.Parse("2020-08-05 13:14:15").VLunar().IsSnakeYear() // false -// Whether is a lunar year of the horse -carbon.Parse("2020-08-05 13:14:15").VLunar().IsHorseYear() // false -// Whether is a lunar year of the goat -carbon.Parse("2020-08-05 13:14:15").VLunar().IsGoatYear() // false -// Whether is a lunar year of the monkey -carbon.Parse("2020-08-05 13:14:15").VLunar().IsMonkeyYear() // false -// Whether is a lunar year of the rooster -carbon.Parse("2020-08-05 13:14:15").VLunar().IsRoosterYear() // false -// Whether is a lunar year of the dog -carbon.Parse("2020-08-05 13:14:15").VLunar().IsDogYear() // false -// Whether is a lunar year of the dig -carbon.Parse("2020-08-05 13:14:15").VLunar().IsPigYear() // false - -``` - -##### Convert Lunar into Solar - -```go -// Convert the Vietnamese Lunar Calendar December 11, 2023 to the Solar Calendar -carbon.CreateFromVLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00 -// Convert Vietnamese lunar calendar February 11, 2023 to Solar calendar -carbon.CreateFromVLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2024-03-02 00:00:00 -// Convert the Vietnamese Lunar Calendar Leap February 11, 2024 to the Solar Calendar -carbon.CreateFromVLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00 -``` \ No newline at end of file diff --git a/calendar/vlunar/vlunar.go b/calendar/vlunar/vlunar.go deleted file mode 100644 index 3c523fa6..00000000 --- a/calendar/vlunar/vlunar.go +++ /dev/null @@ -1,658 +0,0 @@ -package vlunar - -import ( - "fmt" - "math" - "time" - - "github.com/golang-module/carbon/v2/calendar" -) - -// see document and algorithum -// https://www.informatik.uni-leipzig.de/~duc/amlich/calrules_en.html -// https://www.informatik.uni-leipzig.de/~duc/amlich/calrules_en.html#comparison - -type Festival struct { - Day int - Month int - Name string -} - -type LuckyHour struct { - Chi string - From int - To int -} - -type SolarTerm struct { - Longitude int - Name string -} - -// Solar defines a Solar struct. -type Gregorian struct { - calendar.Gregorian -} - -// Lunar defines a Lunar struct. -type Lunar struct { - year, month, day, hour, minute, second, timeZone int - zoneName string - leapMonth int - isLeapYear int //0, 1 - juliusDay int - Error error -} - -var ( - PI = math.Pi - heavenStem = []string{"Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"} - lunarTimes = []string{"Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"} - festivals = []Festival{ - { - Day: 1, - Month: 1, - Name: "Tết Nguyên Đán", - }, - { - Day: 15, - Month: 1, - Name: "Rằm tháng Giêng", - }, - { - Day: 10, - Month: 3, - Name: "Giỗ Tổ Hùng Vương", - }, - { - Day: 15, - Month: 4, - Name: "Phật Đản", - }, - { - Day: 5, - Month: 5, - Name: "Lễ Đoan Ngọ", - }, - { - Day: 15, - Month: 7, - Name: "Vu Lan", - }, - { - Day: 15, - Month: 8, - Name: "Tết Trung Thu", - }, - { - Day: 23, - Month: calendar.MonthsPerYear, - Name: "Ông Táo chầu trời", - }, - } - solarTerms = []SolarTerm{ - { - Longitude: 0, - Name: "Xuân phân", - }, - { - Longitude: 15, - Name: "Thanh minh", - }, - { - Longitude: 30, - Name: "Cốc vũ", - }, - { - Longitude: 45, - Name: "Lập hạ", - }, - { - Longitude: 60, - Name: "Tiểu mãn", - }, - { - Longitude: 75, - Name: "Mang chủng", - }, - { - Longitude: 90, - Name: "Hạ chí", - }, - { - Longitude: 105, - Name: "Tiểu thử", - }, - { - Longitude: 120, - Name: "Đại thử", - }, - { - Longitude: 135, - Name: "Lập thu", - }, - { - Longitude: 150, - Name: "Xử thử", - }, - { - Longitude: 165, - Name: "Bạch lộ", - }, - { - Longitude: 180, - Name: "Thu phân", - }, - { - Longitude: 195, - Name: "Hàn lộ", - }, - { - Longitude: 210, - Name: "Sương giáng", - }, - { - Longitude: 225, - Name: "Lập đông", - }, - { - Longitude: 240, - Name: "Tiểu tuyết", - }, - { - Longitude: 255, - Name: "Đại tuyết", - }, - { - Longitude: 270, - Name: "Đông chí", - }, - { - Longitude: 285, - Name: "Tiểu hàn", - }, - { - Longitude: 300, - Name: "Đại hàn", - }, - { - Longitude: 315, - Name: "Lập xuân", - }, - { - Longitude: 330, - Name: "Vũ Thủy", - }, - { - Longitude: 345, - Name: "Kinh trập", - }, - } - luckyHours = [6]string{"110100101100", "001101001011", "110011010010", "101100110100", "001011001101", "010010110011"} -) - -// NewGregorian returns a new Gregorian instance. -// 初始化 Gregorian 结构体 -func NewGregorian(t time.Time) (g Gregorian) { - g.Time = t - return g -} - -// NewLunar returns a new Lunar instance. -// 初始化 Lunar 结构体 -func NewLunar(year, month, day, hour, minute, second int, isLeapMonth bool) (l Lunar) { - l.year, l.month, l.day = year, month, day - l.hour, l.minute, l.second = hour, minute, second - if isLeapMonth { - l.leapMonth = month - l.isLeapYear = 1 - } - name, offset := time.Now().Zone() - l.timeZone = offset / 3600 - l.zoneName = name - l.juliusDay = lunarToJuliusDay(l.day, l.month, l.year, l.isLeapYear, l.timeZone) - return l -} - -// ToLunar Convert Gregorian calendar into Vietnamese Lunar calendar -// 将 公历 转化为 农历 -func (g Gregorian) ToLunar() (l Lunar) { - l.isLeapYear, l.leapMonth = 0, 0 - name, offset := g.Time.Zone() - l.timeZone = offset / 3600 - l.day, l.month, l.year, l.isLeapYear, l.leapMonth, l.juliusDay = solarToLunar(g.Day(), g.Month(), g.Year(), l.timeZone) - - l.hour, l.minute, l.second = g.Clock() - l.zoneName = name - return l -} - -// ToLunar Convert Vietnamese lunar calendar into Gregorian calendar -// 将 农历 转化为 公历 -func (l Lunar) ToGregorian() (g Gregorian) { - - loc := time.FixedZone(l.zoneName, l.timeZone*3600) - - d, m, y := juliusDayToDate(l.juliusDay) - g.Time = time.Date(y, time.Month(m), d, l.hour, l.minute, l.second, 0, loc) - return g -} - -func (l Lunar) YearHeavenStem() string { - return heavenStem[(l.year+6)%10] -} - -// Animal gets lunar animal name like "Tý". -func (l Lunar) Animal() string { - return lunarTimes[(l.year+8)%calendar.MonthsPerYear] -} - -// Festival gets lunar festival name like "Trung thu". -func (l Lunar) Festivals() (events []Festival) { - events = []Festival{} - month, day := l.month, l.day - - for i := 0; i < len(festivals); i++ { - event := festivals[i] - if event.Day == day && event.Month == month { - events = append(events, event) - } - } - - return -} - -func (l Lunar) SolarTerm() SolarTerm { - solarTerm := getSolarTerm(l.juliusDay+1, 7.0) - return solarTerms[solarTerm] -} - -func (l Lunar) LuckyHour() string { - chiOfDay := (l.juliusDay + 1) % calendar.MonthsPerYear - luckyHour := luckyHours[chiOfDay%6] - - return luckyHour -} - -func (l Lunar) LuckyHours() (ret []LuckyHour) { - ret = []LuckyHour{} - luckyHour := l.LuckyHour() - for i := 0; i < calendar.MonthsPerYear; i++ { - index := luckyHour[i] - if index == '1' { - detail := LuckyHour{ - Chi: lunarTimes[i], - From: (i*2 + 23) % 24, - To: (i*2 + 1) % 24, - } - ret = append(ret, detail) - } - } - return -} - -// DateTime gets lunar year, month, day, hour, minute, and second like 2020, 8, 5, 13, 14, 15. -func (l Lunar) DateTime() (year, month, day, hour, minute, second int) { - return l.year, l.month, l.day, l.hour, l.minute, l.second -} - -// Date gets lunar year, month and day like 2020, 8, 5. -func (l Lunar) Date() (year, month, day int) { - return l.year, l.month, l.day -} - -// Time gets lunar hour, minute, and second like 13, 14, 15. -func (l Lunar) Time() (hour, minute, second int) { - return l.hour, l.minute, l.second -} - -// Year gets lunar year like 2020. -func (l Lunar) Year() int { - return l.year -} - -// Month gets lunar month like 8. -func (l Lunar) Month() int { - return l.month -} - -func (l Lunar) MonthHeavenStem() string { - return heavenStem[((l.year*calendar.MonthsPerYear)+l.month+3)%10] -} - -func (l Lunar) MonthAnimal() string { - return lunarTimes[(l.month+1)%calendar.MonthsPerYear] -} - -// LeapMonth gets lunar leap month like 8. -func (l Lunar) LeapMonth() int { - return l.leapMonth -} - -// Day gets lunar day like 5. -func (l Lunar) Day() int { - return l.day -} - -func (l Lunar) DayHeavenStem() string { - return heavenStem[(l.juliusDay+9)%10] -} - -func (l Lunar) DayAnimal() string { - return lunarTimes[(l.juliusDay+1)%calendar.MonthsPerYear] -} - -// ToYearString outputs a string in lunar year format like "Giáp Tý". -func (l Lunar) ToYearString() string { - year := fmt.Sprintf("%s %s", l.YearHeavenStem(), l.Animal()) - return year -} - -// ToMonthString outputs a string in lunar month format like "Giáp Tý". -func (l Lunar) ToMonthString() string { - month := fmt.Sprintf("%s %s", l.MonthHeavenStem(), l.MonthAnimal()) - return month -} - -// ToDayString outputs a string in lunar day format like "Giáp Tý". -func (l Lunar) ToDayString() (day string) { - day = fmt.Sprintf("%s %s", l.DayHeavenStem(), l.DayAnimal()) - return -} - -// ToDateString outputs a string in lunar date format like "Ngày 16 tháng 9 năm 2020". -func (l Lunar) ToDateString() string { - return fmt.Sprintf("Ngày %02d tháng %02d năm %d", l.day, l.month, l.year) -} - -// String outputs a string in YYYY-MM-DD HH::ii::ss format, implement Stringer interface. -func (l Lunar) String() string { - return fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", l.year, l.month, l.day, l.hour, l.minute, l.second) -} - -// IsLeapYear reports whether is leap year. -func (l Lunar) IsLeapYear() bool { - return l.isLeapYear == 1 -} - -// IsLeapMonth reports whether is leap month. -func (l Lunar) IsLeapMonth() bool { - return l.month == l.LeapMonth() -} - -// IsRatYear reports whether is year of Rat. -func (l Lunar) IsRatYear() bool { - return l.year%calendar.MonthsPerYear == 4 -} - -// IsOxYear reports whether is year of Ox. -func (l Lunar) IsOxYear() bool { - return l.year%calendar.MonthsPerYear == 5 -} - -// IsTigerYear reports whether is year of Tiger. -func (l Lunar) IsTigerYear() bool { - return l.year%calendar.MonthsPerYear == 6 -} - -// IsRabbitYear reports whether is year of Rabbit. -func (l Lunar) IsCatYear() bool { - return l.year%calendar.MonthsPerYear == 7 -} - -// IsDragonYear reports whether is year of Dragon. -func (l Lunar) IsDragonYear() bool { - return l.year%calendar.MonthsPerYear == 8 -} - -// IsSnakeYear reports whether is year of Snake. -func (l Lunar) IsSnakeYear() bool { - return l.year%calendar.MonthsPerYear == 9 -} - -// IsHorseYear reports whether is year of Horse. -func (l Lunar) IsHorseYear() bool { - return l.year%calendar.MonthsPerYear == 10 -} - -// IsGoatYear reports whether is year of Goat. -func (l Lunar) IsGoatYear() bool { - return l.year%calendar.MonthsPerYear == 11 -} - -// IsMonkeyYear reports whether is year of Monkey. -func (l Lunar) IsMonkeyYear() bool { - return l.year%calendar.MonthsPerYear == 0 -} - -// IsRoosterYear reports whether is year of Rooster. -func (l Lunar) IsRoosterYear() bool { - return l.year%calendar.MonthsPerYear == 1 -} - -// IsDogYear reports whether is year of Dog. -func (l Lunar) IsDogYear() bool { - return l.year%calendar.MonthsPerYear == 2 -} - -// IsPigYear reports whether is year of Pig. -func (l Lunar) IsPigYear() bool { - return l.year%calendar.MonthsPerYear == 3 -} - -// private -func intToFloat(i int) float64 { - return float64(i) -} - -func mathFloor(f float64) float64 { - return math.Floor(f) -} - -func floor(f float64) int { - return int(mathFloor(f)) -} - -func dateToJuliusDay(dd, mm, yy int) int { - a := floor((14 - intToFloat(mm)) / calendar.MonthsPerYear) - y := intToFloat(yy) + 4800 - intToFloat(a) - m := intToFloat(mm) + calendar.MonthsPerYear*intToFloat(a) - 3 - juliusDay := intToFloat(dd) + mathFloor((153*m+2)/5) + 365*y + mathFloor(y/4) - math.Floor(y/100) + mathFloor(y/400) - 32045 - if juliusDay < 2299161 { - // julius calendar - juliusDay = intToFloat(dd) + mathFloor((153*m+2)/5) + 365*y + mathFloor(y/4) - 32083 - } - - return floor(juliusDay) -} - -func juliusDayToDate(jd int) (day, month, year int) { - var a, b, c, d, e, m int - if jd > 2299160 { - a = jd + 32044 - b = (4*a + 3) / 146097 - c = a - (b*146097)/4 - } else { - b = 0 - c = jd + 32082 - } - - d = (4*c + 3) / 1461 - e = c - (1461*d)/4 - m = (5*e + 2) / 153 - - day = e - (153*m+2)/5 + 1 - month = m + 3 - calendar.MonthsPerYear*(m/10) - year = b*100 + d - 4800 + (m / 10) - - return -} - -func newMoon(k int) float64 { - var kf, t, t2, t3, dr, jd1, m, mpr, f, c1, deltat, jdNew float64 - kf = intToFloat(k) - t = kf / 1236.85 // Time in Julian centuries from 1900 January 0.5 - t2 = t * t - t3 = t2 * t - dr = PI / 180 - jd1 = 2415020.75933 + 29.53058868*kf + 0.0001178*t2 - 0.000000155*t3 - jd1 = jd1 + 0.00033*math.Sin((166.56+132.87*t-0.009173*t2)*dr) // Mean new moon - m = 359.2242 + 29.10535608*kf - 0.0000333*t2 - 0.00000347*t3 // Sun's mean anomaly - mpr = 306.0253 + 385.81691806*kf + 0.0107306*t2 + 0.000012*t3 // Moon's mean anomaly - f = 21.2964 + 390.67050646*kf - 0.0016528*t2 - 0.00000239*t3 // Moon's argument of latitude - c1 = (0.1734-0.000393*t)*math.Sin(m*dr) + 0.0021*math.Sin(2*dr*m) - c1 = c1 - 0.4068*math.Sin(mpr*dr) + 0.0161*math.Sin(dr*2*mpr) - c1 = c1 - 0.0004*math.Sin(dr*3*mpr) - c1 = c1 + 0.0104*math.Sin(dr*2*f) - 0.0051*math.Sin(dr*(m+mpr)) - c1 = c1 - 0.0074*math.Sin(dr*(m-mpr)) + 0.0004*math.Sin(dr*(2*f+m)) - c1 = c1 - 0.0004*math.Sin(dr*(2*f-m)) - 0.0006*math.Sin(dr*(2*f+mpr)) - c1 = c1 + 0.0010*math.Sin(dr*(2*f-mpr)) + 0.0005*math.Sin(dr*(2*mpr+m)) - if t < -11 { - deltat = 0.001 + 0.000839*t + 0.0002261*t2 - 0.00000845*t3 - 0.000000081*t*t3 - } else { - deltat = -0.000278 + 0.000265*t + 0.000262*t2 - } - jdNew = jd1 + c1 - deltat - - return jdNew -} - -func getNewMoonDay(k, tz int) int { - return floor(newMoon(k) + 0.5 + intToFloat(tz)/24) -} - -func sunLongitude(jdn float64) float64 { - var t, t2, dr, m, l0, dl, l float64 - t = (jdn - 2451545.0) / 36525 // Time in Julian centuries from 2000-01-01 calendar.MonthsPerYear:00:00 GMT - t2 = t * t - dr = PI / 180 // degree to radian - m = 357.52910 + 35999.05030*t - 0.0001559*t2 - 0.00000048*t*t2 // mean anomaly, degree - l0 = 280.46645 + 36000.76983*t + 0.0003032*t2 // mean longitude, degree - dl = (1.914600 - 0.004817*t - 0.000014*t2) * math.Sin(dr*m) - dl = dl + (0.019993-0.000101*t)*math.Sin(dr*2*m) + 0.00029*math.Sin(dr*3*m) - l = l0 + dl // true longitude, degree - l = l * dr - l = l - PI*2*(math.Floor(l/(PI*2))) // Normalize to (0, 2*PI) - return l -} - -func getSunLongitude(d, tz int) int { - return floor((sunLongitude(intToFloat(d)-0.5-intToFloat(tz)/24) / PI) * 6) -} - -func getSolarTerm(dayNumber int, timeZone int) int { - return floor(sunLongitude(intToFloat(dayNumber)-0.5-intToFloat(timeZone)/24.0) / PI * calendar.MonthsPerYear) -} - -/* Find the day that starts the lunar month 11 of the given year for the given time zone */ -func getLunarStartNovember(yy, tz int) int { - var off, k, nm int - - off = dateToJuliusDay(31, calendar.MonthsPerYear, yy) - 2415021 - k = floor(intToFloat(off) / 29.530588853) - nm = getNewMoonDay(k, tz) - sunLong := getSunLongitude(nm, tz) // sun longitude at local midnight - if sunLong >= 9 { - nm = getNewMoonDay(k-1, tz) - } - return nm -} - -func getLeapMonthOffset(a11 float64, tz int) int { - k := floor((a11-2415021.076998695)/29.530588853 + 0.5) - last := 0 - i := 1 // We start with the month following lunar month 11 - arc := getSunLongitude(getNewMoonDay(k+i, tz), tz) - for { - last = arc - i++ - newmoon := getNewMoonDay(k+i, tz) - arc = getSunLongitude(newmoon, tz) - - if arc == last || i >= 14 { - break - } - } - return i - 1 -} - -// The function SolarToLunar converts a given Solar date (dd, mm, yy) into -// the corresponding Lunar date (lunarD, lunarM, lunarY, lunarLeap, lunarMonthLeap, juliusDayNumber) in the Vietnamese Lunar calendar. -// The time zone (tz) is used to calculate the date in the Lunar calendar. -func solarToLunar(dd, mm, yy, tz int) (lunarD, lunarM, lunarY, lunarLeap, lunarMonthLeap, juliusDayNumber int) { - juliusDayNumber = dateToJuliusDay(dd, mm, yy) - k := floor((intToFloat(juliusDayNumber) - 2415021.076998695) / 29.530588853) - monthStart := getNewMoonDay(k+1, tz) - if monthStart > juliusDayNumber { - monthStart = getNewMoonDay(k, tz) - } - a11 := getLunarStartNovember(yy, tz) - b11 := a11 - if a11 >= monthStart { - lunarY = yy - a11 = getLunarStartNovember(yy-1, tz) - } else { - lunarY = yy + 1 - b11 = getLunarStartNovember(yy+1, tz) - } - lunarD = juliusDayNumber - monthStart + 1 - diff := floor((intToFloat(monthStart) - intToFloat(a11)) / 29) - - lunarLeap = 0 - lunarMonthLeap = 0 - lunarM = diff + 11 - if b11-a11 > 365 { - leapMonthOffset := getLeapMonthOffset(intToFloat(a11), tz) - if diff >= leapMonthOffset { - lunarM = diff + 10 - } - lunarMonthLeap = leapMonthOffset - 2 - - if lunarMonthLeap < 0 { - lunarMonthLeap += 12 - } - - lunarLeap = 1 - } - - if lunarM > calendar.MonthsPerYear { - lunarM = lunarM - calendar.MonthsPerYear - } - - if lunarM >= 11 && diff < 4 { - lunarY -= 1 - } - - return -} - -func lunarToJuliusDay(lunarDay, lunarMonth, lunarYear, lunarLeap, tz int) (juliusDay int) { - var k, a11, b11, off, leapOff, leapMonth, monthStart int - if lunarMonth < 11 { - a11 = getLunarStartNovember(lunarYear-1, tz) - b11 = getLunarStartNovember(lunarYear, tz) - } else { - a11 = getLunarStartNovember(lunarYear, tz) - b11 = getLunarStartNovember(lunarYear+1, tz) - } - k = floor(0.5 + (intToFloat(a11)-2415021.076998695)/29.530588853) - off = lunarMonth - 11 - if off < 0 { - off += 12 - } - if b11-a11 > 365 { - leapOff = getLeapMonthOffset(intToFloat(a11), tz) - leapMonth = leapOff - 2 - if leapMonth < 0 { - leapMonth += 12 - } - if lunarLeap != 0 && lunarMonth != leapMonth { - return - } else if lunarLeap != 0 || off >= leapOff { - off += 1 - } - } - monthStart = getNewMoonDay(k+off, tz) - juliusDay = monthStart + lunarDay - 1 - return -} diff --git a/calendar/vlunar/vlunar_test.go b/calendar/vlunar/vlunar_test.go deleted file mode 100755 index d9ed6d69..00000000 --- a/calendar/vlunar/vlunar_test.go +++ /dev/null @@ -1,1660 +0,0 @@ -package vlunar - -import ( - "fmt" - "strconv" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestSolarToLunar(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(2024, 1, 21, 0, 0, 0, 0, time.Local))}, - want: "2023-12-11 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2023, 3, 2, 0, 0, 0, 0, time.Local))}, - want: "2023-02-11 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2023, 4, 1, 0, 0, 0, 0, time.Local))}, - want: "2023-02-11 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2022, 1, 25, 0, 0, 0, 0, time.Local))}, - want: "2021-12-23 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2022, 6, 13, 0, 0, 0, 0, time.Local))}, - want: "2022-05-15 00:00:00", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().String(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunarToGregorian(t *testing.T) { - type args struct { - l Lunar - } - tests := []struct { - args args - want string - }{ - { - args: args{NewLunar(2023, 12, 11, 0, 0, 0, false)}, - want: "2024-01-21 00:00:00", - }, - { - args: args{NewLunar(2023, 2, 11, 0, 0, 0, false)}, - want: "2023-03-02 00:00:00", - }, - { - args: args{NewLunar(2023, 2, 11, 0, 0, 0, true)}, - want: "2023-04-01 00:00:00", - }, - { - args: args{NewLunar(1800, 2, 11, 0, 0, 0, false)}, - want: "1800-03-06 00:00:00", - }, - { - args: args{NewLunar(2500, 2, 11, 0, 0, 0, false)}, - want: "2500-03-11 00:00:00", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.l).ToGregorian().String(), "args{%v}", tt.args.l) - }) - } -} - -func TestLunar_Animal(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "Mùi", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "Tý", - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Tý", - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: "Sửu", - }, - { - args: args{NewGregorian(time.Date(2010, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Dần", - }, - { - args: args{NewGregorian(time.Date(2011, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Mão", - }, - { - args: args{NewGregorian(time.Date(2012, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Thìn", - }, - { - args: args{NewGregorian(time.Date(2013, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Tỵ", - }, - { - args: args{NewGregorian(time.Date(2014, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Ngọ", - }, - { - args: args{NewGregorian(time.Date(2015, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Mùi", - }, - { - args: args{NewGregorian(time.Date(2016, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Thân", - }, - { - args: args{NewGregorian(time.Date(2017, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Dậu", - }, - { - args: args{NewGregorian(time.Date(2018, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Tuất", - }, - { - args: args{NewGregorian(time.Date(2019, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Hợi", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 23, 0, 0, 0, 0, time.Local))}, - want: "Tý", - }, - { - args: args{NewGregorian(time.Date(2020, 6, 21, 0, 0, 0, 0, time.Local))}, - want: "Tý", - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Tý", - }, - { - args: args{NewGregorian(time.Date(2021, 8, 5, 0, 0, 0, 0, time.Local))}, - want: "Sửu", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().Animal(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_SolarTerm(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want SolarTerm - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 240, Name: "Tiểu tuyết"}, - }, - { - args: args{NewGregorian(time.Date(2024, 3, 20, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 0, Name: "Xuân phân"}, - }, - { - args: args{NewGregorian(time.Date(2024, 4, 16, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 15, Name: "Thanh minh"}, - }, - { - args: args{NewGregorian(time.Date(2024, 5, 2, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 30, Name: "Cốc vũ"}, - }, - { - args: args{NewGregorian(time.Date(2024, 5, 16, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 45, Name: "Lập hạ"}, - }, - { - args: args{NewGregorian(time.Date(2024, 5, 29, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 60, Name: "Tiểu mãn"}, - }, - { - args: args{NewGregorian(time.Date(2024, 6, 11, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 75, Name: "Mang chủng"}, - }, - { - args: args{NewGregorian(time.Date(2024, 6, 27, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 90, Name: "Hạ chí"}, - }, - { - args: args{NewGregorian(time.Date(2024, 7, 10, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 105, Name: "Tiểu thử"}, - }, - { - args: args{NewGregorian(time.Date(2024, 7, 25, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 120, Name: "Đại thử"}, - }, - { - args: args{NewGregorian(time.Date(2024, 8, 8, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 135, Name: "Lập thu"}, - }, - { - args: args{NewGregorian(time.Date(2024, 8, 29, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 150, Name: "Xử thử"}, - }, - { - args: args{NewGregorian(time.Date(2024, 9, 10, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 165, Name: "Bạch lộ"}, - }, - { - args: args{NewGregorian(time.Date(2024, 9, 26, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 180, Name: "Thu phân"}, - }, - { - args: args{NewGregorian(time.Date(2024, 10, 9, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 195, Name: "Hàn lộ"}, - }, - { - args: args{NewGregorian(time.Date(2024, 10, 31, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 210, Name: "Sương giáng"}, - }, - { - args: args{NewGregorian(time.Date(2024, 11, 13, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 225, Name: "Lập đông"}, - }, - { - args: args{NewGregorian(time.Date(2024, 11, 22, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 240, Name: "Tiểu tuyết"}, - }, - { - args: args{NewGregorian(time.Date(2024, 11, 22, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 240, Name: "Tiểu tuyết"}, - }, - { - args: args{NewGregorian(time.Date(2024, 12, 6, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 255, Name: "Đại tuyết"}, - }, - { - args: args{NewGregorian(time.Date(2024, 12, 26, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 270, Name: "Đông chí"}, - }, - { - args: args{NewGregorian(time.Date(2025, 1, 8, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 285, Name: "Tiểu hàn"}, - }, - { - args: args{NewGregorian(time.Date(2025, 1, 23, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 300, Name: "Đại hàn"}, - }, - { - args: args{NewGregorian(time.Date(2025, 2, 3, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 315, Name: "Lập xuân"}, - }, - { - args: args{NewGregorian(time.Date(2025, 2, 19, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 330, Name: "Vũ Thủy"}, - }, - { - args: args{NewGregorian(time.Date(2025, 3, 10, 0, 0, 0, 0, time.Local))}, - want: SolarTerm{Longitude: 345, Name: "Kinh trập"}, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().SolarTerm(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_LuckyHour(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "010010110011", - }, - { - args: args{NewGregorian(time.Date(2025, 3, 2, 0, 0, 0, 0, time.Local))}, - want: "110100101100", - }, - { - args: args{NewGregorian(time.Date(2025, 3, 3, 0, 0, 0, 0, time.Local))}, - want: "001101001011", - }, - { - args: args{NewGregorian(time.Date(2025, 3, 4, 0, 0, 0, 0, time.Local))}, - want: "110011010010", - }, - { - args: args{NewGregorian(time.Date(2025, 3, 5, 0, 0, 0, 0, time.Local))}, - want: "101100110100", - }, - { - args: args{NewGregorian(time.Date(2025, 3, 6, 0, 0, 0, 0, time.Local))}, - want: "001011001101", - }, - { - args: args{NewGregorian(time.Date(2025, 3, 7, 0, 0, 0, 0, time.Local))}, - want: "010010110011", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().LuckyHour(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_LuckyHours(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want []LuckyHour - }{ - { - args: args{NewGregorian(time.Date(2025, 3, 2, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Tý", From: 23, To: 1}, {Chi: "Sửu", From: 1, To: 3}, {Chi: "Mão", From: 5, To: 7}, {Chi: "Ngọ", From: 11, To: 13}, {Chi: "Thân", From: 15, To: 17}, {Chi: "Dậu", From: 17, To: 19}}, - }, - { - args: args{NewGregorian(time.Date(2025, 3, 3, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Dần", From: 3, To: 5}, {Chi: "Mão", From: 5, To: 7}, {Chi: "Tỵ", From: 9, To: 11}, {Chi: "Thân", From: 15, To: 17}, {Chi: "Tuất", From: 19, To: 21}, {Chi: "Hợi", From: 21, To: 23}}, - }, - { - args: args{NewGregorian(time.Date(2025, 3, 4, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Tý", From: 23, To: 1}, {Chi: "Sửu", From: 1, To: 3}, {Chi: "Thìn", From: 7, To: 9}, {Chi: "Tỵ", From: 9, To: 11}, {Chi: "Mùi", From: 13, To: 15}, {Chi: "Tuất", From: 19, To: 21}}, - }, - { - args: args{NewGregorian(time.Date(2025, 3, 5, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Tý", From: 23, To: 1}, {Chi: "Dần", From: 3, To: 5}, {Chi: "Mão", From: 5, To: 7}, {Chi: "Ngọ", From: 11, To: 13}, {Chi: "Mùi", From: 13, To: 15}, {Chi: "Dậu", From: 17, To: 19}}, - }, - { - args: args{NewGregorian(time.Date(2025, 3, 6, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Dần", From: 3, To: 5}, {Chi: "Thìn", From: 7, To: 9}, {Chi: "Tỵ", From: 9, To: 11}, {Chi: "Thân", From: 15, To: 17}, {Chi: "Dậu", From: 17, To: 19}, {Chi: "Hợi", From: 21, To: 23}}, - }, - { - args: args{NewGregorian(time.Date(2025, 3, 7, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Sửu", From: 1, To: 3}, {Chi: "Thìn", From: 7, To: 9}, {Chi: "Ngọ", From: 11, To: 13}, {Chi: "Mùi", From: 13, To: 15}, {Chi: "Tuất", From: 19, To: 21}, {Chi: "Hợi", From: 21, To: 23}}, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: []LuckyHour{{Chi: "Dần", From: 3, To: 5}, {Chi: "Thìn", From: 7, To: 9}, {Chi: "Tỵ", From: 9, To: 11}, {Chi: "Thân", From: 15, To: 17}, {Chi: "Dậu", From: 17, To: 19}, {Chi: "Hợi", From: 21, To: 23}}, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().LuckyHours(), "args{%v}", tt.args.g) - }) - } -} -func TestLunar_Festival(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want []Festival - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2021, 2, 12, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 1, Month: 1, Name: "Tết Nguyên Đán"}}, - }, - { - args: args{NewGregorian(time.Date(2021, 2, 26, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 15, Month: 1, Name: "Rằm tháng Giêng"}}, - }, - { - args: args{NewGregorian(time.Date(2025, 4, 7, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 10, Month: 3, Name: "Giỗ Tổ Hùng Vương"}}, - }, - { - args: args{NewGregorian(time.Date(2025, 5, 12, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 15, Month: 4, Name: "Phật Đản"}}, - }, - { - args: args{NewGregorian(time.Date(2021, 6, 14, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 5, Month: 5, Name: "Lễ Đoan Ngọ"}}, - }, - { - args: args{NewGregorian(time.Date(2021, 8, 14, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2021, 8, 22, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 15, Month: 7, Name: "Vu Lan"}}, - }, - { - args: args{NewGregorian(time.Date(2021, 9, 21, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 15, Month: 8, Name: "Tết Trung Thu"}}, - }, - { - args: args{NewGregorian(time.Date(2021, 10, 14, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2021, 11, 5, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2021, 11, 19, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2022, 1, 10, 0, 0, 0, 0, time.Local))}, - want: []Festival{}, - }, - { - args: args{NewGregorian(time.Date(2026, 2, 10, 0, 0, 0, 0, time.Local))}, - want: []Festival{{Day: 23, Month: 12, Name: "Ông Táo chầu trời"}}, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().Festivals(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_Year(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want int - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: -1, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: 2020, - }, - { - args: args{NewGregorian(time.Date(2021, 5, 1, 0, 0, 0, 0, time.Local))}, - want: 2021, - }, - { - args: args{NewGregorian(time.Date(2025, 1, 28, 0, 0, 0, 0, time.Local))}, - want: 2024, - }, - { - args: args{NewGregorian(time.Date(2025, 1, 29, 0, 0, 0, 0, time.Local))}, - want: 2025, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().Year(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_Month(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want int - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: 11, - }, - { - args: args{NewGregorian(time.Date(2021, 3, 5, 0, 0, 0, 0, time.Local))}, - want: 1, - }, - { - args: args{NewGregorian(time.Date(2021, 4, 5, 0, 0, 0, 0, time.Local))}, - want: 2, - }, - { - args: args{NewGregorian(time.Date(2021, 5, 5, 0, 0, 0, 0, time.Local))}, - want: 3, - }, - { - args: args{NewGregorian(time.Date(2021, 6, 5, 0, 0, 0, 0, time.Local))}, - want: 4, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 5, 0, 0, 0, 0, time.Local))}, - want: 5, - }, - { - args: args{NewGregorian(time.Date(2021, 8, 5, 0, 0, 0, 0, time.Local))}, - want: 6, - }, - { - args: args{NewGregorian(time.Date(2021, 9, 5, 0, 0, 0, 0, time.Local))}, - want: 7, - }, - { - args: args{NewGregorian(time.Date(2021, 10, 5, 0, 0, 0, 0, time.Local))}, - want: 8, - }, - { - args: args{NewGregorian(time.Date(2021, 10, 20, 0, 0, 0, 0, time.Local))}, - want: 9, - }, - { - args: args{NewGregorian(time.Date(2021, 11, 5, 0, 0, 0, 0, time.Local))}, - want: 10, - }, - { - args: args{NewGregorian(time.Date(2022, 12, 5, 0, 0, 0, 0, time.Local))}, - want: 11, - }, - { - args: args{NewGregorian(time.Date(2022, 1, 5, 0, 0, 0, 0, time.Local))}, - want: 12, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().Month(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_LeapMonth(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want int - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: 0, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: 4, - }, - { - args: args{NewGregorian(time.Date(2023, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 2, - }, - { - args: args{NewGregorian(time.Date(2025, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 6, - }, - { - args: args{NewGregorian(time.Date(2028, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 5, - }, - { - args: args{NewGregorian(time.Date(2031, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 3, - }, - { - args: args{NewGregorian(time.Date(2033, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 0, - }, - { - args: args{NewGregorian(time.Date(2036, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 6, - }, - { - args: args{NewGregorian(time.Date(2039, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 5, - }, - { - args: args{NewGregorian(time.Date(2042, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 2, - }, - { - args: args{NewGregorian(time.Date(2044, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 7, - }, - { - args: args{NewGregorian(time.Date(2047, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 5, - }, - { - args: args{NewGregorian(time.Date(2050, 7, 1, 0, 0, 0, 0, time.Local))}, - want: 3, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().LeapMonth(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_Day(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want int - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: 4, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 19, 0, 0, 0, 0, time.Local))}, - want: 1, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 20, 0, 0, 0, 0, time.Local))}, - want: 2, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 21, 0, 0, 0, 0, time.Local))}, - want: 3, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 22, 0, 0, 0, 0, time.Local))}, - want: 4, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().Day(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_ToYearString(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "Kỷ Mùi", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "Canh Tý", - }, - { - args: args{NewGregorian(time.Date(2021, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "Tân Sửu", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().ToYearString(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_ToMonthString(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "Bính Tý", - }, - { - args: args{NewGregorian(time.Date(2020, 1, 1, 0, 0, 0, 0, time.Local))}, - want: "Đinh Sửu", - }, - { - args: args{NewGregorian(time.Date(2020, 2, 1, 0, 0, 0, 0, time.Local))}, - want: "Mậu Dần", - }, - { - args: args{NewGregorian(time.Date(2020, 3, 1, 0, 0, 0, 0, time.Local))}, - want: "Kỷ Mão", - }, - { - args: args{NewGregorian(time.Date(2020, 4, 1, 0, 0, 0, 0, time.Local))}, - want: "Canh Thìn", - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: "Tân Tỵ", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "Tân Tỵ", - }, - { - args: args{NewGregorian(time.Date(2020, 6, 1, 0, 0, 0, 0, time.Local))}, - want: "Tân Tỵ", - }, - { - args: args{NewGregorian(time.Date(2020, 7, 1, 0, 0, 0, 0, time.Local))}, - want: "Nhâm Ngọ", - }, - { - args: args{NewGregorian(time.Date(2020, 8, 1, 0, 0, 0, 0, time.Local))}, - want: "Quý Mùi", - }, - { - args: args{NewGregorian(time.Date(2020, 9, 1, 0, 0, 0, 0, time.Local))}, - want: "Giáp Thân", - }, - { - args: args{NewGregorian(time.Date(2020, 10, 1, 0, 0, 0, 0, time.Local))}, - want: "Ất Dậu", - }, - { - args: args{NewGregorian(time.Date(2020, 11, 1, 0, 0, 0, 0, time.Local))}, - want: "Bính Tuất", - }, - { - args: args{NewGregorian(time.Date(2020, 12, 1, 0, 0, 0, 0, time.Local))}, - want: "Đinh Hợi", - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: "Mậu Tý", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().ToMonthString(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_ToDayString(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "Kỷ Hợi", - }, - { - args: args{NewGregorian(time.Date(2020, 1, 1, 0, 0, 0, 0, time.Local))}, - want: "Quý Mão", - }, - { - args: args{NewGregorian(time.Date(2020, 2, 1, 0, 0, 0, 0, time.Local))}, - want: "Giáp Tuất", - }, - { - args: args{NewGregorian(time.Date(2020, 3, 1, 0, 0, 0, 0, time.Local))}, - want: "Quý Mão", - }, - { - args: args{NewGregorian(time.Date(2020, 4, 1, 0, 0, 0, 0, time.Local))}, - want: "Giáp Tuất", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "Giáp Thìn", - }, - { - args: args{NewGregorian(time.Date(2020, 6, 1, 0, 0, 0, 0, time.Local))}, - want: "Ất Hợi", - }, - { - args: args{NewGregorian(time.Date(2020, 7, 1, 0, 0, 0, 0, time.Local))}, - want: "Ất Tỵ", - }, - { - args: args{NewGregorian(time.Date(2020, 8, 1, 0, 0, 0, 0, time.Local))}, - want: "Bính Tý", - }, - { - args: args{NewGregorian(time.Date(2020, 9, 1, 0, 0, 0, 0, time.Local))}, - want: "Đinh Mùi", - }, - { - args: args{NewGregorian(time.Date(2020, 10, 1, 0, 0, 0, 0, time.Local))}, - want: "Đinh Sửu", - }, - { - args: args{NewGregorian(time.Date(2020, 11, 1, 0, 0, 0, 0, time.Local))}, - want: "Mậu Thân", - }, - { - args: args{NewGregorian(time.Date(2020, 12, 1, 0, 0, 0, 0, time.Local))}, - want: "Mậu Dần", - }, - { - args: args{NewGregorian(time.Date(2021, 1, 3, 0, 0, 0, 0, time.Local))}, - want: "Tân Hợi", - }, - { - args: args{NewGregorian(time.Date(2021, 1, 5, 0, 0, 0, 0, time.Local))}, - want: "Quý Sửu", - }, - { - args: args{NewGregorian(time.Date(2021, 4, 11, 0, 0, 0, 0, time.Local))}, - want: "Kỷ Sửu", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().ToDayString(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_DateTime(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "-1-11-04 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-04-09 00:00:00", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - y, m, d, h, i, s := (tt.args.g).ToLunar().DateTime() - assert.Equalf(t, tt.want, fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", y, m, d, h, i, s), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_Date(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "-1-11-04", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-04-09", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - y, m, d := (tt.args.g).ToLunar().Date() - assert.Equalf(t, tt.want, fmt.Sprintf("%d-%02d-%02d", y, m, d), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_Time(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 1, 1, 1, 0, time.Local))}, - want: "01:01:01", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - h, i, s := (tt.args.g).ToLunar().Time() - assert.Equalf(t, tt.want, fmt.Sprintf("%02d:%02d:%02d", h, i, s), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_String(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "-1-11-04 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 1, 1, 0, 0, 0, 0, time.Local))}, - want: "2019-12-07 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 2, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-01-08 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 3, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-02-08 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 4, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-03-09 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-04-09 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 6, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-04-10 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 7, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-05-11 00:00:00", - }, - { - args: args{NewGregorian(time.Date(2020, 8, 1, 0, 0, 0, 0, time.Local))}, - want: "2020-06-12 00:00:00", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().String(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_ToDateString(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want string - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: "Ngày 04 tháng 11 năm -1", - }, - { - args: args{NewGregorian(time.Date(2020, 1, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 07 tháng 12 năm 2019", - }, - { - args: args{NewGregorian(time.Date(2020, 2, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 08 tháng 01 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 3, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 08 tháng 02 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 4, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 09 tháng 03 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 09 tháng 04 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 6, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 10 tháng 04 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 7, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 11 tháng 05 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 8, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 12 tháng 06 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 9, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 14 tháng 07 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 10, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 15 tháng 08 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 11, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 16 tháng 09 năm 2020", - }, - { - args: args{NewGregorian(time.Date(2020, 12, 1, 0, 0, 0, 0, time.Local))}, - want: "Ngày 17 tháng 10 năm 2020", - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().ToDateString(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsLeapYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2022, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsLeapYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsLeapMonth(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2022, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsLeapMonth(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsRatYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2022, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsRatYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsOxYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: true, - }, - { - args: args{NewGregorian(time.Date(2022, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsOxYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsTigerYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2022, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsTigerYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsCatYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2023, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsCatYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsDragonYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2024, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsDragonYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsSnakeYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2025, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsSnakeYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsHorseYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2026, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsHorseYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsGoatYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2027, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsGoatYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsMonkeyYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2028, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsMonkeyYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsRoosterYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2029, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsRoosterYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsDogYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2030, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsDogYear(), "args{%v}", tt.args.g) - }) - } -} - -func TestLunar_IsPigYear(t *testing.T) { - type args struct { - g Gregorian - } - tests := []struct { - args args - want bool - }{ - { - args: args{NewGregorian(time.Date(0, 0, 0, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 4, 23, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 5, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2020, 8, 5, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2021, 7, 7, 0, 0, 0, 0, time.Local))}, - want: false, - }, - { - args: args{NewGregorian(time.Date(2031, 8, 5, 0, 0, 0, 0, time.Local))}, - want: true, - }, - } - for index, tt := range tests { - t.Run(strconv.Itoa(index), func(t *testing.T) { - assert.Equalf(t, tt.want, (tt.args.g).ToLunar().IsPigYear(), "args{%v}", tt.args.g) - }) - } -}