|
@@ -7,7 +7,6 @@ import (
|
|
|
"encoding/base64"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
- "errors"
|
|
|
"fmt"
|
|
|
"image"
|
|
|
"image/png"
|
|
@@ -722,96 +721,6 @@ func GetNowYearLastDay() time.Time {
|
|
|
return nowYearLastDay
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func CalculationDate(startDate, endDate time.Time) (beetweenDay string, err error) {
|
|
|
-
|
|
|
-
|
|
|
- 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
|
|
|
-
|
|
|
-
|
|
|
- if numDay == startDateMonthDays {
|
|
|
- numMonth++
|
|
|
- numDay = 0
|
|
|
-
|
|
|
- if numMonth == 12 {
|
|
|
- numYear++
|
|
|
- numMonth = 0
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- numDay = endDate.Day() - startDate.Day() + 1
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if numDay < 0 {
|
|
|
-
|
|
|
- numDay += endDatePrevMonthDays
|
|
|
-
|
|
|
-
|
|
|
- numMonth = numMonth - 1
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if numMonth < 0 {
|
|
|
-
|
|
|
- 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
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-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
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
func SubStr(str string, subLen int) string {
|
|
|
strRune := []rune(str)
|
|
@@ -880,3 +789,18 @@ func GetOrmInReplace(num int) string {
|
|
|
}
|
|
|
return strings.Join(template, ",")
|
|
|
}
|
|
|
+
|
|
|
+func GetDaysBetween2Date(format, date1Str, date2Str string) (int, error) {
|
|
|
+
|
|
|
+ date1, err := time.ParseInLocation(format, date1Str, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ date2, err := time.ParseInLocation(format, date2Str, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return int(date1.Sub(date2).Hours() / 24), nil
|
|
|
+}
|