forked from free-lancers/electricity_bill_calc_service
		
	fix(utils):调整月差值计算,使其可以使用负数表示前后顺序。
This commit is contained in:
		| @@ -14,16 +14,11 @@ func VeryEndOfDate(date time.Time) time.Time { | ||||
|  | ||||
| func DifferenceInMonth(t1, t2 time.Time) int { | ||||
| 	var differYear, differMonth int | ||||
| 	if t1.After(t2) { | ||||
| 		differYear = t1.Year() - t2.Year() | ||||
| 		differMonth = int(t1.Month() - t2.Month()) | ||||
| 	} else { | ||||
| 		differYear = t2.Year() - t1.Year() | ||||
| 		differMonth = int(t2.Month() - t1.Month()) | ||||
| 	} | ||||
| 	differYear = t1.Year() - t2.Year() | ||||
| 	differMonth = int(t1.Month() - t2.Month()) | ||||
| 	return differYear*12 + differMonth | ||||
| } | ||||
|  | ||||
| func IsNextMonth(t1, t2 time.Time) bool { | ||||
| 	return DifferenceInMonth(t1, t2) == 1 | ||||
| 	return DifferenceInMonth(t1, t2) == -1 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user