|
|
|
@ -15,6 +15,7 @@ import ( |
|
|
|
"math/big" |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/mozillazg/go-pinyin" |
|
|
|
@ -1057,3 +1058,229 @@ func HestacademicdegreeToInt(hir string) int { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 根据字符串组合时间
|
|
|
|
/* |
|
|
|
#dateTime 日期 |
|
|
|
*/ |
|
|
|
func (d *DateTimeTotimes) BaisStrToTime(dateTime string) { |
|
|
|
timeStrAry := strings.Split(dateTime, "-") |
|
|
|
switch len(timeStrAry) { |
|
|
|
case 1: |
|
|
|
dateTime = fmt.Sprintf("%v-01-01 12:00:00", dateTime) |
|
|
|
case 2: |
|
|
|
if len(timeStrAry[1]) < 2 { |
|
|
|
dateTime = fmt.Sprintf("%v-0%v-01 12:00:00", timeStrAry[0], timeStrAry[1]) |
|
|
|
} |
|
|
|
case 3: |
|
|
|
monthStr := timeStrAry[1] |
|
|
|
if len(timeStrAry[1]) < 2 { |
|
|
|
monthStr = fmt.Sprintf("0%v", timeStrAry[1]) |
|
|
|
} |
|
|
|
dayAry := strings.Split(timeStrAry[2], " ") |
|
|
|
// fmt.Printf("dayAry:%v------>%v\n", dayAry, len(dayAry))
|
|
|
|
dayStr := dayAry[0] |
|
|
|
if len(dayAry[0]) < 2 { |
|
|
|
dayStr = fmt.Sprintf("0%v", dayAry[0]) |
|
|
|
} |
|
|
|
if len(dayAry) > 1 { |
|
|
|
// fmt.Printf("dayAry[1]:%v------>%v\n", dayAry[1], len(dayAry[1]))
|
|
|
|
if len(dayAry[1]) > 0 { |
|
|
|
Hours := "00" |
|
|
|
minutes := "00" |
|
|
|
seconds := "00" |
|
|
|
hisAry := strings.Split(dayAry[1], ":") |
|
|
|
switch len(hisAry) { |
|
|
|
case 1: |
|
|
|
if len(hisAry[0]) < 2 { |
|
|
|
Hours = fmt.Sprintf("0%v", hisAry[0]) |
|
|
|
} else { |
|
|
|
Hours = hisAry[0] |
|
|
|
} |
|
|
|
case 2: |
|
|
|
if len(hisAry[0]) < 2 { |
|
|
|
Hours = fmt.Sprintf("0%v", hisAry[0]) |
|
|
|
} else { |
|
|
|
Hours = hisAry[0] |
|
|
|
} |
|
|
|
if len(hisAry[1]) < 2 { |
|
|
|
minutes = fmt.Sprintf("0%v", hisAry[1]) |
|
|
|
} else { |
|
|
|
minutes = hisAry[1] |
|
|
|
} |
|
|
|
case 3: |
|
|
|
if len(hisAry[0]) < 2 { |
|
|
|
Hours = fmt.Sprintf("0%v", hisAry[0]) |
|
|
|
} else { |
|
|
|
Hours = hisAry[0] |
|
|
|
} |
|
|
|
if len(hisAry[1]) < 2 { |
|
|
|
minutes = fmt.Sprintf("0%v", hisAry[1]) |
|
|
|
} else { |
|
|
|
minutes = hisAry[1] |
|
|
|
} |
|
|
|
if len(hisAry[2]) < 2 { |
|
|
|
seconds = fmt.Sprintf("0%v", hisAry[2]) |
|
|
|
} else { |
|
|
|
seconds = hisAry[2] |
|
|
|
} |
|
|
|
default: |
|
|
|
} |
|
|
|
dayStr = fmt.Sprintf("%v %v:%v:%v", dayStr, Hours, minutes, seconds) |
|
|
|
} |
|
|
|
} |
|
|
|
// dayStr := timeStrAry[2]
|
|
|
|
// if len(timeStrAry[2]) < 2 {
|
|
|
|
// dayStr = fmt.Sprintf("0%v", timeStrAry[2])
|
|
|
|
// }
|
|
|
|
dateTime = fmt.Sprintf("%v-%v-%v", timeStrAry[0], monthStr, dayStr) |
|
|
|
|
|
|
|
default: |
|
|
|
} |
|
|
|
fmt.Printf("dateTime:%v---1--->%v\n", dateTime, len(dateTime)) |
|
|
|
orgTime, orgTimeErr := DateToTimeStamp(fmt.Sprintf("%v-01-01 12:00:00", dateTime)) |
|
|
|
if orgTimeErr { |
|
|
|
d.AllTime = orgTime |
|
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10) |
|
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10) |
|
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10) |
|
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10) |
|
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10) |
|
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10) |
|
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10) |
|
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10) |
|
|
|
} else { |
|
|
|
|
|
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v-01 12:00:00", dateTime)) |
|
|
|
if orgTimeErr { |
|
|
|
d.AllTime = orgTime |
|
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10) |
|
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10) |
|
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10) |
|
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10) |
|
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10) |
|
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10) |
|
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10) |
|
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10) |
|
|
|
|
|
|
|
fmt.Printf("dateTime:%v---2--->%v--->%v\n", orgTime, d.AllTime, d.Quarter) |
|
|
|
} else { |
|
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v 12:00:00", dateTime)) |
|
|
|
if orgTimeErr { |
|
|
|
d.AllTime = orgTime |
|
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10) |
|
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10) |
|
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10) |
|
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10) |
|
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10) |
|
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10) |
|
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10) |
|
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10) |
|
|
|
} else { |
|
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v:00:00", dateTime)) |
|
|
|
if orgTimeErr { |
|
|
|
d.AllTime = orgTime |
|
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10) |
|
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10) |
|
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10) |
|
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10) |
|
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10) |
|
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10) |
|
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10) |
|
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10) |
|
|
|
} else { |
|
|
|
orgTime, orgTimeErr = DateToTimeStamp(fmt.Sprintf("%v:00", dateTime)) |
|
|
|
if orgTimeErr { |
|
|
|
d.AllTime = orgTime |
|
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10) |
|
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10) |
|
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10) |
|
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10) |
|
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10) |
|
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10) |
|
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10) |
|
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10) |
|
|
|
} else { |
|
|
|
orgTime, orgTimeErr = DateToTimeStamp(dateTime) |
|
|
|
if orgTimeErr { |
|
|
|
d.AllTime = orgTime |
|
|
|
d.Years = strconv.FormatInt(ComputingTime(orgTime, 1), 10) |
|
|
|
d.Quarter = strconv.FormatInt(ComputingTime(orgTime, 2), 10) |
|
|
|
d.Months = strconv.FormatInt(ComputingTime(orgTime, 3), 10) |
|
|
|
d.Week = strconv.FormatInt(ComputingTime(orgTime, 4), 10) |
|
|
|
d.Days = strconv.FormatInt(ComputingTime(orgTime, 5), 10) |
|
|
|
d.Hours = strconv.FormatInt(ComputingTime(orgTime, 7), 10) |
|
|
|
d.Minutes = strconv.FormatInt(ComputingTime(orgTime, 8), 10) |
|
|
|
d.Second = strconv.FormatInt(ComputingTime(orgTime, 9), 10) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
func DateToTimeStampOld(dataStr string) (timeStamp int64) { |
|
|
|
tmp := "2006-01-02 15:04:05" |
|
|
|
res, _ := time.ParseInLocation(tmp, dataStr, time.Local) |
|
|
|
timeStamp = res.Unix() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 时间计算(年、季、月、周、日、时、分、秒)
|
|
|
|
func ComputingTime(timeStamp int64, timeType int) (timeDataInt int64) { |
|
|
|
var timeData string = "1" |
|
|
|
switch timeType { |
|
|
|
case 1: |
|
|
|
timeData = time.Unix(timeStamp, 0).Format("2006") //年
|
|
|
|
case 2: |
|
|
|
dayMonth := time.Unix(timeStamp, 0).Format("01") //季度
|
|
|
|
datMonthFloat, datMonthFloatErr := strconv.ParseFloat(dayMonth, 10) |
|
|
|
if datMonthFloatErr == nil { |
|
|
|
timeData = strconv.FormatFloat(math.Ceil(datMonthFloat/3), 'f', -1, 64) |
|
|
|
} else { |
|
|
|
timeData = "1" |
|
|
|
} |
|
|
|
case 3: |
|
|
|
timeData = time.Unix(timeStamp, 0).Format("01") //月份
|
|
|
|
case 4: //当前日期为本月第几周
|
|
|
|
monthFirstDayStr := DateToTimeStampOld(UnixTimeToDay(timeStamp, 15) + "-01 00:00:00") //获取指定月第一天时间戳
|
|
|
|
dayTime := time.Unix(monthFirstDayStr, 0) |
|
|
|
dayOfWeek := int(dayTime.Weekday()) //获取本月第一天是周几
|
|
|
|
if dayOfWeek == 0 { |
|
|
|
dayOfWeek = 7 |
|
|
|
} |
|
|
|
|
|
|
|
dayNumber, dayNumberErr := strconv.ParseInt(UnixTimeToDay(timeStamp, 18), 10, 64) //获取今天是几号
|
|
|
|
if dayNumberErr != nil { |
|
|
|
dayNumber = 1 |
|
|
|
} |
|
|
|
daysAndWeeksDiff := dayNumber - (8 - int64(dayOfWeek)) |
|
|
|
if daysAndWeeksDiff <= 0 { |
|
|
|
timeData = "1" |
|
|
|
} else { |
|
|
|
daysAndWeeksDiffFlot, daysAndWeeksDiffFloatErr := strconv.ParseFloat(strconv.FormatInt(daysAndWeeksDiff, 10), 10) |
|
|
|
if daysAndWeeksDiffFloatErr == nil { |
|
|
|
daysWeeksDiffVal := math.Ceil(daysAndWeeksDiffFlot/7) + 1 |
|
|
|
timeData = strconv.FormatFloat(daysWeeksDiffVal, 'f', -1, 64) |
|
|
|
} else { |
|
|
|
timeData = "1" |
|
|
|
} |
|
|
|
} |
|
|
|
case 5: |
|
|
|
timeData = time.Unix(timeStamp, 0).Format("02") //天
|
|
|
|
case 7: |
|
|
|
timeData = time.Unix(timeStamp, 0).Format("15") //时
|
|
|
|
case 8: |
|
|
|
timeData = time.Unix(timeStamp, 0).Format("04") //分
|
|
|
|
case 9: |
|
|
|
timeData = time.Unix(timeStamp, 0).Format("05") //秒
|
|
|
|
default: |
|
|
|
timeData = "0" |
|
|
|
} |
|
|
|
timeDataInt, timeDataIntErr := strconv.ParseInt(timeData, 10, 64) |
|
|
|
if timeDataIntErr != nil { |
|
|
|
timeDataInt = 0 |
|
|
|
return |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|