Commit a3bb5080 authored by Peter Cheng's avatar Peter Cheng

修正時間日期前面未加上零之問題

parent c71bc406
...@@ -18,15 +18,15 @@ import ( ...@@ -18,15 +18,15 @@ import (
func CalcTime(c *gin.Context) { func CalcTime(c *gin.Context) {
params := getPunchclockParams(c) params := getPunchclockParams(c)
beginYear := params.GetBegin().GetYear() beginYear := params.GetBegin().GetYear()
beginMonth := params.GetBegin().GetMonth() beginMonth := appendZero(params.GetBegin().GetMonth())
beginDay := params.GetBegin().GetDay() beginDay := appendZero(params.GetBegin().GetDay())
beginHour := params.GetBegin().GetHour() beginHour := appendZero(params.GetBegin().GetHour())
beginMinute := params.GetBegin().GetMinute() beginMinute := appendZero(params.GetBegin().GetMinute())
endYear := params.GetEnd().GetYear() endYear := params.GetEnd().GetYear()
endMonth := params.GetEnd().GetMonth() endMonth := appendZero(params.GetEnd().GetMonth())
endDay := params.GetEnd().GetDay() endDay := appendZero(params.GetEnd().GetDay())
endHour := params.GetEnd().GetHour() endHour := appendZero(params.GetEnd().GetHour())
endMinute := params.GetEnd().GetMinute() endMinute := appendZero(params.GetEnd().GetMinute())
beginTime, _ := strconv.Atoi(beginHour + beginMinute) beginTime, _ := strconv.Atoi(beginHour + beginMinute)
endTime, _ := strconv.Atoi(endHour + endMinute) endTime, _ := strconv.Atoi(endHour + endMinute)
...@@ -43,8 +43,8 @@ func CalcTime(c *gin.Context) { ...@@ -43,8 +43,8 @@ func CalcTime(c *gin.Context) {
} else { //沒跨午休 } else { //沒跨午休
diffHour, diffMinute = calcTime(beginHour, endHour, beginMinute, endMinute, false) diffHour, diffMinute = calcTime(beginHour, endHour, beginMinute, endMinute, false)
} }
_beginMonth := appendZero(beginMonth) _beginMonth := beginMonth
_beginDay := appendZero(beginDay) _beginDay := beginDay
if isHoliday(beginYear, _beginMonth, _beginDay) { if isHoliday(beginYear, _beginMonth, _beginDay) {
diffDay = 0 diffDay = 0
diffHour = 0 diffHour = 0
...@@ -59,7 +59,7 @@ func CalcTime(c *gin.Context) { ...@@ -59,7 +59,7 @@ func CalcTime(c *gin.Context) {
_diffHour, _diffMinute = calcTime(beginHour, "18", beginMinute, "0", false) _diffHour, _diffMinute = calcTime(beginHour, "18", beginMinute, "0", false)
} }
diffDay = calcDate(beginYear, beginMonth, beginDay, endYear, endMonth, endDay) diffDay = calcDate(beginYear, beginMonth, beginDay, endYear, endMonth, endDay)
if endTime < 1200 { //有跨午休 if endTime > 1330 { //有跨午休
diffHour, diffMinute = calcTime("8", endHour, "30", endMinute, true) diffHour, diffMinute = calcTime("8", endHour, "30", endMinute, true)
} else { //沒跨午休 } else { //沒跨午休
diffHour, diffMinute = calcTime("8", endHour, "30", endMinute, false) diffHour, diffMinute = calcTime("8", endHour, "30", endMinute, false)
...@@ -120,10 +120,10 @@ func isHoliday(year string, month string, day string) bool { ...@@ -120,10 +120,10 @@ func isHoliday(year string, month string, day string) bool {
func calcDate(beginYear string, beginMonth string, beginDay string, endYear string, endMonth string, endDay string) int { func calcDate(beginYear string, beginMonth string, beginDay string, endYear string, endMonth string, endDay string) int {
cfg := env.GetEnv() cfg := env.GetEnv()
diffDay := 0 diffDay := 0
_beginMonth := appendZero(beginMonth) _beginMonth := beginMonth
_beginDay := appendZero(beginDay) _beginDay := beginDay
_endMonth := appendZero(endMonth) _endMonth := endMonth
_endDay := appendZero(endDay) _endDay := endDay
checkTime := beginYear + "-" + _beginMonth + "-" + _beginDay + " 00:00:00" checkTime := beginYear + "-" + _beginMonth + "-" + _beginDay + " 00:00:00"
begin, _ := time.ParseInLocation(cfg.TimeFormat, checkTime, time.Local) begin, _ := time.ParseInLocation(cfg.TimeFormat, checkTime, time.Local)
checkTime = endYear + "-" + _endMonth + "-" + _endDay + " 00:00:00" checkTime = endYear + "-" + _endMonth + "-" + _endDay + " 00:00:00"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment