From 4807169b0ca3d7f068962d7ad143907bbcb313c4 Mon Sep 17 00:00:00 2001 From: Sunil Kumar Yadav <79906609+sunilyadav840@users.noreply.github.com> Date: Tue, 9 Mar 2021 04:50:45 +0530 Subject: [PATCH] Eslint/fix lint date time utility (#471) * fixed lint issue of DateTimeUtility * remove commented code * Do change request. --- .eslintignore | 2 -- .../Tables/QueryBuilder/DateTimeUtilities.ts | 32 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.eslintignore b/.eslintignore index 1e9d595b2..2d350472c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -176,8 +176,6 @@ src/Explorer/Tables/Entities.ts src/Explorer/Tables/QueryBuilder/ClauseGroup.ts src/Explorer/Tables/QueryBuilder/ClauseGroupViewModel.ts src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts -src/Explorer/Tables/QueryBuilder/DateTimeUtilities.test.ts -src/Explorer/Tables/QueryBuilder/DateTimeUtilities.ts src/Explorer/Tables/QueryBuilder/QueryBuilderViewModel.ts src/Explorer/Tables/QueryBuilder/QueryClauseViewModel.ts src/Explorer/Tables/QueryBuilder/QueryViewModel.ts diff --git a/src/Explorer/Tables/QueryBuilder/DateTimeUtilities.ts b/src/Explorer/Tables/QueryBuilder/DateTimeUtilities.ts index 810757f60..86bcc6a1e 100644 --- a/src/Explorer/Tables/QueryBuilder/DateTimeUtilities.ts +++ b/src/Explorer/Tables/QueryBuilder/DateTimeUtilities.ts @@ -2,26 +2,26 @@ const epochTicks = 621355968000000000; const ticksPerMillisecond = 10000; export function getLocalDateTime(dateTime: string): string { - var dateTimeObject: Date = new Date(dateTime); - var year: number = dateTimeObject.getFullYear(); - var month: string = ensureDoubleDigits(dateTimeObject.getMonth() + 1); // Month ranges from 0 to 11 - var day: string = ensureDoubleDigits(dateTimeObject.getDate()); - var hours: string = ensureDoubleDigits(dateTimeObject.getHours()); - var minutes: string = ensureDoubleDigits(dateTimeObject.getMinutes()); - var seconds: string = ensureDoubleDigits(dateTimeObject.getSeconds()); - var milliseconds: string = ensureTripleDigits(dateTimeObject.getMilliseconds()); + const dateTimeObject: Date = new Date(dateTime); + const year: number = dateTimeObject.getFullYear(); + const month: string = ensureDoubleDigits(dateTimeObject.getMonth() + 1); // Month ranges from 0 to 11 + const day: string = ensureDoubleDigits(dateTimeObject.getDate()); + const hours: string = ensureDoubleDigits(dateTimeObject.getHours()); + const minutes: string = ensureDoubleDigits(dateTimeObject.getMinutes()); + const seconds: string = ensureDoubleDigits(dateTimeObject.getSeconds()); + const milliseconds: string = ensureTripleDigits(dateTimeObject.getMilliseconds()); - var localDateTime: string = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`; + const localDateTime = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`; return localDateTime; } export function getUTCDateTime(dateTime: string): string { - var dateTimeObject: Date = new Date(dateTime); + const dateTimeObject = new Date(dateTime); return dateTimeObject.toISOString(); } export function ensureDoubleDigits(num: number): string { - var doubleDigitsString: string = num.toString(); + let doubleDigitsString: string = num.toString(); if (num < 10) { doubleDigitsString = `0${doubleDigitsString}`; } else if (num > 99) { @@ -31,7 +31,7 @@ export function ensureDoubleDigits(num: number): string { } export function ensureTripleDigits(num: number): string { - var tripleDigitsString: string = num.toString(); + let tripleDigitsString: string = num.toString(); if (num < 10) { tripleDigitsString = `00${tripleDigitsString}`; } else if (num < 100) { @@ -51,17 +51,17 @@ export function convertJSDateToUnix(dateTime: string): number { } export function convertTicksToJSDate(ticks: string): Date { - var ticksJSBased = Number(ticks) - epochTicks; - var timeInMillisecond = ticksJSBased / ticksPerMillisecond; + const ticksJSBased = Number(ticks) - epochTicks; + const timeInMillisecond = ticksJSBased / ticksPerMillisecond; return new Date(timeInMillisecond); } export function convertJSDateToTicksWithPadding(dateTime: string): string { - var ticks = epochTicks + new Date(dateTime).getTime() * ticksPerMillisecond; + const ticks = epochTicks + new Date(dateTime).getTime() * ticksPerMillisecond; return padDateTicksWithZeros(ticks.toString()); } function padDateTicksWithZeros(value: string): string { - var s = "0000000000000000000" + value; + const s = "0000000000000000000" + value; return s.substr(s.length - 20); }