Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
homekeeper
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Peter Cheng
homekeeper
Commits
bea71d3a
Commit
bea71d3a
authored
Jun 21, 2019
by
Peter Cheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
追加供內部呼叫用之日期計算
parent
35999478
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
punchclock.go
controllers/punchclock.go
+30
-9
No files found.
controllers/punchclock.go
View file @
bea71d3a
...
@@ -21,16 +21,14 @@ func ResetAllUseMinute(c *gin.Context) {
...
@@ -21,16 +21,14 @@ func ResetAllUseMinute(c *gin.Context) {
result
:=
models
.
GetLeaveHistory
()
result
:=
models
.
GetLeaveHistory
()
for
_
,
item
:=
range
result
{
for
_
,
item
:=
range
result
{
beginDateStr
:=
item
.
Startdate
.
Format
(
cfg
.
TimeFormat
)
beginDateStr
:=
item
.
Startdate
.
Format
(
cfg
.
TimeFormat
)
beginDateStr
=
strings
.
Split
(
beginDateStr
,
" "
)[
0
]
beginDateArr
:=
strings
.
Split
(
beginDateStr
,
" "
)
beginDateArr
:=
strings
.
Split
(
beginDateStr
,
"-"
)
beginTimeArr
:=
strings
.
Split
(
item
.
Starttime
,
":"
)
endDateStr
:=
item
.
Enddate
.
Format
(
cfg
.
TimeFormat
)
endDateStr
:=
item
.
Enddate
.
Format
(
cfg
.
TimeFormat
)
endDate
Str
=
strings
.
Split
(
endDateStr
,
" "
)[
0
]
endDate
Arr
:=
strings
.
Split
(
endDateStr
,
" "
)
endDateArr
:=
strings
.
Split
(
endDateStr
,
"-"
)
checkTime
:=
beginDateArr
[
0
]
+
" "
+
item
.
Starttime
endTimeArr
:=
strings
.
Split
(
item
.
Endtime
,
":"
)
beginTime
,
_
:=
time
.
ParseInLocation
(
cfg
.
TimeFormat
,
checkTime
,
time
.
Local
)
begin
:=
&
beans
.
TimeStruct
{
Year
:
beginDateArr
[
0
],
Month
:
beginDateArr
[
1
],
Day
:
beginDateArr
[
2
],
Hour
:
beginTimeArr
[
0
],
Minute
:
beginTimeArr
[
1
],
Second
:
"00"
}
checkTime
=
endDateArr
[
0
]
+
" "
+
item
.
Endtime
end
:=
&
beans
.
TimeStruct
{
Year
:
endDateArr
[
0
],
Month
:
endDateArr
[
1
],
Day
:
endDateArr
[
2
],
Hour
:
endTimeArr
[
0
],
Minute
:
endTimeArr
[
1
],
Second
:
"00"
}
end
Time
,
_
:=
time
.
ParseInLocation
(
cfg
.
TimeFormat
,
checkTime
,
time
.
Local
)
params
:=
&
beans
.
Punchclock
{
Begin
:
begin
,
End
:
end
}
params
:=
combinTimeParams
(
beginTime
,
endTime
)
diffDay
,
diffHour
,
diffMinute
:=
calcLeaveScope
(
params
)
diffDay
,
diffHour
,
diffMinute
:=
calcLeaveScope
(
params
)
useMinute
:=
diffDay
*
8
*
60
+
diffHour
*
60
+
diffMinute
useMinute
:=
diffDay
*
8
*
60
+
diffHour
*
60
+
diffMinute
models
.
SetUseMinute
(
useMinute
,
item
.
ID
)
models
.
SetUseMinute
(
useMinute
,
item
.
ID
)
...
@@ -38,6 +36,13 @@ func ResetAllUseMinute(c *gin.Context) {
...
@@ -38,6 +36,13 @@ func ResetAllUseMinute(c *gin.Context) {
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
"true"
})
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"status"
:
"true"
})
}
}
//CallCalcTime 透過內部呼叫計算休假區間
func
CallCalcTime
(
onWorkTime
time
.
Time
,
offWorkTime
time
.
Time
)
(
diffDay
int
,
diffHour
int
,
diffMinute
int
)
{
params
:=
combinTimeParams
(
onWorkTime
,
offWorkTime
)
diffDay
,
diffHour
,
diffMinute
=
calcLeaveScope
(
params
)
return
diffDay
,
diffHour
,
diffMinute
}
//CalcTime 計算時數
//CalcTime 計算時數
func
CalcTime
(
c
*
gin
.
Context
)
{
func
CalcTime
(
c
*
gin
.
Context
)
{
params
:=
getPunchclockParams
(
c
)
params
:=
getPunchclockParams
(
c
)
...
@@ -45,6 +50,22 @@ func CalcTime(c *gin.Context) {
...
@@ -45,6 +50,22 @@ func CalcTime(c *gin.Context) {
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"diffDay"
:
diffDay
,
"diffHour"
:
diffHour
,
"diffMinute"
:
diffMinute
})
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"diffDay"
:
diffDay
,
"diffHour"
:
diffHour
,
"diffMinute"
:
diffMinute
})
}
}
func
combinTimeParams
(
beginTime
time
.
Time
,
endTime
time
.
Time
)
*
beans
.
Punchclock
{
cfg
:=
env
.
GetEnv
()
beginStr
:=
beginTime
.
Format
(
cfg
.
TimeFormat
)
beginArr
:=
strings
.
Split
(
beginStr
,
" "
)
beginDateArr
:=
strings
.
Split
(
beginArr
[
0
],
"-"
)
beginTimeArr
:=
strings
.
Split
(
beginArr
[
1
],
":"
)
endStr
:=
endTime
.
Format
(
cfg
.
TimeFormat
)
endArr
:=
strings
.
Split
(
endStr
,
" "
)
endDateArr
:=
strings
.
Split
(
endArr
[
0
],
"-"
)
endTimeArr
:=
strings
.
Split
(
endArr
[
1
],
":"
)
begin
:=
&
beans
.
TimeStruct
{
Year
:
beginDateArr
[
0
],
Month
:
beginDateArr
[
1
],
Day
:
beginDateArr
[
2
],
Hour
:
beginTimeArr
[
0
],
Minute
:
beginTimeArr
[
1
],
Second
:
beginTimeArr
[
2
]}
end
:=
&
beans
.
TimeStruct
{
Year
:
endDateArr
[
0
],
Month
:
endDateArr
[
1
],
Day
:
endDateArr
[
2
],
Hour
:
endTimeArr
[
0
],
Minute
:
endTimeArr
[
1
],
Second
:
endTimeArr
[
2
]}
params
:=
&
beans
.
Punchclock
{
Begin
:
begin
,
End
:
end
}
return
params
}
//calcLeaveScope 計算休假區間主程式
//calcLeaveScope 計算休假區間主程式
func
calcLeaveScope
(
params
*
beans
.
Punchclock
)
(
diffDay
int
,
diffHour
int
,
diffMinute
int
)
{
func
calcLeaveScope
(
params
*
beans
.
Punchclock
)
(
diffDay
int
,
diffHour
int
,
diffMinute
int
)
{
beginYear
:=
params
.
GetBegin
()
.
GetYear
()
beginYear
:=
params
.
GetBegin
()
.
GetYear
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment