Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
abu-sufyan1 committed Jan 13, 2025
commit 9df3ab4a7414537a922fef48456d4ac37d457a10
10 changes: 7 additions & 3 deletions src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { LRU } from 'ylru';
const lru = new LRU(1000); // Cache up to 1000 entries

export function resetTimezone(date: Date) {
let TIMEZONE = '';
let TIMEZONE: string = '';
const offsetInMinutes = date.getTimezoneOffset();
const _hourOffset = Math.floor(-offsetInMinutes / 60);
const _minuteOffset = Math.abs(offsetInMinutes % 60);
const _hourOffset: number = Math.floor(-offsetInMinutes / 60);
const _minuteOffset: number = Math.abs(offsetInMinutes % 60);

TIMEZONE += _hourOffset >= 0 ? '+' : '-';
TIMEZONE += `${String(Math.abs(_hourOffset)).padStart(2, '0')}${String(_minuteOffset).padStart(2, '0')}`;
Expand Down Expand Up @@ -213,6 +213,10 @@ export enum DateFormat {
* Provide milliseconds, return a formatted string.
*/
export function getDateFromMilliseconds(milliseconds: number, format?: DateFormat): string {
if (!Number.isFinite(milliseconds)) {
throw new Error('Invalid milliseconds value');
}

switch (format) {
case DateFormat.DateTimeWithTimeZone:
return accessLogDate(new Date(milliseconds));
Expand Down
Loading