src/vs/workbench/contrib/update/common/updateUtils.ts

227 LOC · 208 covered · 19 uncovered · 63 ranges · 46 concepts · 42 introducers · 36 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/update/common/update.ts · 127 LOCcommon/update.tsupdateUtils.test|title=UpdateUtils formatBytes rounds to one decimal place correctly|occurrence=1 · 0 introduced LOCupdateUtils.test|title=U…updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 4 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 7 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 1 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 1 introduced LOCupdateUtils.ts ×1updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for unparseable versions|occurrence=1 · 0 introduced LOCupdateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when new version is undefined|occurrence=1, updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when previous version is undefined|occurrence=1 · 0 introduced LOCupdateUtils.test|title=U…updateUtils.ts ×2 · 4 introduced LOCupdateUtils.ts ×2updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for patch-only change|occurrence=1, updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for identical versions|occurrence=1, +2 · 0 introduced LOCupdateUtils.test|title=U…updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×2 · 7 introduced LOCupdateUtils.ts ×2updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×2 · 4 introduced LOCupdateUtils.ts ×2updateUtils.ts ×2 · 11 introduced LOCupdateUtils.ts ×2updateUtils.ts ×1 · 4 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×3 · 4 introduced LOCupdateUtils.ts ×3updateUtils.ts ×1 · 2 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×2 · 5 introduced LOCupdateUtils.ts ×2updateUtils.ts ×2 · 3 introduced LOCupdateUtils.ts ×2updateUtils.ts ×2 · 2 introduced LOCupdateUtils.ts ×2updateUtils.ts ×1 · 1 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 6 introduced LOCupdateUtils.ts ×1updateUtils.ts ×1 · 3 introduced LOCupdateUtils.ts ×1updateUtils.ts ×13 · 208 introduced LOCupdateUtils.ts ×13updateUtils.test|title=UpdateUtils computeDownloadSpeed computes correct download speed in bytes per second|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadSpeed computes correct download speed in bytes per second|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeDownloadSpeed returns undefined for invalid or incomplete input|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadSpeed returns undefined for invalid or incomplete input|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeDownloadSpeed returns undefined for zero downloaded bytes|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadSpeed returns undefined for zero downloaded bytes|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeDownloadSpeed returns undefined for zero or negative elapsed time|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadSpeed returns undefined for zero or negative elapsed time|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeDownloadTimeRemaining computes correct time remaining|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadTimeRemaining computes correct time remaining|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeDownloadTimeRemaining returns 0 when download is complete or over-downloaded|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadTimeRemaining returns 0 when download is complete or over-downloaded|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeDownloadTimeRemaining returns undefined for invalid or incomplete input|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeDownloadTimeRemaining returns undefined for invalid or incomplete input|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeProgressPercent clamps to 0-100 range|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeProgressPercent clamps to 0-100 range|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeProgressPercent computes correct percentage|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeProgressPercent computes correct percentage|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeProgressPercent handles invalid values|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeProgressPercent handles invalid values|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns minor .0 version when major differs|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns minor .0 version when major differs|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns minor .0 version when minor differs|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns minor .0 version when minor differs|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns target version as-is when same minor|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns target version as-is when same minor|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns undefined for invalid versions|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils computeUpdateInfoVersion returns undefined for invalid versions|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatBytes formats bytes for values less than 1 KB|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatBytes formats bytes for values less than 1 KB|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatBytes formats gigabytes for values >= 1 GB|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatBytes formats gigabytes for values >= 1 GB|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatBytes formats kilobytes for values between 1 KB and 1 MB|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatBytes formats kilobytes for values between 1 KB and 1 MB|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatBytes formats megabytes for values between 1 MB and 1 GB|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatBytes formats megabytes for values between 1 MB and 1 GB|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatBytes rounds to one decimal place correctly|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatBytes rounds to one decimal place correctly|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatDate formats a timestamp as a readable date|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatDate formats a timestamp as a readable date|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatTimeRemaining formats fractional hours for values >= 1 hour|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatTimeRemaining formats fractional hours for values >= 1 hour|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatTimeRemaining formats minutes for values between 1 minute and 1 hour|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatTimeRemaining formats minutes for values between 1 minute and 1 hour|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils formatTimeRemaining formats seconds for values less than 1 minute|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils formatTimeRemaining formats seconds for values less than 1 minute|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils getUpdateInfoUrl constructs correct URL for .0 versions|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils getUpdateInfoUrl constructs correct URL for .0 versions|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils getUpdateInfoUrl constructs correct URL for patch versions|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils getUpdateInfoUrl constructs correct URL for patch versions|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for identical versions|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for identical versions|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for patch-only change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for patch-only change|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for unparseable versions|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false for unparseable versions|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when both versions are undefined|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when both versions are undefined|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when new version is undefined|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when new version is undefined|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when previous version is undefined|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns false when previous version is undefined|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns true for major version change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns true for major version change|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns true for minor version change|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils isMajorMinorVersionChange returns true for minor version change|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils tryParseDate parses valid ISO date strings|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils tryParseDate parses valid ISO date strings|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils tryParseDate returns undefined for invalid date strings|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils tryParseDate returns undefined for invalid date strings|occurrence=1updateUtils.test|title=U…updateUtils.test|title=UpdateUtils tryParseDate returns undefined for undefined input|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/update/test/common/updateUtils.test|title=UpdateUtils tryParseDate returns undefined for undefined input|occurrence=1updateUtils.test|title=U…Focused file · src/vs/workbench/contrib/update/common/updateUtils.ts · 227 LOCcommon/updateUtils.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- updateUtils.ts ×13
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { localize } from '../../../../nls.js';
7 > import { Downloading } from '../../../../platform/update/common/update.js';
8 >
9 > /**
10 > * Returns the progress percentage based on the current and maximum progress values.
11 > */
12 > export function computeProgressPercent(current: number | undefined, max: number | undefined): number | undefined {
13 > if (current === undefined || max === undefined || max <= 0) { updateUtils.ts ×1
14 > return undefined; updateUtils.ts ×1
15 > }
17 > return Math.max(Math.min(Math.round((current / max) * 100), 100), 0);
18 > }
20 > /**
21 > * Computes an estimate of remaining download time in seconds.
22 > */
23 > export function computeDownloadTimeRemaining(state: Downloading): number | undefined {
24 > const { downloadedBytes, totalBytes, startTime } = state; updateUtils.ts ×2
25 > if (downloadedBytes === undefined || totalBytes === undefined || startTime === undefined) {
26 > return undefined; updateUtils.ts ×2
27 > }
29 > const elapsedMs = Date.now() - startTime;
30 > if (downloadedBytes <= 0 || totalBytes <= 0 || elapsedMs <= 0) {
31 > return undefined; updateUtils.ts ×2
32 > }
34 > const remainingBytes = totalBytes - downloadedBytes;
35 > if (remainingBytes <= 0) {
36 > return 0; updateUtils.ts ×1
37 > }
39 > const bytesPerMs = downloadedBytes / elapsedMs;
40 > if (bytesPerMs <= 0) {
41 return undefined;
42 }
44 > const remainingMs = remainingBytes / bytesPerMs;
45 > return Math.ceil(remainingMs / 1000);
46 > }
48 > /**
49 > * Computes the current download speed in bytes per second.
50 > */
51 > export function computeDownloadSpeed(state: Downloading): number | undefined {
52 > const { downloadedBytes, startTime } = state; updateUtils.ts ×2
53 > if (downloadedBytes === undefined || startTime === undefined) {
54 > return undefined; updateUtils.ts ×1
55 > }
57 > const elapsedMs = Date.now() - startTime;
58 > if (elapsedMs <= 0 || downloadedBytes <= 0) { updateUtils.ts ×2
59 > return undefined; updateUtils.ts ×1
60 > }
62 > return (downloadedBytes / elapsedMs) * 1000;
63 > }
65 > /**
66 > * Computes the version to use for fetching update info.
67 > * - If the minor version differs: returns `{major}.{minor}` (e.g., 1.108.2 -> 1.109.5 => 1.109)
68 > * - If the same minor: returns the target version as-is (e.g., 1.109.2 -> 1.109.5 => 1.109.5)
69 > */
70 > export function computeUpdateInfoVersion(currentVersion: string, targetVersion: string): string | undefined {
71 > const current = tryParseVersion(currentVersion); updateUtils.ts ×2
72 > const target = tryParseVersion(targetVersion);
73 > if (!current || !target) {
74 > return undefined; updateUtils.ts ×1
75 > }
77 > if (current.minor !== target.minor || current.major !== target.major) { updateUtils.ts ×2
78 > return `${target.major}.${target.minor}`; updateUtils.ts ×1
79 > }
81 > return `${target.major}.${target.minor}.${target.patch}`;
82 > }
84 > /**
85 > * Computes the URL to fetch update info from.
86 > * Follows the release notes URL pattern but with `_update` suffix.
87 > */
88 > export function getUpdateInfoUrl(version: string): string {
89 > const versionLabel = version.replace(/\./g, '_').replace(/_0$/, ''); updateUtils.ts ×1
90 > return `https://code.visualstudio.com/raw/v${versionLabel}_update.md`;
91 > }
93 > /**
94 > * Formats the time remaining as a human-readable string.
95 > */
96 > export function formatTimeRemaining(seconds: number): string {
97 > const hours = seconds / 3600; updateUtils.ts ×1
98 > if (hours >= 1) {
99 > const formattedHours = formatDecimal(hours); updateUtils.ts ×1
100 > if (formattedHours === '1') {
101 > return localize('update.timeRemainingHour', "{0} hour", formattedHours);
102 > } else {
103 > return localize('update.timeRemainingHours', "{0} hours", formattedHours);
104 > }
105 > }
107 > const minutes = Math.floor(seconds / 60);
108 > if (minutes >= 1) {
109 > return localize('update.timeRemainingMinutes', "{0} min", minutes); updateUtils.ts ×1
110 > }
112 > return localize('update.timeRemainingSeconds', "{0}s", seconds);
113 > }
115 > /**
116 > * Formats a byte count as a human-readable string.
117 > */
118 > export function formatBytes(bytes: number): string {
119 > if (bytes < 1024) { updateUtils.ts ×1
120 > return localize('update.bytes', "{0} B", bytes); updateUtils.ts ×1
121 > }
123 > const kb = bytes / 1024;
124 > if (kb < 1024) {
125 > return localize('update.kilobytes', "{0} KB", formatDecimal(kb)); updateUtils.ts ×1
126 > }
128 > const mb = kb / 1024;
129 > if (mb < 1024) {
130 > return localize('update.megabytes', "{0} MB", formatDecimal(mb)); updateUtils.ts ×1
131 > }
133 > const gb = mb / 1024;
134 > return localize('update.gigabytes', "{0} GB", formatDecimal(gb));
135 > }
137 > /**
138 > * Tries to parse a date string and returns the timestamp or undefined if parsing fails.
139 > */
140 > export function tryParseDate(date: string | undefined): number | undefined {
141 > if (date === undefined) { updateUtils.ts ×3
142 > return undefined; updateUtils.ts ×1
143 > }
145 > try {
146 > const parsed = Date.parse(date);
147 > return isNaN(parsed) ? undefined : parsed; updateUtils.ts ×3
148 > } catch {
149 return undefined;
150 }
153 > /**
154 > * Formats a timestamp as a localized date string.
155 > */
156 > export function formatDate(timestamp: number): string {
157 > return new Date(timestamp).toLocaleDateString(undefined, { updateUtils.ts ×1
158 > year: 'numeric',
159 > month: 'short',
160 > day: 'numeric'
161 > });
162 > }
164 > /**
165 > * Formats a number to 1 decimal place, omitting ".0" for whole numbers.
166 > */
167 > export function formatDecimal(value: number): string {
168 > const rounded = Math.round(value * 10) / 10; updateUtils.ts ×1
169 > return rounded % 1 === 0 ? rounded.toString() : rounded.toFixed(1);
170 > }
172 > export interface IVersion {
173 > major: number;
174 > minor: number;
175 > patch: number;
176 > }
177 >
178 > /**
179 > * Parses a version string in the format "major.minor.patch" and returns an object with the components.
180 > */
181 > export function tryParseVersion(version: string | undefined): IVersion | undefined {
182 > if (version === undefined) { updateUtils.ts ×2
183 > return undefined; updateUtils.ts ×1
184 > }
186 > const match = /^(\d{1,10})\.(\d{1,10})\.(\d{1,10})/.exec(version);
187 > if (!match) {
188 > return undefined; updateUtils.ts ×1
189 > }
191 > try {
192 > return {
193 > major: parseInt(match[1]),
194 > minor: parseInt(match[2]),
195 > patch: parseInt(match[3])
196 > };
197 > } catch {
198 return undefined;
199 }
202 > /**
203 > * Processes an error message and returns a user-friendly version of it, or undefined if the error should be ignored.
204 > */
205 > export function preprocessError(error?: string): string | undefined {
206 if (!error) {
207 return undefined;
208 }
209
210 if (/The request timed out|The network connection was lost/i.test(error)) {
211 return undefined;
212 }
213
214 return error.replace(
215 /See https:\/\/github\.com\/Squirrel\/Squirrel\.Mac\/issues\/182 for more information/,
216 'This might mean the application was put on quarantine by macOS. See [this link](https://github.com/microsoft/vscode/issues/7426#issuecomment-425093469) for more information'
217 );
218 }
220 > /**
221 > * Determines whether there is a major or minor version change between two versions.
222 > */
223 > export function isMajorMinorVersionChange(previousVersion?: string, newVersion?: string): boolean {
224 > const previous = tryParseVersion(previousVersion); updateUtils.ts ×1
225 > const current = tryParseVersion(newVersion);
226 > return !!previous && !!current && (previous.major !== current.major || previous.minor !== current.minor);
227 > }