From f2ef1b38976561b01d6816798f4fa48139ceceb5 Mon Sep 17 00:00:00 2001 From: Ko Nagase Date: Wed, 1 Mar 2023 22:40:14 +0900 Subject: [PATCH 1/2] Add break time with specific day test --- tests/timesheets_test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/timesheets_test.js b/tests/timesheets_test.js index 6d53034..b7b9d6c 100644 --- a/tests/timesheets_test.js +++ b/tests/timesheets_test.js @@ -193,6 +193,14 @@ QUnit.test( "Timesheets", function(assert) { msgTest('test1', '休憩 30分', [['休憩', 'test1', "30分"]]); }); + // 休憩時間(過去日時) + test1 = {}; + var pastDateStr = String(DateUtils.toDate(new Date(2013,11,3,12,0,0))) + test1[pastDateStr] = { user: 'test1', signIn: new Date(2013,11,3,12,0,0), signOut: '-' }; + storageTest({'test1': test1}, function(msgTest) { + msgTest('test1', '休憩 30分 12/3', [['休憩', 'test1', "30分"]]); + }); + // 休暇申請 storageTest({}, function(msgTest) { msgTest('test1', 'お休み', []); From d012bc48ff76191b33b8c8eb88afea4cc33299ce Mon Sep 17 00:00:00 2001 From: Ko Nagase Date: Wed, 1 Mar 2023 22:41:09 +0900 Subject: [PATCH 2/2] Adjust DateUtil.normalizeDateTime method to care break minutes --- scripts/date_utils.js | 14 +++++++++++--- scripts/timesheets.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/date_utils.js b/scripts/date_utils.js index 0979119..d6210c1 100644 --- a/scripts/date_utils.js +++ b/scripts/date_utils.js @@ -138,11 +138,19 @@ loadDateUtils = function () { return null; }; - // 日付と時間の配列から、Dateオブジェクトを生成 - DateUtils.normalizeDateTime = function(date, time) { + // 日付と時間の配列から、Dateオブジェクトを生成 (休憩時間も考慮) + DateUtils.normalizeDateTime = function(date, time, minutes) { // 時間だけの場合は日付を補完する if(date) { - if(!time) date = null; + // 日付だけで時間がなくても、休憩時間がある場合は時間を補完する + if(!time) { + if(!minutes) { + date = null; + } + else { + time = [now().getHours(), now().getMinutes()]; + } + } } else { date = [now().getFullYear(), now().getMonth()+1, now().getDate()]; diff --git a/scripts/timesheets.js b/scripts/timesheets.js index 79f43e8..42c6301 100644 --- a/scripts/timesheets.js +++ b/scripts/timesheets.js @@ -19,7 +19,7 @@ loadTimesheets = function (exports) { this.date = DateUtils.parseDate(message); this.time = DateUtils.parseTime(message); this.minutes = DateUtils.parseMinutes(message) - this.datetime = DateUtils.normalizeDateTime(this.date, this.time); + this.datetime = DateUtils.normalizeDateTime(this.date, this.time, this.minutes); if (this.datetime !== null) { this.dateStr = DateUtils.format("Y/m/d", this.datetime); this.datetimeStr = DateUtils.format("Y/m/d H:M", this.datetime);