Skip to content

Commit

Permalink
fix : remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
prigal committed Jun 11, 2024
1 parent 9e6c124 commit cf9d7ee
Showing 1 changed file with 0 additions and 64 deletions.
64 changes: 0 additions & 64 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,70 +124,6 @@ const formatDate = (date: Date, locale:string): string => {
return formattedDate
}


function convertUTCDateToTimezone(utcDate: Date, timezoneId: string): Date {
// Check if the date is in UTC format by examining its string representation
const utcDateString = utcDate.toISOString();
if (!utcDateString.endsWith('Z') && !utcDateString.includes('+00:00') && !utcDateString.includes('-00:00')) {
// The date is not in UTC format, return the input date unchanged
console.error('\x1b[31m'," - The provided date is not in UTC format, return the provided date", '\x1b[0m')
return utcDate;
}

// Get the UTC time parts from the Date object
const utcYear = utcDate.getUTCFullYear();
const utcMonth = utcDate.getUTCMonth();
const utcDay = utcDate.getUTCDate();
const utcHour = utcDate.getUTCHours();
const utcMinute = utcDate.getUTCMinutes();
const utcSecond = utcDate.getUTCSeconds();
const utcMillisecond = utcDate.getUTCMilliseconds();

// Construct an ISO string for the UTC date
const isoDateString = new Date(Date.UTC(
utcYear,
utcMonth,
utcDay,
utcHour,
utcMinute,
utcSecond,
utcMillisecond
)).toISOString();

// Use Intl.DateTimeFormat to format the UTC date to the target timezone
const options = {
timeZone: timezoneId,
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
fractionalSecondDigits: 3, // Include milliseconds
hour12: false
};
const formatter = new Intl.DateTimeFormat('en-US', options);
const parts = formatter.formatToParts(new Date(isoDateString));

// Extract the relevant parts from the formatted date
const year = parseInt(parts.find(part => part.type === 'year')?.value || '0', 10);
const month = parseInt(parts.find(part => part.type === 'month')?.value || '0', 10) - 1; // JavaScript months are 0-based
const day = parseInt(parts.find(part => part.type === 'day')?.value || '0', 10);
const hour = parseInt(parts.find(part => part.type === 'hour')?.value || '0', 10);
const minute = parseInt(parts.find(part => part.type === 'minute')?.value || '0', 10);
const second = parseInt(parts.find(part => part.type === 'second')?.value || '0', 10);
const millisecond = parseInt(parts.find(part => part.type === 'fractionalSecond')?.value || '0', 10);

// Create a new Date object in the target timezone
const targetDate = new Date(year, month, day, hour, minute, second, millisecond);

// Adjust for the timezone offset manually because JavaScript Date uses local time by default
const offsetInMinutes = targetDate.getTimezoneOffset();
const adjustedTime = targetDate.getTime() - offsetInMinutes * 60000;

return new Date(adjustedTime);
}

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

const getProgress = async (downloadPath: string): Promise<string> => {
Expand Down

0 comments on commit cf9d7ee

Please sign in to comment.