From f5539f04c3eb843d360ce7c523bb3a7f884888c7 Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 30 Jan 2024 08:47:41 +0800 Subject: [PATCH] * zin: fix work days calculation. --- module/execution/ui/create.html.php | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/module/execution/ui/create.html.php b/module/execution/ui/create.html.php index 040d9ff702..dee444c847 100644 --- a/module/execution/ui/create.html.php +++ b/module/execution/ui/create.html.php @@ -52,25 +52,25 @@ $showExecutionExec = !empty($from) and ($from == 'execution' || $from == 'doc'); $handleBeginEndChange = jsCallback() ->const('weekend', $config->execution->weekend) ->do(<<<'JS' - const $picker = $this.closest('.date-range-picker'); - const begin = $picker.find('[name=begin]').val(); - const end = $picker.find('[name=end]').val(); - if(!zui.isValidDate(begin) || !zui.isValidDate(end)) return; - const $days = $element.find('[name=days]'); - const beginDate = zui.createDate(begin); - const endDate = zui.createDate(end); - const totalDays = Math.floor((endDate.getTime() - beginDate.getTime()) / zui.TIME_DAY); - if(totalDays <= 0) return $days.val(0); - let workDays = 0; - for(i = 0; i < totalDays; i++) - { - const date = new Date(beginDate.getTime()); - date.setDate(date.getDate() + i); + const $picker = $this.closest('.date-range-picker'); + const begin = $picker.find('[name=begin]').val(); + const end = $picker.find('[name=end]').val(); + if(!zui.isValidDate(begin) || !zui.isValidDate(end)) return; + const $days = $element.find('[name=days]'); + const beginDate = zui.createDate(begin); + const endDate = zui.createDate(end); + const totalDays = 1 + Math.ceil((endDate.getTime() - beginDate.getTime()) / zui.TIME_DAY); + if(totalDays <= 0) return $days.val(0); + let workDays = 0; + for(i = 0; i < totalDays; i++) + { + const date = new Date(beginDate.getTime()); + date.setDate(date.getDate() + i); - if((weekend == 2 && date.getDay() == 6) || date.getDay() == 0) continue; - workDays++; - } - $days.val(workDays); + if((weekend == 2 && date.getDay() == 6) || date.getDay() == 0) continue; + workDays++; + } + $days.val(workDays); JS); formGridPanel