|
@@ -1519,16 +1519,29 @@ func CalculateTradingDays(baseDate time.Time, tradingDays int) int {
|
|
|
return totalDays
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+func getLastDayOfMonth(t time.Time) time.Time {
|
|
|
+
|
|
|
+ return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location()).AddDate(0, 1, -1)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
func CalculateEndOfMonth(baseDate time.Time, months int) int {
|
|
|
-
|
|
|
- newDate := baseDate.AddDate(0, months, 0)
|
|
|
+
|
|
|
+ daysToAdd := 28 * (months + 1)
|
|
|
+
|
|
|
+ nextMonth := baseDate.AddDate(0, 0, daysToAdd)
|
|
|
+
|
|
|
+
|
|
|
+ firstDayOfNextMonth := time.Date(nextMonth.Year(), nextMonth.Month(), 1, 0, 0, 0, 0, nextMonth.Location())
|
|
|
+
|
|
|
+
|
|
|
+ lastDayOfTargetMonth := firstDayOfNextMonth.AddDate(0, 0, -1)
|
|
|
|
|
|
-
|
|
|
- lastDay := time.Date(newDate.Year(), newDate.Month()+1, 1, 0, 0, 0, 0, newDate.Location()).AddDate(0, 0, -1)
|
|
|
+
|
|
|
+ daysDifference := int(lastDayOfTargetMonth.Sub(baseDate).Hours() / 24)
|
|
|
|
|
|
-
|
|
|
- return int(lastDay.Sub(baseDate).Hours() / 24)
|
|
|
+ return daysDifference
|
|
|
}
|
|
|
|
|
|
|