diff --git a/__tests__/bugs/d3-timezone.spec.ts b/__tests__/bugs/d3-timezone.spec.ts new file mode 100644 index 00000000..00b8db8a --- /dev/null +++ b/__tests__/bugs/d3-timezone.spec.ts @@ -0,0 +1,11 @@ +import { d3Time } from '../../src'; + +test('d3Time(1698796800000, 1701302400000, 5)', () => { + const ticks = d3Time(new Date(1698796800000), new Date(1701302400000), 5); + expect(ticks).toEqual([ + new Date('2023-11-04T23:00:00.000Z'), + new Date('2023-11-11T23:00:00.000Z'), + new Date('2023-11-18T23:00:00.000Z'), + new Date('2023-11-25T23:00:00.000Z'), + ]); +}); diff --git a/package.json b/package.json index 9cc1303c..59f3c782 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/scale", - "version": "0.4.13", + "version": "0.4.14", "description": "Toolkit for mapping abstract data into visual representation.", "license": "MIT", "main": "lib/index.js", @@ -20,7 +20,9 @@ "size": "limit-size", "lint": "eslint ./src/**/*.ts ./__tests__/**/*.ts && prettier ./src ./__tests__ --check ", "fix": "eslint ./src/**/*.ts ./__tests__/**/*.ts --fix && prettier ./src ./__tests__ --write ", - "test": "jest", + "test": "run-s test:timezone test:jest", + "test:jest": "jest --testPathIgnorePatterns=__tests__/bugs/d3-timezone.spec.ts", + "test:timezone": "cross-env TZ=Europe/Berlin jest __tests__/bugs/d3-timezone.spec.ts", "build:umd": "rimraf ./dist && rollup -c && npm run size", "build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib", "build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm", @@ -42,6 +44,7 @@ "@types/jest": "^26.0.20", "@typescript-eslint/eslint-plugin": "^4.18.0", "@typescript-eslint/parser": "^4.19.0", + "cross-env": "^7.0.3", "d3-scale": "^3.2.4", "eslint": "^7.22.0", "eslint-config-airbnb": "^18.2.1", diff --git a/src/utils/time-interval.ts b/src/utils/time-interval.ts index 1ccc6a48..2ba6cc51 100644 --- a/src/utils/time-interval.ts +++ b/src/utils/time-interval.ts @@ -63,7 +63,8 @@ export function createInterval(duration: number, floorish: TimeProcess, offseti: const ticks = []; const roundStep = Math.floor(step); const t = shouldAdjust ? ceil(start, step) : ceil(start); - for (let i = t; +i < +stop; offseti(i, roundStep), floori(i)) { + let index = 0; + for (let i = t; +i < +stop && index < 10; offseti(i, roundStep), floori(i), index += 1) { ticks.push(new Date(+i)); } return ticks; @@ -150,7 +151,7 @@ export const week: Interval = createInterval( date.setHours(0, 0, 0, 0); }, (date, step = 1) => { - date.setTime(+date + DURATION_WEEK * step); + date.setDate(date.getDate() + 7 * step); }, (date) => { const start = month.floor(date);