Skip to content

Commit

Permalink
fix: 🐛 fixed issue with date and time formatting (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB authored Sep 29, 2024
1 parent 55c676b commit a0d6a82
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@ export const formatDuration = (duration: number): string => {
};

export const formatTime = (dateTime: string): string => {
const cleanedDateString = dateTime.replace('AST', 'UTC');
const parsedDate = parse(
cleanedDateString,
/* eslint-disable @stylistic/ts/quotes */
"yyyy-MM-dd'T'HH:mm:ss 'UTC'",
new Date()
);
return format(parsedDate, 'hh:mm:ss bb');
const TIME_FORMAT = 'hh:mm:ss bb';
if (dateTime.endsWith('AST')) {
const cleanedDateString = dateTime.replace('AST', 'UTC');
const parsedDate = parse(
cleanedDateString,
/* eslint-disable @stylistic/ts/quotes */
"yyyy-MM-dd'T'HH:mm:ss 'UTC'",
new Date()
);
return format(parsedDate, TIME_FORMAT);
}
return format(dateTime, TIME_FORMAT);
};

export const formatDate = (dateTime: string): string => {
const cleanedDateString = dateTime.replace('AST', 'UTC');
const parsedDate = parse(
cleanedDateString,
/* eslint-disable @stylistic/ts/quotes */
"yyyy-MM-dd'T'HH:mm:ss 'UTC'",
new Date()
);
return format(parsedDate, 'dd-MMM-yyyy');
const DATE_FORMAT = 'dd-MMM-yyyy';
if (dateTime.endsWith('AST')) {
const cleanedDateString = dateTime.replace('AST', 'UTC');
const parsedDate = parse(
cleanedDateString,
/* eslint-disable @stylistic/ts/quotes */
"yyyy-MM-dd'T'HH:mm:ss 'UTC'",
new Date()
);
return format(parsedDate, DATE_FORMAT);
}
return format(dateTime, DATE_FORMAT);
};

export const round = (value: number): number => {
Expand Down

0 comments on commit a0d6a82

Please sign in to comment.