Skip to content

Commit

Permalink
fix(time): infinite loop for ticks of Berlin time (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Dec 18, 2023
1 parent 1d79503 commit 70c03b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions __tests__/bugs/d3-timezone.spec.ts
Original file line number Diff line number Diff line change
@@ -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'),
]);
});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/utils/time-interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 70c03b0

Please sign in to comment.