This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert time-format to TypeScript (#78)
* convert source to TS * fix lint * convert unit test to TS * fix rebasing issue * fix typings * use ts-ignore
- Loading branch information
Showing
26 changed files
with
171 additions
and
115 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
7 changes: 0 additions & 7 deletions
7
packages/superset-ui-number-format/test/factories/createD3NumberFormatter.test.js
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/superset-ui-number-format/test/factories/createD3NumberFormatter.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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
|
||
import { ExtensibleFunction, isRequired } from '@superset-ui/core'; | ||
import { TimeFormatFunction } from './types'; | ||
|
||
export const PREVIEW_TIME = new Date(Date.UTC(2017, 1, 14, 11, 22, 33)); | ||
|
||
export default class TimeFormatter extends ExtensibleFunction { | ||
id: string; | ||
label: string; | ||
description: string; | ||
formatFunc: TimeFormatFunction; | ||
useLocalTime: boolean; | ||
|
||
constructor(config: { | ||
id: string; | ||
label?: string; | ||
description?: string; | ||
formatFunc: TimeFormatFunction; | ||
useLocalTime?: boolean; | ||
}) { | ||
super((value: Date | null | undefined) => this.format(value)); | ||
|
||
const { | ||
id = isRequired('config.id'), | ||
label, | ||
description = '', | ||
formatFunc = isRequired('config.formatFunc'), | ||
useLocalTime = false, | ||
} = config; | ||
|
||
this.id = id; | ||
this.label = label || id; | ||
this.description = description; | ||
this.formatFunc = formatFunc; | ||
this.useLocalTime = useLocalTime; | ||
} | ||
|
||
format(value: Date | null | undefined) { | ||
if (value === null || value === undefined) { | ||
return `${value}`; | ||
} | ||
|
||
return this.formatFunc(value); | ||
} | ||
|
||
preview(value: Date = PREVIEW_TIME) { | ||
return `${value.toUTCString()} => ${this.format(value)}`; | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,2 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export type TimeFormatFunction = (value: Date) => string; |
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
File renamed without changes.
Oops, something went wrong.