Fix millisecond display for date formatting

Summary: If we have a milliseconds portion of a date that's <100, we'd fill in zeroes in a symmetrical way (around the value) rather than filling in at the front, which led to some confusion.

Reviewed By: mweststrate

Differential Revision: D41342194

fbshipit-source-id: a8f60110dcad8bfa77b81abed88df0b0643c780e
This commit is contained in:
Pascal Hartig
2022-11-17 05:32:02 -08:00
committed by Facebook GitHub Bot
parent 0ac8c2a6b3
commit f1cbe7ed79
2 changed files with 5 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ import {
CopyOutlined, CopyOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import {Button, Typography} from 'antd'; import {Button, Typography} from 'antd';
import {isPlainObject, pad} from 'lodash'; import {isPlainObject, padStart} from 'lodash';
import React, {createElement, Fragment, isValidElement, useState} from 'react'; import React, {createElement, Fragment, isValidElement, useState} from 'react';
import {_tryGetFlipperLibImplementation} from 'flipper-plugin-core'; import {_tryGetFlipperLibImplementation} from 'flipper-plugin-core';
import {safeStringify} from 'flipper-plugin-core'; import {safeStringify} from 'flipper-plugin-core';
@@ -57,7 +57,7 @@ export const DataFormatter = {
res = res =
value.toTimeString().split(' ')[0] + value.toTimeString().split(' ')[0] +
'.' + '.' +
pad('' + value.getMilliseconds(), 3, '0'); padStart('' + value.getMilliseconds(), 3, '0');
break; break;
} }
if (value instanceof Map) { if (value instanceof Map) {

View File

@@ -21,6 +21,9 @@ test('default formatter', () => {
expect( expect(
DataFormatter.format(new Date(2020, 2, 3, 5, 8, 4, 244654)), DataFormatter.format(new Date(2020, 2, 3, 5, 8, 4, 244654)),
).toMatchInlineSnapshot(`"05:12:08.654"`); ).toMatchInlineSnapshot(`"05:12:08.654"`);
expect(
DataFormatter.format(new Date(1668609938.068577 * 1000)),
).toMatchInlineSnapshot(`"01:45:38.068"`);
expect(DataFormatter.format('test')).toMatchInlineSnapshot(`"test"`); expect(DataFormatter.format('test')).toMatchInlineSnapshot(`"test"`);
expect(DataFormatter.format({hello: 'world'})).toMatchInlineSnapshot(` expect(DataFormatter.format({hello: 'world'})).toMatchInlineSnapshot(`