diff --git a/src/components/log/LiveLog.tsx b/src/components/log/LiveLog.tsx index 350c9ee..a81f435 100644 --- a/src/components/log/LiveLog.tsx +++ b/src/components/log/LiveLog.tsx @@ -11,7 +11,7 @@ import React, { Component } from "react"; import { animateScroll } from "react-scroll"; import { WithAPIData } from "../common/WithAPIData"; -import { humanTimestamp } from "../../util/dateUtils"; +import { getTimeFromTimestamp } from "../../util/dateUtils"; import api from "../../util/api"; export interface LiveLogProps { @@ -44,7 +44,7 @@ class LiveLog extends Component { nextId = this.props.nextID; log.map(item => - logHistory.push(humanTimestamp(item.timestamp) + " " + item.message) + logHistory.push(getTimeFromTimestamp(item.timestamp) + " " + item.message) ); const outputStyle = { diff --git a/src/util/__tests__/dateUtils.test.tsx b/src/util/__tests__/dateUtils.test.tsx new file mode 100644 index 0000000..ea703af --- /dev/null +++ b/src/util/__tests__/dateUtils.test.tsx @@ -0,0 +1,19 @@ +/* Pi-hole: A black hole for Internet advertisements + * (c) 2019 Pi-hole, LLC (https://pi-hole.net) + * Network-wide ad blocking via your own hardware. + * + * Web Interface + * Date/Time utility tests + * + * This file is copyright under the latest version of the EUPL. + * Please see LICENSE file for your rights under this license. */ + +import { getTimeFromTimestamp } from "../dateUtils"; + +const timestamp = 1574713854; + +describe("humanTimestamp", () => { + it("returns the time 20:30:54 from the input 1574713854", () => { + expect(getTimeFromTimestamp(timestamp)).toEqual("20:30:54"); + }); +}); diff --git a/src/util/dateUtils.tsx b/src/util/dateUtils.tsx index edbff72..a05214b 100644 --- a/src/util/dateUtils.tsx +++ b/src/util/dateUtils.tsx @@ -8,7 +8,7 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -export function humanTimestamp(input: number) { +export function getTimeFromTimestamp(input: number) { var date = new Date(input * 1000); var hours = date.getHours(); var minutes = "0" + date.getMinutes();