Skip to content

Commit

Permalink
Support strings for kernel activity dates (#14335)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Sep 18, 2023
1 parent a7a1fab commit e3cbadc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/kernels/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,18 @@ export function getRemoteKernelSessionInformation(
defaultValue: string = ''
): string {
if (kernelConnection?.kind === 'connectToLiveRemoteKernel') {
let date: Date | undefined;
if (typeof kernelConnection.kernelModel.lastActivityTime === 'string') {
try {
date = new Date(kernelConnection.kernelModel.lastActivityTime);
} catch (ex) {
traceVerbose(`Error parsing date ${ex}`);
}
} else {
date = kernelConnection.kernelModel.lastActivityTime;
}
return DataScience.jupyterSelectLiveRemoteKernelDescription(
kernelConnection.kernelModel.lastActivityTime,
date,
kernelConnection.kernelModel.numberOfConnections
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernels/jupyter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface IJupyterKernel {
*/
id?: string;
name: string;
lastActivityTime: Date;
lastActivityTime: Date | string;
numberOfConnections: number;
}

Expand Down
11 changes: 10 additions & 1 deletion src/platform/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,16 @@ export namespace DataScience {
export const jupyterSelectURIMustBeHttpOrHttps = l10n.t(
'Invalid protocol in URL specified, only HTTP or HTTPS are supported.'
);
export const jupyterSelectLiveRemoteKernelDescription = (time: Date, numberOfConnections: number) => {
export const jupyterSelectLiveRemoteKernelDescription = (time: Date | undefined, numberOfConnections: number) => {
if (!time) {
if (numberOfConnections === 0) {
return '';
}
if (numberOfConnections === 1) {
return l10n.t('1 connection');
}
return l10n.t('{1} connections', numberOfConnections.toString());
}
if (numberOfConnections === 0) {
return l10n.t('Last activity {0}', fromNow(time, true, false, false));
}
Expand Down
1 change: 0 additions & 1 deletion src/test/mocks/vsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ export namespace vscMock {
public static readonly SourceFixAll: CodeActionKind = new CodeActionKind('source.fix.all');
public static readonly RefactorMove: CodeActionKind = new CodeActionKind('refactor.move');
static readonly Notebook: CodeActionKind;

private constructor(private _value: string) {}

public append(parts: string): CodeActionKind {
Expand Down

0 comments on commit e3cbadc

Please sign in to comment.