@@ -100,26 +100,19 @@ export type ScheduleBackgroundEventParameters = InferMatching<
100100> ;
101101
102102/**
103- * Generates an ISO 8601 date based on if a duration or date is provided.
103+ * Generates a `DateTime` object based on if a duration or date is provided.
104104 *
105105 * @param params - The validated params from the `snap_scheduleBackgroundEvent` call.
106- * @returns An ISO 8601 date string .
106+ * @returns A `DateTime` object .
107107 */
108- function getTruncatedDate ( params : ScheduleBackgroundEventParams ) {
109- let date ;
110-
108+ function getStartDate ( params : ScheduleBackgroundEventParams ) {
111109 if ( 'duration' in params ) {
112- date = DateTime . fromJSDate ( new Date ( ) )
110+ return DateTime . fromJSDate ( new Date ( ) )
113111 . toUTC ( )
114112 . plus ( Duration . fromISO ( params . duration ) ) ;
115- } else {
116- date = DateTime . fromISO ( params . date , { setZone : true } ) ;
117113 }
118114
119- // Make sure any millisecond precision is removed.
120- return date . startOf ( 'second' ) . toISO ( {
121- suppressMilliseconds : true ,
122- } ) ;
115+ return DateTime . fromISO ( params . date , { setZone : true } ) ;
123116}
124117
125118/**
@@ -156,11 +149,16 @@ async function getScheduleBackgroundEventImplementation(
156149
157150 const { request } = validatedParams ;
158151
159- const date = getTruncatedDate ( validatedParams ) ;
152+ const date = getStartDate ( validatedParams ) ;
153+
154+ // Make sure any millisecond precision is removed.
155+ const truncatedDate = date . startOf ( 'second' ) . toISO ( {
156+ suppressMilliseconds : true ,
157+ } ) ;
160158
161- assert ( date ) ;
159+ assert ( truncatedDate ) ;
162160
163- const id = scheduleBackgroundEvent ( { date, request } ) ;
161+ const id = scheduleBackgroundEvent ( { date : truncatedDate , request } ) ;
164162 res . result = id ;
165163 } catch ( error ) {
166164 return end ( error ) ;
0 commit comments