forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(time-format): add full-date to weekly time formatter (apache#486)
- Loading branch information
1 parent
6facf1d
commit 11547a0
Showing
7 changed files
with
79 additions
and
12 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
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
19 changes: 19 additions & 0 deletions
19
...-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-time-format/src/types.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 +1,20 @@ | ||
export type TimeFormatFunction = (value: Date) => string; | ||
|
||
export type TimeGranularity = | ||
| 'date' | ||
| 'PT1S' | ||
| 'PT1M' | ||
| 'PT5M' | ||
| 'PT10M' | ||
| 'PT15M' | ||
| 'PT0.5H' | ||
| 'PT1H' | ||
| 'P1D' | ||
| 'P1W' | ||
| 'P1M' | ||
| 'P0.25Y' | ||
| 'P1Y' | ||
| '1969-12-28T00:00:00Z/P1W' | ||
| '1969-12-29T00:00:00Z/P1W' | ||
| 'P1W/1970-01-03T00:00:00Z' | ||
| 'P1W/1970-01-04T00:00:00Z'; |
34 changes: 34 additions & 0 deletions
34
...ui/packages/superset-ui-time-format/test/factories/getTimeFormatterForGranularity.test.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,34 @@ | ||
import getFormatter from '../../src/factories/getTimeFormatterForGranularity'; | ||
import smartDateVerbose from '../../src/formatters/smartDateVerbose'; | ||
|
||
describe('getTimeFormatterForGranularity()', () => { | ||
it('use smartDate when granularity unknown or undefined', () => { | ||
expect(getFormatter(undefined)).toBe(smartDateVerbose); | ||
// @ts-ignore | ||
expect(getFormatter('random-string')).toBe(smartDateVerbose); | ||
}); | ||
|
||
it('format time for known granularities', () => { | ||
// JS Date constructor month is zero-based | ||
const date = new Date(2020, 4, 10, 11, 10, 1); // May 10, 2020 is Sunday | ||
expect(getFormatter('date')(date)).toBe('2020-05-10'); | ||
expect(getFormatter('PT1S')(date)).toBe('2020-05-10 11:10:01'); | ||
expect(getFormatter('PT1M')(date)).toBe('2020-05-10 11:10'); | ||
expect(getFormatter('PT5M')(date)).toBe('2020-05-10 11:10'); | ||
expect(getFormatter('PT10M')(date)).toBe('2020-05-10 11:10'); | ||
expect(getFormatter('PT15M')(date)).toBe('2020-05-10 11:10'); | ||
expect(getFormatter('PT0.5H')(date)).toBe('2020-05-10 11:10'); | ||
expect(getFormatter('PT1H')(date)).toBe('2020-05-10 11:00'); | ||
expect(getFormatter('P1D')(date)).toBe('2020-05-10'); | ||
expect(getFormatter('P1W')(date)).toBe('2020-05-10 W19'); | ||
expect(getFormatter('P1M')(date)).toBe('2020-05'); | ||
expect(getFormatter('P0.25Y')(date)).toBe('2020 Q2'); | ||
expect(getFormatter('P1Y')(date)).toBe('2020'); | ||
// sunday based week | ||
expect(getFormatter('1969-12-28T00:00:00Z/P1W')(date)).toBe('2020-05-10 W19'); | ||
expect(getFormatter('P1W/1970-01-03T00:00:00Z')(date)).toBe('2020-05-10 W19'); | ||
// monday based week | ||
expect(getFormatter('1969-12-29T00:00:00Z/P1W')(date)).toBe('2020-05-10 W18'); | ||
expect(getFormatter('P1W/1970-01-04T00:00:00Z')(date)).toBe('2020-05-10 W18'); | ||
}); | ||
}); |
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