|
@@ -1543,10 +1543,13 @@ func getLastDayOfMonth(t time.Time) time.Time {
|
|
|
}
|
|
|
|
|
|
|
|
|
-func CalculateEndOfMonth(baseDate time.Time, months int) int {
|
|
|
+func CalculateEndOfMonth(baseDate time.Time, months, moveType int) int {
|
|
|
|
|
|
daysToAdd := 28 * (months + 2)
|
|
|
|
|
|
+ if moveType == 2 {
|
|
|
+ daysToAdd = -(daysToAdd - 28)
|
|
|
+ }
|
|
|
nextMonth := baseDate.AddDate(0, 0, daysToAdd)
|
|
|
|
|
|
|
|
@@ -1556,25 +1559,76 @@ func CalculateEndOfMonth(baseDate time.Time, months int) int {
|
|
|
lastDayOfTargetMonth := firstDayOfNextMonth.AddDate(0, 0, -1)
|
|
|
|
|
|
|
|
|
- daysDifference := int(lastDayOfTargetMonth.Sub(baseDate).Hours() / 24)
|
|
|
+ daysDifference := int(math.Abs(lastDayOfTargetMonth.Sub(baseDate).Hours() / 24))
|
|
|
|
|
|
return daysDifference
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+func CalculateDekadTime(baseDate time.Time, tradingDays, moveType int) int {
|
|
|
+
|
|
|
+ oldDate := baseDate
|
|
|
+
|
|
|
+
|
|
|
+ var moveDekads int
|
|
|
+ if moveType != 2 {
|
|
|
+ moveDekads = tradingDays
|
|
|
+ } else {
|
|
|
+ moveDekads = -tradingDays
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ baseDate = baseDate.AddDate(0, 0, moveDekads*10)
|
|
|
+
|
|
|
+
|
|
|
+ baseDate = adjustToNearestDekad(baseDate)
|
|
|
+
|
|
|
+
|
|
|
+ subDays := baseDate.Sub(oldDate)
|
|
|
+ days := int(subDays.Hours() / 24)
|
|
|
+
|
|
|
+ fmt.Printf("最终日期: %s, 总天数差: %d 天\n", baseDate.Format("2006-01-02"), days)
|
|
|
+
|
|
|
+ return days
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func adjustToNearestDekad(date time.Time) time.Time {
|
|
|
+ day := date.Day()
|
|
|
+ lastDayOfMonth := getLastDayOfMonth(date).Day()
|
|
|
+
|
|
|
+ if day <= 10 {
|
|
|
+ return time.Date(date.Year(), date.Month(), 10, 0, 0, 0, 0, date.Location())
|
|
|
+ } else if day <= 20 {
|
|
|
+ return time.Date(date.Year(), date.Month(), 20, 0, 0, 0, 0, date.Location())
|
|
|
+ } else {
|
|
|
+ return time.Date(date.Year(), date.Month(), lastDayOfMonth, 0, 0, 0, 0, date.Location())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func getLastDayOfMonth(date time.Time) time.Time {
|
|
|
+
|
|
|
+ nextMonth := date.AddDate(0, 1, -date.Day()+1)
|
|
|
+
|
|
|
+ lastDay := nextMonth.AddDate(0, 0, -1)
|
|
|
+ return lastDay
|
|
|
+}*/
|
|
|
+
|
|
|
|
|
|
-func CalculateEndOfQuarter(baseDate time.Time, quarters int) int {
|
|
|
+func CalculateEndOfQuarter(baseDate time.Time, quarters, moveType int) int {
|
|
|
|
|
|
- return CalculateEndOfMonth(baseDate, quarters*3)
|
|
|
+ return CalculateEndOfMonth(baseDate, quarters*3, moveType)
|
|
|
}
|
|
|
|
|
|
|
|
|
-func CalculateEndOfYear(baseDate time.Time, years int) int {
|
|
|
+func CalculateEndOfYear(baseDate time.Time, years, moveType int) int {
|
|
|
|
|
|
- return CalculateEndOfMonth(baseDate, years*12)
|
|
|
+ return CalculateEndOfMonth(baseDate, years*12, moveType)
|
|
|
}
|
|
|
|
|
|
|
|
|
-func CalculateEndOfHalfYear(baseDate time.Time, years int) int {
|
|
|
+func CalculateEndOfHalfYear(baseDate time.Time, years, moveType int) int {
|
|
|
|
|
|
- return CalculateEndOfMonth(baseDate, years*6)
|
|
|
+ return CalculateEndOfMonth(baseDate, years*6, moveType)
|
|
|
}
|