-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give option to sort or filter by Created timestamp (#2293)
* add rough implementation for sorting and filtering by created * start to refactor * unit test date string comparison * unit test is free text date * unit test date filters * better standardize dates before comparing * support created being filterable and sortable in the experiments table * make iso date tz aware
- Loading branch information
1 parent
2189eab
commit 6eade74
Showing
14 changed files
with
321 additions
and
36 deletions.
There are no files selected for viewing
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,11 @@ | ||
import { ColumnType } from '../webview/contract' | ||
import { Column, ColumnType } from '../webview/contract' | ||
|
||
export const timestampColumn = { | ||
const type = ColumnType.TIMESTAMP | ||
|
||
export const timestampColumn: Column = { | ||
hasChildren: false, | ||
label: 'Created', | ||
path: 'Created', | ||
type: ColumnType.TIMESTAMP | ||
type, | ||
types: [type] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Operator } from '.' | ||
import { compareDateStrings } from './date' | ||
|
||
describe('compareDateStrings', () => { | ||
it('should compare two date strings and give the expected results', () => { | ||
const earlierDate = '2022-01-01' | ||
const laterDate = '2023-01-01' | ||
expect( | ||
compareDateStrings(earlierDate, Operator.GREATER_THAN, laterDate) | ||
).toBe(false) | ||
expect( | ||
compareDateStrings(laterDate, Operator.GREATER_THAN, earlierDate) | ||
).toBe(true) | ||
|
||
expect(compareDateStrings(earlierDate, Operator.LESS_THAN, laterDate)).toBe( | ||
true | ||
) | ||
expect(compareDateStrings(laterDate, Operator.LESS_THAN, earlierDate)).toBe( | ||
false | ||
) | ||
|
||
expect(compareDateStrings(earlierDate, Operator.EQUAL, laterDate)).toBe( | ||
false | ||
) | ||
}) | ||
|
||
it('should compare a date string and an ISO date strings from the different days and give the expected results', () => { | ||
const earlierDate = '2000-01-01' | ||
const laterTimestamp = '2000-01-02T00:00:01' | ||
|
||
expect( | ||
compareDateStrings(earlierDate, Operator.GREATER_THAN, laterTimestamp) | ||
).toBe(false) | ||
expect( | ||
compareDateStrings(laterTimestamp, Operator.GREATER_THAN, earlierDate) | ||
).toBe(true) | ||
|
||
expect( | ||
compareDateStrings(earlierDate, Operator.LESS_THAN, laterTimestamp) | ||
).toBe(true) | ||
expect( | ||
compareDateStrings(laterTimestamp, Operator.LESS_THAN, earlierDate) | ||
).toBe(false) | ||
|
||
expect( | ||
compareDateStrings(earlierDate, Operator.EQUAL, laterTimestamp) | ||
).toBe(false) | ||
}) | ||
|
||
it('should compare two ISO date strings from the same day and give the expected results', () => { | ||
const earlierTimestamp = '2000-01-01T00:12:00' | ||
const laterTimestamp = '2000-01-01T23:12:00' | ||
|
||
expect( | ||
compareDateStrings( | ||
earlierTimestamp, | ||
Operator.GREATER_THAN, | ||
laterTimestamp | ||
) | ||
).toBe(false) | ||
expect( | ||
compareDateStrings( | ||
laterTimestamp, | ||
Operator.GREATER_THAN, | ||
earlierTimestamp | ||
) | ||
).toBe(false) | ||
|
||
expect( | ||
compareDateStrings(earlierTimestamp, Operator.LESS_THAN, laterTimestamp) | ||
).toBe(false) | ||
expect( | ||
compareDateStrings(laterTimestamp, Operator.LESS_THAN, earlierTimestamp) | ||
).toBe(false) | ||
|
||
expect( | ||
compareDateStrings(earlierTimestamp, Operator.EQUAL, laterTimestamp) | ||
).toBe(true) | ||
}) | ||
}) |
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,30 @@ | ||
import { Operator } from '.' | ||
import { standardizeDate } from '../../../util/date' | ||
|
||
export const compareDateStrings = ( | ||
baseDateString: string | number | boolean, | ||
operator: Operator.LESS_THAN | Operator.GREATER_THAN | Operator.EQUAL, | ||
comparisonDateString: string | number | boolean | ||
): boolean => { | ||
if ( | ||
typeof baseDateString !== 'string' || | ||
typeof comparisonDateString !== 'string' | ||
) { | ||
return false | ||
} | ||
|
||
const epoch = standardizeDate(baseDateString) | ||
const otherEpoch = standardizeDate(comparisonDateString) | ||
|
||
switch (operator) { | ||
case Operator.LESS_THAN: | ||
return epoch < otherEpoch | ||
case Operator.GREATER_THAN: | ||
return epoch > otherEpoch | ||
case Operator.EQUAL: | ||
return epoch === otherEpoch | ||
|
||
default: | ||
return false | ||
} | ||
} |
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
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
Oops, something went wrong.