superset/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-time-format
Chris Williams 6c8e40c710 [build] fix typescript builds (#56)
* [build] fix typescript builds

* [typescript] ensure types pass in build

* [typescript][connection] declare modules in tests

* [typescript][connection] fix ts errors in tests

* [typescript][connection] test/types.ts => types/external.d.ts

* [chart][typescript] add @types/react-loadable

* [chart][components] convert to ts

* [charts][tests][broken] convert to ts

* [chart][typescript] re-write component generics

* [chart][typescript] fix reactify generic, add react-dom types

* [chart][typescript] more iteration

* - Tweaking reactify types (using Readonly types).
- Uncovered an issue in which ReactifyProps and Props can collide on id and className.
- Move @types/react-loadable to dev dependency
- Fixing a lint error

* [chart][deps] add @types/fetch-mock

* [client][typescript] add and export SupersetClientInterface

* [chart][clients] fix ts

* [charts][components] more ts iterations

* [chart][client] assert FormData type

* [chart][deps] try adding newest @types/react

* [chart][components][ts] fix reactify prop TS

* [chart] lint

* [chart][ts] lint #2, move @types to deps not dev-deps

* [chart][jest] fix tests

* [chart][tests] up branch coverage

* [chart][ts][test] null => undefined

* [chart][tests] hundo

* [chart][tests] update name

* [chart][ts] ChartClient type fixes
2021-11-26 11:44:38 +08:00
..
src allow leading and trailing space when looking up formatter (#46) 2021-11-26 11:44:36 +08:00
test [build] fix typescript builds (#56) 2021-11-26 11:44:38 +08:00
package.json v0.7.2 2021-11-26 11:44:37 +08:00
README.md Add @superset-ui/time-format (#38) 2021-11-26 11:44:36 +08:00

@superset-ui/time-format

Version David (path)

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.