-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
• trying to fix #2 timezone issues
- Loading branch information
Showing
6 changed files
with
121 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { describe, it } from 'node:test' | ||
import { ok, strictEqual } from 'assert' | ||
|
||
describe('lib/cache', () => {}) | ||
|
||
// async function readCoinbaseCache(startsWith = 'coinbase,', directory = 'cache', { readdir } = fs, { join } = path) { | ||
// return ( await readdir(directory) ) | ||
// .filter(file => file.startsWith(startsWith)) | ||
// .map(file => { | ||
// const [exchange, id, rest] = file.split(',') | ||
// const [interval, extension] = rest.split('.') | ||
// return { exchange, id, interval, extension, path: join(directory, file) } | ||
// }) | ||
// } | ||
|
||
|
||
|
||
// describe('lib/cache', () => { | ||
// it('returns an array of objects', async () => { | ||
// const cache = await readCoinbaseCache('coinbase,', '../cache') | ||
// console.log(cache) | ||
// }) | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,86 @@ | ||
import { describe, it } from 'node:test' | ||
import { ok, strictEqual } from 'node:assert' | ||
|
||
import { INTERVALS, parseInterval, daysBetween, jsonDateReviver } from '../../lib/date.mjs' | ||
import { INTERVALS, parseInterval, daysBetween, jsonDateReviver, utcDate } from '../../lib/date.mjs' | ||
import { dateReviver } from '../../lib/json.mjs' | ||
|
||
describe('lib/date', () => { | ||
describe('.INTERVALS', () => { | ||
it('is a Map', () => { | ||
ok(INTERVALS instanceof Map) | ||
}) | ||
it('has a key of "1y" for years', () => { | ||
ok(INTERVALS.has('1y')) | ||
}) | ||
it('has a key of "1m" for months', () => { | ||
ok(INTERVALS.has('1m')) | ||
}) | ||
it('has a key of "1d" for days', () => { | ||
ok(INTERVALS.has('1d')) | ||
}) | ||
it('has a key of "1h" for hours', () => { | ||
ok(INTERVALS.has('1h')) | ||
}) | ||
it('has a key of "1" for minutes', () => { | ||
ok(INTERVALS.has('1')) | ||
}) | ||
}) | ||
describe('.daysBetween', () => { | ||
it('is callable', () => { | ||
strictEqual(typeof daysBetween, 'function') | ||
}) | ||
it('returns a number', () => { | ||
strictEqual(typeof daysBetween(new Date(), new Date()), 'number') | ||
}) | ||
it('returns the number of days between two dates', () => { | ||
strictEqual(daysBetween(new Date('2021-09-26'), new Date('2021-09-27')), 1) | ||
}) | ||
it('returns the number of days between two dates with iso8601 format', () => { | ||
strictEqual(daysBetween(new Date('2021-09-26T10:30:00.000Z'), new Date('2021-09-27T10:30:00.000Z')), 1) | ||
}) | ||
}) | ||
describe.todo('.parseInterval', () => { | ||
it('is callable', () => { | ||
strictEqual(typeof parseInterval, 'function') | ||
}) | ||
it('returns a number', () => { | ||
strictEqual(typeof parseInterval('1y'), 'number') | ||
}) | ||
it('handles years|y, months|m, weeks|w, days|d, hours|h, and minutes (without any label)', () => { | ||
strictEqual(parseInterval('1y'), 31536000000) | ||
strictEqual(parseInterval('1m'), 2592000000) | ||
strictEqual(parseInterval('1w'), 604800000) | ||
strictEqual(parseInterval('1d'), 86400000) | ||
strictEqual(parseInterval('1h'), 3600000) | ||
strictEqual(parseInterval('1'), 60000) | ||
}) | ||
it('handles multiples of any given interval', () => { | ||
strictEqual(parseInterval('2y'), 63072000000) | ||
strictEqual(parseInterval('3m'), 7776000000) | ||
strictEqual(parseInterval('2w'), 1209600000) | ||
strictEqual(parseInterval('3d'), 259200000) | ||
strictEqual(parseInterval('2h'), 7200000) | ||
strictEqual(parseInterval('2'), 120000) | ||
}) | ||
}) | ||
describe('.parseInterval', () => {}) | ||
describe('.daysBetween', () => {}) | ||
describe('.jsonDateReviver (deprecated)', () => { | ||
it('is duplicate of ~/lib/json.mjs:dateReviver', () => { | ||
strictEqual(jsonDateReviver.toString(), dateReviver.toString().replace(/^function\s+\w+\s*\(/, `function ${jsonDateReviver.name} (`)) | ||
}) | ||
it.skip('is not callable anymore', () => { | ||
strictEqual(typeof jsonDateReviver, 'undefined') | ||
}) | ||
}) | ||
describe('.utcDate', () => { | ||
it('is callable', () => { | ||
strictEqual(typeof utcDate, 'function') | ||
}) | ||
it('returns a Date', () => { | ||
ok(utcDate() instanceof Date) | ||
}) | ||
it('returns a Date that is adjusted to .getTimezoneOffset ', () => { | ||
const now = new Date() | ||
strictEqual(utcDate(now).toJSON(), new Date(now.getTime() + (now.getTimezoneOffset() * 6e4)).toJSON()) | ||
}) | ||
}) | ||
}) |