From f1cbe7ed79f50f522552055f706f3ea7a835e74f Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 17 Nov 2022 05:32:02 -0800 Subject: [PATCH] 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 --- desktop/flipper-plugin/src/ui/DataFormatter.tsx | 4 ++-- .../flipper-plugin/src/ui/__tests__/DataFormatter.node.tsx | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/desktop/flipper-plugin/src/ui/DataFormatter.tsx b/desktop/flipper-plugin/src/ui/DataFormatter.tsx index 5a087a5e8..41b0abd61 100644 --- a/desktop/flipper-plugin/src/ui/DataFormatter.tsx +++ b/desktop/flipper-plugin/src/ui/DataFormatter.tsx @@ -13,7 +13,7 @@ import { CopyOutlined, } from '@ant-design/icons'; import {Button, Typography} from 'antd'; -import {isPlainObject, pad} from 'lodash'; +import {isPlainObject, padStart} from 'lodash'; import React, {createElement, Fragment, isValidElement, useState} from 'react'; import {_tryGetFlipperLibImplementation} from 'flipper-plugin-core'; import {safeStringify} from 'flipper-plugin-core'; @@ -57,7 +57,7 @@ export const DataFormatter = { res = value.toTimeString().split(' ')[0] + '.' + - pad('' + value.getMilliseconds(), 3, '0'); + padStart('' + value.getMilliseconds(), 3, '0'); break; } if (value instanceof Map) { diff --git a/desktop/flipper-plugin/src/ui/__tests__/DataFormatter.node.tsx b/desktop/flipper-plugin/src/ui/__tests__/DataFormatter.node.tsx index 5fc1818d5..97f57f229 100644 --- a/desktop/flipper-plugin/src/ui/__tests__/DataFormatter.node.tsx +++ b/desktop/flipper-plugin/src/ui/__tests__/DataFormatter.node.tsx @@ -21,6 +21,9 @@ test('default formatter', () => { expect( DataFormatter.format(new Date(2020, 2, 3, 5, 8, 4, 244654)), ).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({hello: 'world'})).toMatchInlineSnapshot(`