mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 17:22:29 -05:00
* Fixing Migration Cutover Dialog Adding support for target file share Fixing request body Correcting localized strings * Redesigned IR page Adding additional details in migration status dialog * vbump * Fixed the perpetual loading * Fixed duration logic * Adding icon for migration extension * Adding helper commenst to util function localizing some strings logging console errors * enabling cutover buttons for ignored files
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { DAYS, HRS, MINUTE, SEC } from '../constants/strings';
|
|
|
|
export function deepClone<T>(obj: T): T {
|
|
if (!obj || typeof obj !== 'object') {
|
|
return obj;
|
|
}
|
|
if (obj instanceof RegExp) {
|
|
// See https://github.com/Microsoft/TypeScript/issues/10990
|
|
return obj as any;
|
|
}
|
|
const result: any = Array.isArray(obj) ? [] : {};
|
|
Object.keys(<any>obj).forEach((key: string) => {
|
|
if ((<any>obj)[key] && typeof (<any>obj)[key] === 'object') {
|
|
result[key] = deepClone((<any>obj)[key]);
|
|
} else {
|
|
result[key] = (<any>obj)[key];
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export function getSqlServerName(majorVersion: number): string | undefined {
|
|
switch (majorVersion) {
|
|
case 10:
|
|
return 'SQL Server 2008';
|
|
case 11:
|
|
return 'SQL Server 2012';
|
|
case 12:
|
|
return 'SQL Server 2014';
|
|
case 13:
|
|
return 'SQL Server 2016';
|
|
case 14:
|
|
return 'SQL Server 2017';
|
|
case 15:
|
|
return 'SQL Server 2019';
|
|
default:
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generates a wordy time difference between start and end time.
|
|
* @returns stringified duration like '10.0 days', '12.0 hrs', '1.0 min'
|
|
*/
|
|
export function convertTimeDifferenceToDuration(startTime: Date, endTime: Date): string {
|
|
const time = endTime.getTime() - startTime.getTime();
|
|
let seconds = (time / 1000).toFixed(1);
|
|
let minutes = (time / (1000 * 60)).toFixed(1);
|
|
let hours = (time / (1000 * 60 * 60)).toFixed(1);
|
|
let days = (time / (1000 * 60 * 60 * 24)).toFixed(1);
|
|
if (time / 1000 < 60) {
|
|
return SEC(parseFloat(seconds));
|
|
}
|
|
else if (time / (1000 * 60) < 60) {
|
|
return MINUTE(parseFloat(minutes));
|
|
}
|
|
else if (time / (1000 * 60 * 60) < 24) {
|
|
return HRS(parseFloat(hours));
|
|
}
|
|
else {
|
|
return DAYS(parseFloat(days));
|
|
}
|
|
}
|