<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Small Home Tools]]></title><description><![CDATA[Notes on renting, moving and residence rules, written from the official sources behind the free browser tools at Small Home Tools. Made by Eddy Hwang.]]></description><link>https://smallhometools.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 02 Nov 2026 23:51:13 GMT</lastBuildDate><atom:link href="https://smallhometools.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[UK ILR absences: checking the 180-days-in-any-12-months rule with a rolling window]]></title><description><![CDATA[How the UK ILR "180 days in any 12 months" rule works (CR 3.1), why calendar years miss it, and an O(n) rolling-window check in JavaScript.]]></description><link>https://smallhometools.hashnode.dev/uk-ilr-absences-checking-the-180-days-in-any-12-months-rule-with-a-rolling-window</link><guid isPermaLink="true">https://smallhometools.hashnode.dev/uk-ilr-absences-checking-the-180-days-in-any-12-months-rule-with-a-rolling-window</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[algorithms]]></category><dc:creator><![CDATA[Small Home Tools]]></dc:creator><pubDate>Sat, 31 Oct 2026 04:00:04 GMT</pubDate><content:encoded><![CDATA[<p>Most UK settlement routes, including indefinite leave to remain (ILR) on the common 5-year routes, require continuous residence. The absence limit sounds simple until you try to check your own travel history against it. This post quotes the rule, explains why calendar years give the wrong answer, and walks through a rolling-window check that runs in linear time.</p>
<p>I built a small browser tool that does this, so I am the maker of what I describe at the end. This post was drafted with an AI agent and reviewed against the GOV.UK sources quoted below. It is about counting days, not legal advice.</p>
<h2>The rule</h2>
<p>Appendix Continuous Residence, CR 3.1:</p>
<blockquote>
<p>To meet the continuous residence requirement, the applicant must not have been outside the UK for more than 180 days in any 12- month period (unless CR 3.2., CR 3.3., CR 5.1. or CR 5.2. applies, and subject to CR 3.4.).</p>
</blockquote>
<p>The important words are "any 12-month period". The Home Office caseworker guidance on continuous residence (version 10.0, published 8 October 2026) spells it out:</p>
<blockquote>
<p>Absences from the UK during a period of permission granted on or after 11 January 2018 are considered on a rolling basis over any 12-month period. This means that absences should not be considered solely in fixed consecutive 12-month periods, as they are for those with permission granted before 11 January 2018. Instead, absences are considered in any 12-month period they may fall within.</p>
</blockquote>
<h2>Why calendar years are not enough</h2>
<p>Take two hypothetical trips:</p>
<table>
<thead>
<tr>
<th>Trip</th>
<th>Leave UK</th>
<th>Return</th>
<th>Whole days outside</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>31 Aug 2023</td>
<td>1 Dec 2023</td>
<td>91 (1 Sep to 30 Nov)</td>
</tr>
<tr>
<td>2</td>
<td>31 Jan 2024</td>
<td>1 May 2024</td>
<td>90 (1 Feb to 30 Apr)</td>
</tr>
</tbody></table>
<p>Per calendar year this is 91 days in 2023 and 90 in 2024, both well under 180. But the 12-month period from 1 May 2023 to 30 April 2024 contains both trips: 181 days. Every period ending between 30 April 2024 and 31 August 2024 holds the same 181 days. A spreadsheet with one row per year would never show it.</p>
<h2>Counting days: whole days only</h2>
<p>The guidance is explicit:</p>
<blockquote>
<p>You must only include whole days when calculating an applicant's absences. Part day absences, less than 24 hours are not counted.</p>
</blockquote>
<p>It gives an example: an applicant absent for 180 days who started the journey back on day 180 and arrived on day 181 does not have day 181 counted as absence. So the departure day and the return day are not counted; only the days strictly between them are. That is why trip 1 above is 91 days and not 93.</p>
<h2>Which period to check</h2>
<p>The windows only matter inside the qualifying period, and CR 1.1 says where that period ends:</p>
<blockquote>
<p>The qualifying period for continuous residence will be calculated by counting back from whichever of the following dates is the most beneficial to the applicant, taking periods of absence into account: (a) the date of application; or (b) any date up to 28 days after the date of application; or (c) the date of decision; ...</p>
</blockquote>
<p>So the end date is an input, and it is worth testing more than one (for example the planned application date and the date 28 days later).</p>
<h2>The algorithm</h2>
<p>The naive approach, summing every trip's overlap with every window, is fine for a few trips but gets messy with partial overlaps. A cleaner way is to work on days.</p>
<ol>
<li><strong>Turn dates into day numbers.</strong> Days since the Unix epoch in UTC, so there are no time zones or daylight saving surprises: <code>Math.floor(Date.UTC(y, m - 1, d) / 86400000)</code>.</li>
<li><strong>Fix the qualifying period.</strong> <code>start</code> is the day after the reference date minus N years; <code>end</code> is the reference date. For 5 years that is about 1,826 days.</li>
<li><strong>Mark absence days.</strong> For each trip, set <code>flag[d] = 1</code> for every whole day outside the UK, from departure + 1 to return − 1. A trip with no return date yet runs to the reference date.</li>
<li><strong>Build a prefix sum.</strong> <code>prefix[k + 1] = prefix[k] + flag[k]</code>. The number of absence days between any two days is now a subtraction.</li>
<li><strong>Slide the window.</strong> For every possible end day <code>e</code> in the period, the window starts on the day after <code>e</code> minus 12 calendar months. Its total is <code>prefix[e + 1] - prefix[from]</code> (with days counted from the start of the period), one operation per window.</li>
<li><strong>Report.</strong> Keep the highest total and merge consecutive end days over 180 into runs, so the output says "periods ending 30 Apr 2024 to 31 Aug 2024 reach 181 days" instead of 124 separate lines.</li>
</ol>
<p>Here is the core, simplified from the tool's source:</p>
<pre><code class="language-js">const LIMIT = 180; // CR 3.1

function ukRolling(trips, start, end) {
  const len = end - start + 1;
  const flag = new Uint8Array(len);
  for (const t of trips) {
    const first = t.out + 1;                        // departure day not counted
    const last = t.ret === null ? end : t.ret - 1;  // return day not counted
    for (let d = Math.max(first, start); d &lt;= Math.min(last, end); d++) flag[d - start] = 1;
  }
  const prefix = new Int32Array(len + 1);
  for (let k = 0; k &lt; len; k++) prefix[k + 1] = prefix[k] + flag[k];

  let worst = { days: -1 };
  const breaches = [];
  for (let e = start; e &lt;= end; e++) {
    const from = Math.max(start, addMonths(e, -12) + 1);
    const days = prefix[e - start + 1] - prefix[from - start];
    if (days &gt; worst.days) worst = { days, from, to: e };
    if (days &gt; LIMIT) {
      const run = breaches[breaches.length - 1];
      if (run &amp;&amp; run.lastEnd === e - 1) { run.lastEnd = e; run.max = Math.max(run.max, days); }
      else breaches.push({ firstEnd: e, lastEnd: e, max: days });
    }
  }
  return { worst, breaches };
}
</code></pre>
<p>Marking days is linear in the total days abroad, and the window scan is linear in the length of the period, so 5 or 10 years of history is instant in a browser.</p>
<h3>Details that are easy to get wrong</h3>
<ul>
<li><strong>"12 months" is calendar months, not 365 days.</strong> The window is built with month arithmetic. When the target month has no matching day (29 February minus 12 months), <code>addMonths</code> clamps to the last day of that month. If you prefer 365-day windows, be aware that the result can differ by a day around leap years.</li>
<li><strong>Overlapping trips.</strong> If two trips overlap in your input, a day is still counted once because it is a flag, not a counter. The tool also warns about overlaps, because they usually mean a typo.</li>
<li><strong>Windows at the start of the period.</strong> The scan starts at the start of the qualifying period, so the earliest windows are clipped to that start. Absences before the qualifying period are outside the check.</li>
<li><strong>Testing.</strong> Write tests from the guidance examples and from hand-made cases like the two trips above, including a trip that ends on the reference date and one with no return date.</li>
</ul>
<h2>What a counter cannot know</h2>
<ul>
<li><strong>Disregarded absences.</strong> CR 3.4 lists absences that do not count, such as travel disruption due to natural disaster, military conflict or pandemic, or compelling and compassionate personal circumstances like the life-threatening illness or death of a close family member. A program cannot see the reason for a trip, so it counts every trip you enter.</li>
<li><strong>Older permission.</strong> For permission granted before 11 January 2018, CR 3.2 uses consecutive 12-month periods instead of rolling ones.</li>
<li><strong>Long Residence.</strong> Under CR 3.3, absences that started before 11 April 2024 are checked against a 548-day total and a 184-day single-absence limit instead.</li>
</ul>
<h2>Try it</h2>
<p>The counter I built, StayDays, applies exactly this check in the browser and keeps the trips on your device: <a href="https://stay-days.pages.dev/en/">stay-days.pages.dev/en</a>. Choose the UK ILR rule set, enter departure and return dates, and it shows the total, the longest trip, the highest 12-month total and any period over 180 days. It also covers Japan's permanent residence and naturalisation counts, which use different rules.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6ae56675e511631306545c3a/c62af4b6-f291-4217-abdc-cc2fd731b3b4.png" alt="StayDays screenshot: six sample trips under the UK ILR rule, 207 days in total, longest trip 75 days, highest 12-month total 137 days, no rolling period over 180" style="display:block;margin:0 auto" />

<p>For a real application, check the current rules and talk to an OISC-regulated adviser or a solicitor.</p>
<p><strong>Sources</strong> (checked 31 October 2026)</p>
<ul>
<li>GOV.UK, Immigration Rules: Appendix Continuous Residence: <a href="https://www.gov.uk/guidance/immigration-rules/immigration-rules-appendix-continuous-residence">https://www.gov.uk/guidance/immigration-rules/immigration-rules-appendix-continuous-residence</a></li>
<li>Home Office, Continuous residence caseworker guidance, version 10.0: <a href="https://www.gov.uk/government/publications/continuous-residence">https://www.gov.uk/government/publications/continuous-residence</a></li>
</ul>
]]></content:encoded></item></channel></rss>