|
@@ -588,7 +588,7 @@ func GetHtmlByContractDetail(contractDetail *contract.ContractDetail, htmlType s
|
|
|
////合同有效期
|
|
|
//data.NumYear = numYearDecimal.String()
|
|
|
|
|
|
- tmpPrintContent, tmpErr := CalculationDate(contractDetail.StartDate, contractDetail.EndDate)
|
|
|
+ tmpPrintContent, tmpErr := utils.CalculationDate(contractDetail.StartDate, contractDetail.EndDate)
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
@@ -1590,7 +1590,7 @@ func getPrintData(data WordElement, contractDetail *contract.ContractDetail) (is
|
|
|
// numYearDecimal = minDecimal
|
|
|
//}
|
|
|
//printContent = numYearDecimal.String()
|
|
|
- tmpPrintContent, tmpErr := CalculationDate(contractDetail.StartDate, contractDetail.EndDate)
|
|
|
+ tmpPrintContent, tmpErr := utils.CalculationDate(contractDetail.StartDate, contractDetail.EndDate)
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
@@ -1846,93 +1846,3 @@ func FuncDocs2Pdf(command string, fileSrcPath string, fileOutDir string, convert
|
|
|
//fmt.Println("文件转换成功...", string(byteByStat))
|
|
|
return fileOutPath, nil
|
|
|
}
|
|
|
-
|
|
|
-// CalculationDate 计算两个日期之间相差n年m月y天
|
|
|
-func CalculationDate(startDate, endDate time.Time) (beetweenDay string, err error) {
|
|
|
- //startDate := time.Date(2021, 3, 28, 0, 0, 0, 0, time.Now().Location())
|
|
|
- //endDate := time.Date(2022, 3, 31, 0, 0, 0, 0, time.Now().Location())
|
|
|
- numYear := endDate.Year() - startDate.Year()
|
|
|
-
|
|
|
- numMonth := int(endDate.Month()) - int(startDate.Month())
|
|
|
-
|
|
|
- numDay := 0
|
|
|
- //获取截止月的总天数
|
|
|
- endDateDays := getMonthDay(endDate.Year(), int(endDate.Month()))
|
|
|
-
|
|
|
- //获取截止月的前一个月
|
|
|
- endDatePrevMonthDate := endDate.AddDate(0, -1, 0)
|
|
|
- //获取截止日期的上一个月的总天数
|
|
|
- endDatePrevMonthDays := getMonthDay(endDatePrevMonthDate.Year(), int(endDatePrevMonthDate.Month()))
|
|
|
- //获取开始日期的的月份总天数
|
|
|
- startDateMonthDays := getMonthDay(startDate.Year(), int(startDate.Month()))
|
|
|
-
|
|
|
- //判断,截止月是否完全被选中,如果相等,那么代表截止月份全部天数被选择
|
|
|
- if endDate.Day() == endDateDays {
|
|
|
- numDay = startDateMonthDays - startDate.Day() + 1
|
|
|
-
|
|
|
- //如果剩余天数正好与开始日期的天数是一致的,那么月份加1
|
|
|
- if numDay == startDateMonthDays {
|
|
|
- numMonth++
|
|
|
- numDay = 0
|
|
|
- //超过月份了,那么年份加1
|
|
|
- if numMonth == 12 {
|
|
|
- numYear++
|
|
|
- numMonth = 0
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- numDay = endDate.Day() - startDate.Day() + 1
|
|
|
- }
|
|
|
-
|
|
|
- //天数小于0,那么向月份借一位
|
|
|
- if numDay < 0 {
|
|
|
- //向上一个月借一个月的天数
|
|
|
- numDay += endDatePrevMonthDays
|
|
|
-
|
|
|
- //总月份减去一个月
|
|
|
- numMonth = numMonth - 1
|
|
|
- }
|
|
|
-
|
|
|
- //月份小于0,那么向年份借一位
|
|
|
- if numMonth < 0 {
|
|
|
- //向上一个年借12个月
|
|
|
- numMonth += 12
|
|
|
-
|
|
|
- //总年份减去一年
|
|
|
- numYear = numYear - 1
|
|
|
- }
|
|
|
- if numYear < 0 {
|
|
|
- err = errors.New("日期异常")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if numYear > 0 {
|
|
|
- beetweenDay += fmt.Sprint(numYear, "年")
|
|
|
- }
|
|
|
- if numMonth > 0 {
|
|
|
- beetweenDay += fmt.Sprint(numMonth, "个月")
|
|
|
- }
|
|
|
- if numDay > 0 {
|
|
|
- beetweenDay += fmt.Sprint(numDay, "天")
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// getMonthDay 获取某年某月有多少天
|
|
|
-func getMonthDay(year, month int) (days int) {
|
|
|
- if month != 2 {
|
|
|
- if month == 4 || month == 6 || month == 9 || month == 11 {
|
|
|
- days = 30
|
|
|
-
|
|
|
- } else {
|
|
|
- days = 31
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ((year%4) == 0 && (year%100) != 0) || (year%400) == 0 {
|
|
|
- days = 29
|
|
|
- } else {
|
|
|
- days = 28
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
-}
|