Skip to content

Commit 149e17f

Browse files
authored
refactor(metrics): swap isDate for instanceof Date (#3462)
1 parent 1d1e2f9 commit 149e17f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: packages/metrics/src/Metrics.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Console } from 'node:console';
2-
import { isDate } from 'node:util/types';
32
import { Utility, isIntegerNumber } from '@aws-lambda-powertools/commons';
43
import type {
54
GenericLogger,
@@ -1033,11 +1032,12 @@ class Metrics extends Utility implements MetricsInterface {
10331032
* @param timestamp - Date object or epoch time in milliseconds representing the timestamp to validate.
10341033
*/
10351034
#validateEmfTimestamp(timestamp: number | Date): boolean {
1036-
if (!isDate(timestamp) && !isIntegerNumber(timestamp)) {
1035+
const isDate = timestamp instanceof Date;
1036+
if (!isDate && !isIntegerNumber(timestamp)) {
10371037
return false;
10381038
}
10391039

1040-
const timestampMs = isDate(timestamp) ? timestamp.getTime() : timestamp;
1040+
const timestampMs = isDate ? timestamp.getTime() : timestamp;
10411041
const currentTime = new Date().getTime();
10421042

10431043
const minValidTimestamp = currentTime - EMF_MAX_TIMESTAMP_PAST_AGE;
@@ -1056,7 +1056,7 @@ class Metrics extends Utility implements MetricsInterface {
10561056
if (isIntegerNumber(timestamp)) {
10571057
return timestamp;
10581058
}
1059-
if (isDate(timestamp)) {
1059+
if (timestamp instanceof Date) {
10601060
return timestamp.getTime();
10611061
}
10621062
/**

0 commit comments

Comments
 (0)