Skip to content

Commit 211532d

Browse files
Merge pull request #28 from imcaizheng/fix-last-week-day-calulation
weeklycount: fix calculation of last week day
2 parents d7dc87d + 4a7221f commit 211532d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"aws-sdk": "^2.787.0",
2525
"config": "^3.3.2",
2626
"cors": "^2.8.5",
27+
"date-fns": "^2.16.1",
2728
"dotenv": "^8.2.0",
2829
"express": "^4.17.1",
2930
"express-interceptor": "^1.2.0",

src/services/TeamService.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const _ = require('lodash')
66
const Joi = require('joi')
7+
const dateFNS = require('date-fns')
78
const helper = require('../common/helper')
89
const logger = require('../common/logger')
910
const JobService = require('./JobService')
@@ -65,13 +66,9 @@ async function getTeamDetail (currentUser, projects, isSearch = true) {
6566

6667
// Get first week day and last week day
6768
const curr = new Date()
68-
curr.setHours(0, 0, 0, 0)
69-
const first = curr.getDate() - curr.getDay()
70-
const last = first + 6
69+
const firstDay = dateFNS.startOfWeek(curr)
70+
const lastDay = dateFNS.endOfWeek(curr)
7171

72-
const firstDay = new Date(curr.setDate(first))
73-
const lastDay = new Date(curr.setDate(last))
74-
lastDay.setHours(23, 59, 59, 59) // the end of the day
7572
logger.debug({ component: 'TeamService', context: 'getTeamDetail', message: `week started: ${firstDay}, week ended: ${lastDay}` })
7673

7774
const result = []

0 commit comments

Comments
 (0)