forked from free-lancers/electricity_bill_calc_service
		
	refactor(utils):改进对于月份差值的计算。
This commit is contained in:
		| @@ -1,6 +1,8 @@ | ||||
| package utils | ||||
|  | ||||
| import "time" | ||||
| import ( | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| func VeryBeginOfDate(date time.Time) time.Time { | ||||
| 	return time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location()) | ||||
| @@ -10,7 +12,7 @@ func VeryEndOfDate(date time.Time) time.Time { | ||||
| 	return time.Date(date.Year(), date.Month(), date.Day(), 23, 59, 59, 999999999, date.Location()) | ||||
| } | ||||
|  | ||||
| func IsNextMonth(t1, t2 time.Time) bool { | ||||
| func DifferenceInMonth(t1, t2 time.Time) int { | ||||
| 	var differYear, differMonth int | ||||
| 	if t1.After(t2) { | ||||
| 		differYear = t1.Year() - t2.Year() | ||||
| @@ -19,5 +21,9 @@ func IsNextMonth(t1, t2 time.Time) bool { | ||||
| 		differYear = t2.Year() - t1.Year() | ||||
| 		differMonth = int(t2.Month() - t1.Month()) | ||||
| 	} | ||||
| 	return (differMonth == -11 && differYear == 1) || (differMonth == 1 && differYear == 0) | ||||
| 	return differYear*12 + differMonth | ||||
| } | ||||
|  | ||||
| func IsNextMonth(t1, t2 time.Time) bool { | ||||
| 	return DifferenceInMonth(t1, t2) == 1 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user