Skip to content

Commit

Permalink
Merge pull request #339 from easyops-cn/steve/fix-time
Browse files Browse the repository at this point in the history
fix(): use millisecond instead of microsecond
  • Loading branch information
qiaofengxi authored Jul 12, 2024
2 parents c8a41d3 + db66432 commit fdc7a27
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("BrickHumanizeTime", () => {
const wrapper = shallow(
<BrickHumanizeTime
value={1563509000}
isMicrosecond={true}
isMillisecond={true}
isCostTime={true}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isNil } from "lodash";

interface BrickHumanizeTimeProps {
value: number | string;
isMicrosecond?: boolean;
isMillisecond?: boolean;
formatter?: HumanizeTimeFormat;
isCostTime?: boolean;
inputFormat?: string;
Expand All @@ -26,7 +26,7 @@ export function BrickHumanizeTime(
): React.ReactElement {
const {
value,
isMicrosecond,
isMillisecond,
inputFormat,
outputFormat,
isCostTime,
Expand All @@ -40,7 +40,7 @@ export function BrickHumanizeTime(

let ts;
if (typeof value === "number") {
ts = isMicrosecond ? value : Number(value) * 1000;
ts = isMillisecond ? value : Number(value) * 1000;
} else {
const time = moment(value, inputFormat);
ts = time.unix() * 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import ReactDOM from "react-dom";
import "./";

const spyOnRender = jest.spyOn(ReactDOM, "render").mockImplementation(() => {});
const spyOnRender = jest
.spyOn(ReactDOM, "render")
.mockImplementation(() => void 0);
const unmountComponentAtNode = jest
.spyOn(ReactDOM, "unmountComponentAtNode")
.mockImplementation((() => {}) as any);
.mockImplementation((() => void 0) as any);

jest.spyOn(console, "warn").mockImplementation(() => void 0);
jest.spyOn(console, "warn").mockImplementation(() => void 0);

describe("presentational-bricks.brick-humanize-time", () => {
it("should create a custom element", async () => {
Expand All @@ -17,8 +19,8 @@ describe("presentational-bricks.brick-humanize-time", () => {
dataSource: {},
fields: { value: "" },
isCostTime: false,
isMicrosecond: true,
formatter: "accurate"
isMillisecond: true,
formatter: "accurate",
});
// Always waiting for async `(dis)connectedCallback`
await jest.runAllTimers();
Expand Down
13 changes: 10 additions & 3 deletions bricks/presentational-bricks/src/brick-humanize-time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class BrickHumanizeTimeElement extends UpdatingElement {
<BrickHumanizeTime
value={value}
formatter={this.formatter}
isMicrosecond={this.isMicrosecond}
isMillisecond={this.isMillisecond ?? this.isMicrosecond}
isCostTime={this.isCostTime}
link={link}
inputFormat={this.inputFormat}
Expand Down Expand Up @@ -145,14 +145,21 @@ export class BrickHumanizeTimeElement extends UpdatingElement {
formatter: HumanizeTimeFormat;

/**
* @required false
* @default false
* @description value 值的单位是否为毫秒
* @group advanced
*/
@property({
type: Boolean,
})
isMillisecond: boolean;

/**
* @description value 值的单位是否为毫秒(此处属性 id 写错,实际表达意义为 isMillisecond)
* @deprecated 请使用 `isMillisecond`
*/
@property({
type: Boolean,
})
isMicrosecond: boolean;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const BrickHumanizeTimeStory: Story = {
brick: "presentational-bricks.brick-humanize-time",
properties: {
value: 1571017058000,
isMicrosecond: true,
isMillisecond: true,
formatter: "relative",
},
},
Expand Down

0 comments on commit fdc7a27

Please sign in to comment.