Skip to content

Commit

Permalink
fix: removed unnecessary offset in daysBetween() (#539)
Browse files Browse the repository at this point in the history
* fix: removed unnecessary offset in daysBetween

* ci: added test to nodejs.yml

---------

Co-authored-by: David Golightly <[email protected]>
  • Loading branch information
dereekb and davidgoli authored Nov 10, 2023
1 parent 62e7320 commit 26c799f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ jobs:
- run: LANG=en_CA TZ=America/Vancouver yarn test
- run: LANG=en_US TZ=America/Los_Angeles yarn test
- run: LANG=sw_KE TZ=Africa/Nairobi yarn test
- run: LANG=en_KI TZ=Pacific/Kiritimati yarn test
- run: LANG=jp_JP TZ=Asia/Tokyo yarn test-ci
- run: nyc report --reporter=json && codecov -t ${{ secrets.CODECOV_REPO_TOKEN }} -f coverage/*.json
6 changes: 4 additions & 2 deletions src/dateutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ export const tzOffset = function (date: Date) {
export const daysBetween = function (date1: Date, date2: Date) {
// The number of milliseconds in one day
// Convert both dates to milliseconds
const date1ms = date1.getTime() - tzOffset(date1)
const date2ms = date2.getTime() - tzOffset(date2)
const date1ms = date1.getTime()
const date2ms = date2.getTime()

// Calculate the difference in milliseconds
const differencems = date1ms - date2ms

// Convert back to days and return
return Math.round(differencems / ONE_DAY)
}
Expand Down

0 comments on commit 26c799f

Please sign in to comment.