-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0e1d176
commit 97450c2
Showing
8 changed files
with
31 additions
and
31 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
aurelia-slickgrid/src/aurelia-slickgrid/sorters/compareDateUtility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as moment from 'moment'; | ||
|
||
export function compareDates(value1: any, value2: any, sortDirection: number, format: string | moment.MomentBuiltinFormat, strict?: boolean) { | ||
let diff = 0; | ||
|
||
if (value1 === null || value1 === '' || !moment(value1, format, strict).isValid()) { | ||
diff = -1; | ||
} else if (value2 === null || value2 === '' || !moment(value2, format, strict).isValid()) { | ||
diff = 1; | ||
} else { | ||
const date1 = moment(value1, format, strict); | ||
const date2 = moment(value2, format, strict); | ||
diff = parseInt(date1.format('X'), 10) - parseInt(date2.format('X'), 10); | ||
} | ||
|
||
return sortDirection * (diff === 0 ? 0 : (diff > 0 ? 1 : -1)); | ||
} |
6 changes: 3 additions & 3 deletions
6
aurelia-slickgrid/src/aurelia-slickgrid/sorters/dateIsoSorter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { mapMomentDateFormatWithFieldType } from './../services/utilities'; | ||
import { FieldType, Sorter } from './../models/index'; | ||
import { compareDates } from './sorterUtilities'; | ||
import { compareDates } from './compareDateUtility'; | ||
const FORMAT = mapMomentDateFormatWithFieldType(FieldType.dateIso); | ||
|
||
export const dateIsoSorter: Sorter = (value1, value2, sortDirection) => { | ||
return compareDates(sortDirection, value1, value2, FORMAT, true); | ||
export const dateIsoSorter: Sorter = (value1: any, value2: any, sortDirection: number) => { | ||
return compareDates(value1, value2, sortDirection, FORMAT, true); | ||
}; |
6 changes: 3 additions & 3 deletions
6
aurelia-slickgrid/src/aurelia-slickgrid/sorters/dateSorter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import * as moment from 'moment'; | ||
import { Sorter } from './../models/sorter.interface'; | ||
import { compareDates } from './sorterUtilities'; | ||
import { compareDates } from './compareDateUtility'; | ||
|
||
export const dateSorter: Sorter = (value1, value2, sortDirection) => { | ||
return compareDates(sortDirection, value1, value2, moment.ISO_8601); | ||
export const dateSorter: Sorter = (value1: any, value2: any, sortDirection: number) => { | ||
return compareDates(value1, value2, sortDirection, moment.ISO_8601); | ||
}; |
6 changes: 3 additions & 3 deletions
6
aurelia-slickgrid/src/aurelia-slickgrid/sorters/dateUsShortSorter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { mapMomentDateFormatWithFieldType } from './../services/utilities'; | ||
import { FieldType, Sorter } from './../models/index'; | ||
import { compareDates } from './sorterUtilities'; | ||
import { compareDates } from './compareDateUtility'; | ||
const FORMAT = mapMomentDateFormatWithFieldType(FieldType.dateUsShort); | ||
|
||
export const dateUsShortSorter: Sorter = (value1, value2, sortDirection) => { | ||
return compareDates(sortDirection, value1, value2, FORMAT, true); | ||
export const dateUsShortSorter: Sorter = (value1: any, value2: any, sortDirection: number) => { | ||
return compareDates(value1, value2, sortDirection, FORMAT, true); | ||
}; |
6 changes: 3 additions & 3 deletions
6
aurelia-slickgrid/src/aurelia-slickgrid/sorters/dateUsSorter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { mapMomentDateFormatWithFieldType } from './../services/utilities'; | ||
import { FieldType, Sorter } from './../models/index'; | ||
import { compareDates } from './sorterUtilities'; | ||
import { compareDates } from './compareDateUtility'; | ||
const FORMAT = mapMomentDateFormatWithFieldType(FieldType.dateUs); | ||
|
||
export const dateUsSorter: Sorter = (value1, value2, sortDirection) => { | ||
return compareDates(sortDirection, value1, value2, FORMAT, true); | ||
export const dateUsSorter: Sorter = (value1: any, value2: any, sortDirection: number) => { | ||
return compareDates(value1, value2, sortDirection, FORMAT, true); | ||
}; |
2 changes: 1 addition & 1 deletion
2
aurelia-slickgrid/src/aurelia-slickgrid/sorters/numericSorter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
aurelia-slickgrid/src/aurelia-slickgrid/sorters/stringSorter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters