Skip to content

Commit 8d03062

Browse files
committed
Fix seed2 generating intervals with seconds / milliseconds
Not typically what we want. Might be possible to prevent this in DB level, if it seems important.
1 parent 83e9101 commit 8d03062

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test-db-manager/src/builders/common.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ import { randomInt } from '../utils';
66
export const buildLabelArray = (labelPrefix: string, labelCount: number) =>
77
range(1, labelCount + 1).map((no) => `${labelPrefix}${no}`);
88

9-
export const buildRandomDuration = (min: Duration, max: Duration) =>
10-
Duration.fromMillis(randomInt(min.toMillis(), max.toMillis()));
9+
export const buildRandomDuration = (min: Duration, max: Duration) => {
10+
const unroundedDuration = Duration.fromMillis(
11+
randomInt(min.toMillis(), max.toMillis()),
12+
);
13+
14+
// We only want to handle durations in minute precision, currently.
15+
const durationParts = unroundedDuration.rescale().toObject();
16+
delete durationParts.seconds;
17+
delete durationParts.milliseconds;
18+
const durationInMinutes = Duration.fromObject(durationParts);
19+
20+
return durationInMinutes;
21+
};
1122

1223
type ConstantCount = number;
1324
type RandomCount = { min: number; max: number };

0 commit comments

Comments
 (0)