Skip to content

Commit 6147b9e

Browse files
chore: static defaults
1 parent 1de3030 commit 6147b9e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

projects/common/src/utilities/coercers/date-coercer.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { TimeDuration } from '../../time/time-duration';
2+
import { TimeUnit } from '../../time/time-unit.type';
13
import { Coercer, CoercerOptions } from './coercer';
24

35
export class DateCoercer extends Coercer<Date, DateCoercerOptions> {
6+
private static readonly DEFAULT_TIME_WINDOW: DateCoercerOptions = {
7+
earliestDate: new Date(Date.now() - new TimeDuration(10, TimeUnit.Year).toMillis()),
8+
latestDate: new Date(Date.now() + new TimeDuration(10, TimeUnit.Year).toMillis())
9+
};
10+
411
public constructor(options: DateCoercerOptions = {}) {
512
super(options);
613
}
714

815
protected assignDefaults(options: DateCoercerOptions): DateCoercerOptions {
9-
const tenYearsInMillis = 10 * 365 * 24 * 60 * 60 * 1000;
10-
const now = Date.now();
11-
const tenYearsAgo = new Date(now - tenYearsInMillis);
12-
const tenYearsFuture = new Date(now + tenYearsInMillis);
13-
1416
return {
15-
earliestDate: tenYearsAgo,
16-
latestDate: tenYearsFuture,
17+
...DateCoercer.DEFAULT_TIME_WINDOW,
1718
...super.assignDefaults(options)
1819
};
1920
}

0 commit comments

Comments
 (0)