File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
projects/common/src/utilities/coercers Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 1+ import { TimeDuration } from '../../time/time-duration' ;
2+ import { TimeUnit } from '../../time/time-unit.type' ;
13import { Coercer , CoercerOptions } from './coercer' ;
24
35export 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 }
You can’t perform that action at this time.
0 commit comments