package utils

import "time"

func InSameDay(t1, t2 time.Time) bool {
	y1, m1, d1 := t1.Date()
	y2, m2, d2 := t2.Date()

	return y1 == y2 && m1 == m2 && d1 == d2
}

func SplitDate(beginDate, endDate, format string) []string {
	bDate, _ := time.ParseInLocation(format, beginDate, time.Local)
	eDate, _ := time.ParseInLocation(format, endDate, time.Local)
	day := int(eDate.Sub(bDate).Hours() / 24)
	dlist := make([]string, 0)
	dlist = append(dlist, beginDate)
	for i := 1; i < day; i++ {
		result := bDate.AddDate(0, 0, i)
		dlist = append(dlist, result.Format(format))
	}
	dlist = append(dlist, endDate)
	return dlist
}

func YearMonthRange(start, end time.Time, format string) []string {
	// 创建年月数组
	start = time.Date(start.Year(), start.Month(), 1, 0, 0, 0, 0, start.Location())
	yms := make([]string, 0)

	// 遍历每个月
	for t := start; t.Before(end); t = t.AddDate(0, 1, 0) {
		yms = append(yms, t.Format(format))
	}

	return yms
}
