@@ -283,18 +283,28 @@ const results = rawResults.filter(item => {
283283});
284284```
285285
286- ** Date calculation pattern** (day-granularity — ` .split('T')[0] ` truncates to YYYY-MM-DD):
286+ ** Date calculation pattern** (day-granularity — ` .toISOString().slice(0, 10) ` truncates to YYYY-MM-DD):
287287``` javascript
288- const today = new Date ().toISOString ().split (' T' )[0 ];
289- const dayOfWeek = new Date ().getUTCDay (); // 0=Sunday, 6=Saturday
290- const lookbackDays = dayOfWeek === 6 ? 5 : Math .ceil (12 / 24 ); // Saturday=5 days, else ceil(hours/24)
291- const fromDate = new Date (Date .now () - lookbackDays * 86400000 ).toISOString ().split (' T' )[0 ];
288+ const now = new Date ();
289+ const lookback_hours = 12 ; // default; override via workflow input
290+ const lookbackHours = Number (lookback_hours);
291+ if (! Number .isFinite (lookbackHours) || ! Number .isInteger (lookbackHours) || lookbackHours <= 0 ) {
292+ throw new Error (' Invalid lookback_hours' );
293+ }
294+ const lookbackMs = lookbackHours * 3600000 ; // 3600000 ms per hour
295+ const fromDate = new Date (now .getTime () - lookbackMs).toISOString ().slice (0 , 10 );
296+ // For weekly review (Saturday): 5 * 86400000 ms = 5 days
297+ const weekStart = new Date (now .getTime () - 5 * 86400000 ).toISOString ().slice (0 , 10 );
298+ const today = now .toISOString ().slice (0 , 10 );
292299```
293300
294301** Post-query filtering example:**
295302``` javascript
296303const results = await get_betankanden ({ rm: currentRm, limit: 50 });
297- const recent = results .filter (b => (b .publicerad || ' ' ).slice (0 , 10 ) >= fromDate);
304+ const recent = results .filter (item => {
305+ const itemDate = (item .datum || item .publicerad || item .inl ämnad || ' ' ).slice (0 , 10 );
306+ return itemDate >= fromDate;
307+ });
298308```
299309
300310** Date calculation example:**
@@ -317,6 +327,29 @@ const todayVotes = votes.filter(v => v.datum?.slice(0, 10) >= fromDate);
317327
318328Cross-reference related data sources for richer analysis. Filter all results by date to ` >= fromDate` .
319329
330+ #### Example 1: Committee Report Deep Dive
331+ ` ` `
332+ // 1. Fetch committee reports for the period
333+ // 2. For each report, look up related voting records via search_voteringar(bet: reportId)
334+ // 3. Cross-reference with any motions that reference the same bet
335+ ` ` `
336+
337+ #### Example 2: Government Activity Analysis
338+ ` ` `
339+ // 1. Get government propositions (get_propositioner)
340+ // 2. Search for committee reports (get_betankanden) that reference each proposition
341+ // 3. Look up debate speeches (search_anforanden) on the same topic
342+ ` ` `
343+
344+ #### Example 3: Party Behavior Analysis
345+ ` ` `
346+ // 1. Get voting records grouped by party (search_voteringar with groupBy: parti)
347+ // 2. Cross-reference with motions filed by each party
348+ // 3. Identify where parties voted against their own motions
349+ ` ` `
350+
351+ ### Detailed Code Examples
352+
320353**Example 1: Committee Report Deep Dive**
321354` ` ` javascript
322355// Setup: riksmöte + date threshold (ISO-string comparison — timezone-safe)
0 commit comments