Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: smarter date formatter #25404

Merged
merged 5 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Increase code coverage
  • Loading branch information
betodealmeida committed Sep 26, 2023
commit 6b7b0e617f3937620e5443541fa358da0bb46816
3 changes: 3 additions & 0 deletions superset-frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* under the License.
*/

// timezone for unit tests
process.env.TZ = 'America/New_York';

module.exports = {
testRegex:
'\\/superset-frontend\\/(spec|src|plugins|packages|tools)\\/.*(_spec|\\.test)\\.[jt]sx?$',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,43 @@ import finestTemporalGrain from './finestTemporalGrain';

test('finestTemporalGrain', () => {
const monthFormatter = finestTemporalGrain([
1041379200000, // 2003-01-01 00:00:00Z
1044057600000, // 2003-02-01 00:00:00Z
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2003-02-01 00:00:00Z').getTime(),
]);
expect(monthFormatter(1041379200000)).toBe('2003-01-01');
expect(monthFormatter(1044057600000)).toBe('2003-02-01');
expect(monthFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2003-01-01',
);
expect(monthFormatter(new Date('2003-02-01 00:00:00Z').getTime())).toBe(
'2003-02-01',
);

const yearFormatter = finestTemporalGrain([
1041379200000, // 2003-01-01 00:00:00Z
1072915200000, // 2004-01-01 00:00:00Z
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2004-01-01 00:00:00Z').getTime(),
]);
expect(yearFormatter(1041379200000)).toBe('2003');
expect(yearFormatter(1072915200000)).toBe('2004');
expect(yearFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2003',
);
expect(yearFormatter(new Date('2004-01-01 00:00:00Z').getTime())).toBe(
'2004',
);

const milliSecondFormatter = finestTemporalGrain([
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2003-04-05 06:07:08.123Z').getTime(),
]);
expect(milliSecondFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2003-01-01 00:00:00.000',
);

const localTimeFormatter = finestTemporalGrain(
[
new Date('2003-01-01 00:00:00Z').getTime(),
new Date('2003-02-01 00:00:00Z').getTime(),
],
true,
);
expect(localTimeFormatter(new Date('2003-01-01 00:00:00Z').getTime())).toBe(
'2002-12-31 19:00',
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
getDataRecordFormatter({
timeFormatter: finestTemporalGrainFormatter(data.map(el => el.col)),
}),
[data, datatype],
[data],
);

const updateDataMask = useCallback(
Expand Down