mirror of
https://github.com/apache/superset.git
synced 2024-09-19 20:19:37 -04:00
97f18e686b
* build: migrate to nimbus * build: update gitignore * build: update package.json * build: update travis config * build: lower engine requirements * build: adjust typescript config * fix: errors * fix: change yarn run to yarn * fix: lint (cherry picked from commit 22328c349c9b987eecc5e46fb306e459b6a9cadc) * fix: eslint rules * fix: lint * fix: setup file * fix: more lint * fix: lint - pass build and lint * fix: test setup and babel transform runtime (cherry picked from commit dd55fd88ced045a8f83ca771705721bf2f930ff0) * fix: timeout issues * fix: some broken test due to jest.setTimeout * fix: computeMaxFontSize tests * fix: createLoadableRenderer test * fix: loadble and broken tests due to warnings * fix: test coverage * fix: coverage of generator tests * fix: all unit tests pass * fix: remove yeutech-lab/react-loadable |
||
---|---|---|
.. | ||
src | ||
test | ||
package.json | ||
README.md |
@superset-ui/time-format
Description
Example usage
Add @superset-ui/time-format
, a module for formatting time. Functions getTimeFormatter
and formatTime
should be used instead of calling d3.utcFormat
or d3.timeFormat
directly.
import { getTimeFormatter } from '@superset-ui/time-format';
const formatter = getTimeFormatter('%Y-%m-d');
console.log(formatter(new Date()));
or
import { formatTime } from '@superset-ui/time-format';
console.log(formatTime('%Y-%m-d', new Date()));
It is powered by a registry to support registration of custom formatting, with fallback to d3.utcFormat
or d3.timeFormat
(if the formatId starts with local!
)
import { getTimeFormatterRegistry, formatTime, TimeFormatter } from '@superset-ui/time-format';
getTimeFormatterRegistry().registerValue('my_format', new TimeFormatter({
id: 'my_format',
formatFunc: v => `my special format of ${utcFormat('%Y')(v)}`
});
console.log(formatTime('my_format', new Date(2018)));
// prints 'my special format of 2018'
It also define constants for common d3 time formats. See TimeFormats.js.
import { TimeFormats } from '@superset-ui/time-format';
TimeFormats.DATABASE_DATETIME // '%Y-%m-%d %H:%M:%S'
TimeFormats.US_DATE // '%m/%d/%Y'
API
fn(args)
- Do something
Development
@data-ui/build-config
is used to manage the build configuration for this package including babel
builds, jest testing, eslint, and prettier.