Skip to content

Commit 10b0baa

Browse files
authored
fix(search): widen Slack day modifiers so a member's time zone never empties a date window (#10145)
1 parent b61441b commit 10b0baa

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

‎apps/sim/lib/sim-search/live/dates.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('generic live search dates', () => {
134134
const result = await searchSlack(api, input)
135135
expect(api.json).toHaveBeenCalledTimes(1)
136136
expect(api.json.mock.calls[0]?.[1].body).toMatchObject({
137-
modifiers: 'after:2026-09-21 before:2026-09-24',
137+
modifiers: 'after:2026-09-20 before:2026-09-25',
138138
after: Date.parse(filters.startDate) / 1000 - 1,
139139
before: Date.parse(filters.endDate) / 1000,
140140
sort: 'timestamp',
@@ -166,3 +166,29 @@ describe('generic live search dates', () => {
166166
expect(api.json).toHaveBeenCalledTimes(3)
167167
})
168168
})
169+
170+
describe('Slack date windows', () => {
171+
const DAY = 86_400_000
172+
const HOUR = 3_600_000
173+
/** Slack reads `after:`/`before:` days in the member's zone, which may be UTC-12 to UTC+14. */
174+
const firstIncludedInstant = (afterDay: string) => Date.parse(afterDay) + DAY + 12 * HOUR
175+
const firstExcludedInstant = (beforeDay: string) => Date.parse(beforeDay) - 14 * HOUR
176+
177+
it.each([
178+
['UTC midnight', '2026-09-22T00:00:00Z', '2026-09-23T00:00:00Z'],
179+
['midnight ahead of UTC', '2026-09-22T00:00:00+09:00', '2026-09-23T00:00:00+09:00'],
180+
['midnight behind UTC', '2026-09-22T00:00:00-11:00', '2026-09-23T00:00:00-11:00'],
181+
])(
182+
'day modifiers never narrow a window starting at %s in any member zone',
183+
async (_, startDate, endDate) => {
184+
const api = client()
185+
api.json.mockResolvedValue({ ok: true, results: { messages: [] } })
186+
await searchSlack(api, { ...input, filters: { startDate, endDate } })
187+
const modifiers = String(api.json.mock.calls[0]?.[1].body.modifiers)
188+
const after = modifiers.match(/after:(\S+)/)?.[1] ?? ''
189+
const before = modifiers.match(/before:(\S+)/)?.[1] ?? ''
190+
expect(firstIncludedInstant(after)).toBeLessThanOrEqual(Date.parse(startDate))
191+
expect(firstExcludedInstant(before)).toBeGreaterThanOrEqual(Date.parse(endDate))
192+
}
193+
)
194+
})

‎apps/sim/lib/sim-search/live/slack.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ const SLACK_PAGE_SIZE = 20
157157
* against the member's RTS rate limit of about 10 calls a minute.
158158
*/
159159
const MAX_SLACK_SEARCH_PAGES = 3
160+
/**
161+
* Slack's `after:`/`before:` day modifiers are exclusive and read in the member's own zone
162+
* (UTC-12 to UTC+14), so each is widened by two days; the exact `after`/`before` timestamps sent
163+
* alongside still bound the results.
164+
*/
165+
const DAY_MODIFIER_MARGIN_MS = 2 * 86_400_000
166+
167+
/** The UTC day, as `YYYY-MM-DD`, of an instant shifted by `offsetMs`. */
168+
const utcDay = (iso: string, offsetMs: number) =>
169+
new Date(Date.parse(iso) + offsetMs).toISOString().slice(0, 10)
160170

161171
/**
162172
* A search across every source reads one page, so Slack shares the result list with the other
@@ -221,12 +231,8 @@ async function searchSlackPage(
221231
.map(([type]) => type)
222232
const dates = nativeDateBounds(input)
223233
const dateModifiers = [
224-
dates.start
225-
? `after:${new Date(Date.parse(dates.start) - 86400000).toISOString().slice(0, 10)}`
226-
: '',
227-
dates.end
228-
? `before:${new Date(Date.parse(dates.end) + 86400000).toISOString().slice(0, 10)}`
229-
: '',
234+
dates.start ? `after:${utcDay(dates.start, -DAY_MODIFIER_MARGIN_MS)}` : '',
235+
dates.end ? `before:${utcDay(dates.end, DAY_MODIFIER_MARGIN_MS)}` : '',
230236
]
231237
.filter(Boolean)
232238
.join(' ')

0 commit comments

Comments
 (0)