Skip to content

Commit

Permalink
refactor(metrics): swap isDate for instanceof Date (#3462)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi authored Jan 8, 2025
1 parent 1d1e2f9 commit 149e17f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Console } from 'node:console';
import { isDate } from 'node:util/types';
import { Utility, isIntegerNumber } from '@aws-lambda-powertools/commons';
import type {
GenericLogger,
Expand Down Expand Up @@ -1033,11 +1032,12 @@ class Metrics extends Utility implements MetricsInterface {
* @param timestamp - Date object or epoch time in milliseconds representing the timestamp to validate.
*/
#validateEmfTimestamp(timestamp: number | Date): boolean {
if (!isDate(timestamp) && !isIntegerNumber(timestamp)) {
const isDate = timestamp instanceof Date;
if (!isDate && !isIntegerNumber(timestamp)) {
return false;
}

const timestampMs = isDate(timestamp) ? timestamp.getTime() : timestamp;
const timestampMs = isDate ? timestamp.getTime() : timestamp;
const currentTime = new Date().getTime();

const minValidTimestamp = currentTime - EMF_MAX_TIMESTAMP_PAST_AGE;
Expand All @@ -1056,7 +1056,7 @@ class Metrics extends Utility implements MetricsInterface {
if (isIntegerNumber(timestamp)) {
return timestamp;
}
if (isDate(timestamp)) {
if (timestamp instanceof Date) {
return timestamp.getTime();
}
/**
Expand Down

0 comments on commit 149e17f

Please sign in to comment.