Skip to content

Commit b0fd3ca

Browse files
committed
Fix createdAt and expiresAt returning numbers instead of Date objects
setUTCMilliseconds() returns a numeric timestamp, not a Date object, causing type mismatches and crashes on Android. Replace with new Date() constructor which correctly creates Date objects from millisecond timestamps. Also removes the downstream typeof workaround in defaultDateMapper and the @ts-ignore suppression. Fixes #581 https://claude.ai/code/session_016EHrcqQDgexLB5xApCxrZj
1 parent e69c305 commit b0fd3ca

2 files changed

Lines changed: 3 additions & 23 deletions

File tree

src/inApp/classes/IterableInAppMessage.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,8 @@ export class IterableInAppMessage {
175175
const campaignId = dict.campaignId;
176176
const trigger = IterableInAppTrigger.fromDict(dict.trigger);
177177

178-
let createdAt = dict.createdAt;
179-
if (createdAt) {
180-
const dateObject = new Date(0);
181-
createdAt = dateObject.setUTCMilliseconds(createdAt);
182-
}
183-
let expiresAt = dict.expiresAt;
184-
if (expiresAt) {
185-
const dateObject = new Date(0);
186-
expiresAt = dateObject.setUTCMilliseconds(expiresAt);
187-
}
178+
const createdAt = dict.createdAt ? new Date(dict.createdAt) : undefined;
179+
const expiresAt = dict.expiresAt ? new Date(dict.expiresAt) : undefined;
188180
const saveToInbox = IterableUtil.readBoolean(dict, 'saveToInbox');
189181
const inboxMetadataDict = dict.inboxMetadata;
190182
let inboxMetadata: IterableInboxMetadata | undefined;
@@ -202,10 +194,6 @@ export class IterableInAppMessage {
202194
messageId,
203195
campaignId,
204196
trigger,
205-
// MOB-10426: Speak to the team about `IterableInAppMessage` requiring a date
206-
// object, but being passed a number in this case
207-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
208-
// @ts-ignore
209197
createdAt,
210198
expiresAt,
211199
saveToInbox,

src/inbox/classes/IterableInboxDataModel.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,7 @@ export class IterableInboxDataModel {
211211
return '';
212212
}
213213

214-
let createdAt;
215-
216-
if (typeof message.createdAt === 'string') {
217-
createdAt = new Date(parseInt(message.createdAt, 10));
218-
} else {
219-
createdAt = new Date(message.createdAt);
220-
}
221-
222-
const defaultDateString = `${createdAt.toLocaleDateString()} at ${createdAt.toLocaleTimeString()}`;
214+
const defaultDateString = `${message.createdAt.toLocaleDateString()} at ${message.createdAt.toLocaleTimeString()}`;
223215

224216
return defaultDateString;
225217
}

0 commit comments

Comments
 (0)