Skip to content

Commit

Permalink
Merge pull request #5 from Volicon/f/date-optimizations
Browse files Browse the repository at this point in the history
Removed slow implicit date to number convertion
  • Loading branch information
Vlad Balin authored Jan 4, 2017
2 parents 2818722 + b9b43bc commit 950b096
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
15 changes: 9 additions & 6 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/record/attributes/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ export class DateType extends AnyType {
convert( value : any, a?, b?, record? ){
if( value == null || value instanceof Date ) return value;

const date = new Date( value );
const date = new Date( value ),
timestamp = date.getTime();

if( isNaN( +date ) ){
if( timestamp !== timestamp ){
this._log( 'warn', 'assigned with Invalid Date', value, record );
}

return date;
}

validate( model, value, name ) {
if( value != null && isNaN( +value ) ) return name + ' is Invalid Date';
if( value != null ){
const timestamp = value.getTime();
if( timestamp !== timestamp ) return name + ' is Invalid Date';
}
}

toJSON( value ) { return value && value.toISOString(); }

isChanged( a, b ) { return ( a && +a ) !== ( b && +b ); }
isChanged( a, b ) { return ( a && a.getTime() ) !== ( b && b.getTime() ); }

clone( value ) { return value && new Date( +value ); }
clone( value ) { return value && new Date( value.getTime() ); }
}

Date._attribute = DateType;
Expand Down

0 comments on commit 950b096

Please sign in to comment.