Skip to content

Commit

Permalink
fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoputzer committed Sep 17, 2024
1 parent f819a29 commit 562730d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ export function parseInterval (interval) {
}

export function daysBetween (date1, date2, oneDay = INTERVALS.get('1d')) {
return Math.round(
return Math.ceil(
Math.abs(
new Date(date1).getTime() - new Date(date2).getTime()
) / oneDay
)

// return Math.round(
// Math.abs(
// new Date(date1).getTime() - new Date(date2).getTime()
// ) / oneDay
// )
}

export function utcDate (now = new Date()) {
Expand Down
9 changes: 9 additions & 0 deletions test/lib/date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ describe('lib/date', () => {
it('returns the number of days between two dates with iso8601 format', () => {
equal(daysBetween(new Date('2021-09-26T10:30:00.000Z'), new Date('2021-09-27T10:30:00.000Z')), 1)
})

it('this bug is run on github actions and currently results to zero and prevents yesterdays candle to be downloaded on scheduled run', () => {
equal(
daysBetween(
new Date('2024-09-16T00:00:00.000Z'),
new Date('2024-09-16T01:02:23.498Z')
),
1)
})
})
describe('.utcDate', () => {
it('is callable', () => {
Expand Down

0 comments on commit 562730d

Please sign in to comment.