diff --git a/CHANGELOG.md b/CHANGELOG.md index f56468cd2..f2aaeb4cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ ([#7734](https://github.com/mitmproxy/mitmproxy/pull/7734), @lups2000) - Add syntax highlighting for CSS and JavaScript contentviews. ([#7749](https://github.com/mitmproxy/mitmproxy/pull/7749), @mhils) +- Display local timezone in the Timing tab of mitmweb. + ([#7804](https://github.com/mitmproxy/mitmproxy/pull/7804), @lups2000) ## 25 May 2025: mitmproxy 12.1.1 diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs index 7e2dce91d..7036d75de 100644 --- a/web/eslint.config.mjs +++ b/web/eslint.config.mjs @@ -38,7 +38,12 @@ export default defineConfig([ }, }, { - files: ["jest.config.js", "gulpfile.js", "setup-jest.js"], + files: [ + "jest.config.js", + "gulpfile.js", + "setup-jest.js", + "setup-global-jest.js", + ], languageOptions: { globals: globals.node }, }, { diff --git a/web/jest.config.js b/web/jest.config.js index 268a96001..4f3f177f8 100644 --- a/web/jest.config.js +++ b/web/jest.config.js @@ -25,5 +25,6 @@ module.exports = async () => { ], }, setupFilesAfterEnv: ["/setup-jest.js"], + globalSetup: "/setup-global-jest.js", }; }; diff --git a/web/setup-global-jest.js b/web/setup-global-jest.js new file mode 100644 index 000000000..13e803927 --- /dev/null +++ b/web/setup-global-jest.js @@ -0,0 +1,3 @@ +export default function () { + process.env.TZ = "UTC"; +} diff --git a/web/setup-jest.js b/web/setup-jest.js index 5946270e2..fdf9497d5 100644 --- a/web/setup-jest.js +++ b/web/setup-jest.js @@ -1,4 +1,3 @@ -process.env.TZ = "UTC"; const err = console.error; console.warn = console.error = function () { err.apply(console, arguments); diff --git a/web/src/js/__tests__/utilsSpec.tsx b/web/src/js/__tests__/utilsSpec.tsx index db03e9f58..de437c4d9 100644 --- a/web/src/js/__tests__/utilsSpec.tsx +++ b/web/src/js/__tests__/utilsSpec.tsx @@ -23,10 +23,10 @@ describe("formatTimeDelta", () => { describe("formatTimeStamp", () => { it("should return formatted time", () => { expect( - utils.formatTimeStamp(1483228800, { milliseconds: false }), + utils.formatTimeStamp(1483228800, { includeMilliseconds: false }), ).toEqual("2017-01-01 00:00:00"); expect( - utils.formatTimeStamp(1483228800, { milliseconds: true }), + utils.formatTimeStamp(1483228800, { includeMilliseconds: true }), ).toEqual("2017-01-01 00:00:00.000"); }); }); diff --git a/web/src/js/components/FlowView/Connection.tsx b/web/src/js/components/FlowView/Connection.tsx index 211bda1eb..6e31fc9f3 100644 --- a/web/src/js/components/FlowView/Connection.tsx +++ b/web/src/js/components/FlowView/Connection.tsx @@ -115,7 +115,7 @@ export function CertificateInfo({ flow }: { flow: Flow }): React.ReactElement { Valid from {formatTimeStamp(cert.notbefore, { - milliseconds: false, + includeMilliseconds: false, })} @@ -123,7 +123,7 @@ export function CertificateInfo({ flow }: { flow: Flow }): React.ReactElement { Valid to {formatTimeStamp(cert.notafter, { - milliseconds: false, + includeMilliseconds: false, })} diff --git a/web/src/js/utils.ts b/web/src/js/utils.ts index 1b05144f0..b37d9ebf5 100644 --- a/web/src/js/utils.ts +++ b/web/src/js/utils.ts @@ -33,12 +33,22 @@ export const formatTimeDelta = function (milliseconds) { export const formatTimeStamp = function ( seconds: number, - { milliseconds = true } = {}, + { includeMilliseconds = true } = {}, ) { - const utc = new Date(seconds * 1000); - let ts = utc.toISOString().replace("T", " ").replace("Z", ""); - if (!milliseconds) ts = ts.slice(0, -4); - return ts; + const date = new Date(seconds * 1000); + + const yearStr = String(date.getFullYear()); + const monthStr = String(date.getMonth() + 1).padStart(2, "0"); + const dayStr = String(date.getDate()).padStart(2, "0"); + const hourStr = String(date.getHours()).padStart(2, "0"); + const minuteStr = String(date.getMinutes()).padStart(2, "0"); + const secondStr = String(date.getSeconds()).padStart(2, "0"); + const millisecondStr = String(date.getMilliseconds()).padStart(3, "0"); + + let timestamp = `${yearStr}-${monthStr}-${dayStr} ${hourStr}:${minuteStr}:${secondStr}`; + if (includeMilliseconds) timestamp += `.${millisecondStr}`; + + return timestamp; }; export function formatAddress(address: [string, number]): string {