Skip to content

Commit 606eb0e

Browse files
authored
Show long cache values as days/hours/minutes. (#144)
1 parent bfceec4 commit 606eb0e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/ts/helpers/parse.ts

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ export function formatMilliseconds(millis: number): string {
6565
return `${roundNumber(millis, 3)} ms`;
6666
}
6767

68+
const SECONDS_PER_MINUTE = 60;
69+
const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
70+
const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
71+
72+
export function formatSeconds(seconds: number): string {
73+
const raw = `${roundNumber(seconds, 3)} s`;
74+
if (seconds > SECONDS_PER_DAY) {
75+
return `${raw} (~${roundNumber(seconds / SECONDS_PER_DAY, 0)} days)`;
76+
}
77+
if (seconds > SECONDS_PER_HOUR) {
78+
return `${raw} (~${roundNumber(seconds / SECONDS_PER_HOUR, 0)} hours)`;
79+
}
80+
if (seconds > SECONDS_PER_MINUTE) {
81+
return `${raw} (~${roundNumber(seconds / SECONDS_PER_MINUTE, 0)} minutes)`;
82+
}
83+
return raw;
84+
}
85+
6886
export function formatDateLocalized(date: Date): string {
6987
return `${date.toUTCString()}</br>(local time: ${date.toLocaleString()})`;
7088
}

src/ts/waterfall/details-overlay/extract-details-keys.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {getHeader} from "../../helpers/har";
22
import {
3-
formatBytes, formatDateLocalized, formatMilliseconds, parseAndFormat, parseDate, parseNonEmpty,
3+
formatBytes, formatDateLocalized, formatMilliseconds, formatSeconds, parseAndFormat, parseDate, parseNonEmpty,
44
parseNonNegative, parsePositive,
55
} from "../../helpers/parse";
66
import {Entry, Header} from "../../typing/har";
@@ -31,7 +31,7 @@ function parseGeneralDetails(entry: WaterfallEntry, requestID: number): KvTuple[
3131
["IP", harEntry._ip_addr],
3232
["Client Port", parseAndFormat(harEntry._client_port, parsePositive)],
3333
["Expires", harEntry._expires],
34-
["Cache Time", parseAndFormat(harEntry._cache_time, parsePositive)],
34+
["Cache Time", parseAndFormat(harEntry._cache_time, parsePositive, formatSeconds)],
3535
["CDN Provider", harEntry._cdn_provider],
3636
byteSizeProperty("ObjectSize", harEntry._objectSize),
3737
byteSizeProperty("Bytes In (downloaded)", harEntry._bytesIn),
@@ -113,7 +113,7 @@ function parseResponseDetails(harEntry: Entry): KvTuple[] {
113113
stringHeader("Connection"),
114114
stringHeader("ETag"),
115115
stringHeader("Accept-Patch"),
116-
stringHeader("Age"),
116+
["Age", parseAndFormat(getHeader(headers, "Age"), parseNonNegative, formatSeconds)],
117117
stringHeader("Allow"),
118118
stringHeader("Content-Disposition"),
119119
stringHeader("Location"),

0 commit comments

Comments
 (0)