@@ -3,9 +3,8 @@ import type {
33 APIGatewayEventRequestContextV2 ,
44 APIGatewayEventRequestContextWithAuthorizer ,
55} from 'aws-lambda' ;
6- import { DateTime } from 'luxon' ;
76import type { Merge } from 'type-fest' ;
8- import { deepMerge , randomIpAddress } from '../utils' ;
7+ import { currentEpochTime , deepMerge , randomIpAddress } from '../utils' ;
98import { DEFAULT_ACCOUNT_ID , DEFAULT_REGION } from './consts' ;
109
1110export type PartialAPIGatewayEventRequestContext < TAuthorizer > = Merge <
@@ -16,6 +15,26 @@ export type PartialAPIGatewayEventRequestContext<TAuthorizer> = Merge<
1615 }
1716> ;
1817
18+ export const eventParsedDateTime = ( date : Date ) : string => {
19+ const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' ) ;
20+ const month = date . toLocaleString ( 'en-US' , { month : 'short' } ) ;
21+ const year = date . getFullYear ( ) ;
22+ const hour = String ( date . getHours ( ) ) ;
23+ const minute = String ( date . getMinutes ( ) ) ;
24+ const second = String ( date . getSeconds ( ) ) ;
25+
26+ const offset = - date . getTimezoneOffset ( ) ; // Reverse the sign
27+
28+ const sign = offset >= 0 ? '+' : '-' ;
29+ const absOffset = Math . abs ( offset ) ;
30+ const hours = String ( Math . floor ( absOffset / 60 ) ) . padStart ( 2 , '0' ) ;
31+ const minutes = String ( absOffset % 60 ) . padStart ( 2 , '0' ) ;
32+
33+ const formattedTz = `${ sign } ${ hours } ${ minutes } ` ;
34+
35+ return `${ day } /${ month } /${ year } :${ hour } :${ minute } :${ second } ${ formattedTz } ` ;
36+ } ;
37+
1938export const APIGatewayEventRequestContextWithAuthorizerStub = < TAuthorizer > (
2039 overrides : PartialAPIGatewayEventRequestContext < TAuthorizer > = {
2140 authorizer : undefined ,
@@ -31,7 +50,7 @@ export const APIGatewayEventRequestContextWithAuthorizerStub = <TAuthorizer>(
3150 path : '/prod/resource' ,
3251 stage : 'prod' ,
3352 requestId : crypto . randomUUID ( ) ,
34- requestTimeEpoch : DateTime . now ( ) . toUnixInteger ( ) ,
53+ requestTimeEpoch : currentEpochTime ( ) ,
3554 resourceId : 'resource-id' ,
3655 resourcePath : '/resource' ,
3756 authorizer : undefined as TAuthorizer , // Will be overridden by deepMerge
@@ -54,7 +73,6 @@ export type PartialAPIGatewayEventRequestContextV2 = Merge<
5473export const APIGatewayEventRequestContextV2Stub = (
5574 overrides : PartialAPIGatewayEventRequestContextV2 = { }
5675) : APIGatewayEventRequestContextV2 => {
57- const dateTime = DateTime . now ( ) ;
5876
5977 return deepMerge (
6078 {
@@ -72,8 +90,8 @@ export const APIGatewayEventRequestContextV2Stub = (
7290 requestId : crypto . randomUUID ( ) ,
7391 routeKey : '$default' ,
7492 stage : 'prod' ,
75- time : dateTime . toFormat ( 'dd/MMM/yyyy:HH:mm:ss ZZZ' ) ,
76- timeEpoch : dateTime . toUnixInteger ( ) ,
93+ time : eventParsedDateTime ( new Date ( ) ) ,
94+ timeEpoch : currentEpochTime ( ) ,
7795 } ,
7896 overrides as Partial < APIGatewayEventRequestContextV2 >
7997 ) ;
@@ -92,7 +110,7 @@ export const APIGatewayEventRequestContextV2WithAuthorizerStub = <TAuthorizer>(
92110 > (
93111 {
94112 ...APIGatewayEventRequestContextV2Stub ( overrides ) ,
95- authorizer : undefined as TAuthorizer , // will be overwrtitten by deepMerge
113+ authorizer : undefined as TAuthorizer , // will be overwritten by deepMerge
96114 } ,
97115 { authorizer }
98116 ) ;
0 commit comments