<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hasibat Alomr</title>
    <description>The latest articles on DEV Community by Hasibat Alomr (@hasibatalomr).</description>
    <link>https://dev.to/hasibatalomr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4273610%2F0ef49a27-2d3d-455f-a83d-87b4fa114854.png</url>
      <title>DEV Community: Hasibat Alomr</title>
      <link>https://dev.to/hasibatalomr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hasibatalomr"/>
    <language>en</language>
    <item>
      <title>Rebuilding the Citizen Account Estimator in JavaScript — Three Limits, One Straight Line</title>
      <dc:creator>Hasibat Alomr</dc:creator>
      <pubDate>Mon, 30 Nov 2026 10:36:01 +0000</pubDate>
      <link>https://dev.to/hasibatalomr/rebuilding-the-citizen-account-estimator-in-javascript-three-limits-one-straight-line-3414</link>
      <guid>https://dev.to/hasibatalomr/rebuilding-the-citizen-account-estimator-in-javascript-three-limits-one-straight-line-3414</guid>
      <description>&lt;p&gt;Every month, the same question lands in our inbox in different words: &lt;em&gt;"My salary is X and I have three kids — how much Citizen Account support will I get?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Saudi Arabia's Citizen Account program (حساب المواطن) has an official estimator, but it lives inside the program's portal, and most people just want a quick number before they commit to the full application. So we built one for our site — a small calculator that takes monthly income and family makeup and gives the estimated support in riyals. Rebuilding it turned out to be a nice exercise in reverse-engineering a government formula from the outside, and in testing against a black box until the numbers matched exactly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The formula is three numbers, not a table
&lt;/h2&gt;

&lt;p&gt;My first assumption was that support amounts sit in some big lookup table — income brackets down one side, family sizes across the top. They don't. For any household, everything comes from three figures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The full entitlement.&lt;/strong&gt; The head of household counts for 720 SAR. Each dependent aged 18 or over adds 360, and each younger dependent adds 216. A large family's entitlement stops growing at 2,088.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The exemption limit&lt;/strong&gt; (حد الإعفاء). Below this income, you receive the full entitlement, untouched. It starts at 4,310 for a single person and grows by 2,155 per adult dependent and 1,293 per child.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The preventing limit&lt;/strong&gt; (الحد المانع). At or above this income, support is zero. It starts at 6,857 and grows by 3,428 per adult dependent and 2,057 per child.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Between the two limits, support slides down a straight line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;support = entitlement × (preventingLimit − income) / (preventingLimit − exemptionLimit)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the whole model. Two worked examples, both checked against the official estimator:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A single person earning 5,000 SAR: entitlement 720, limits 4,310 and 6,857 → 720 × 1,857 / 2,547 ≈ &lt;strong&gt;525 SAR&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;A head of household with one adult dependent and two children, earning 12,000 SAR: entitlement 1,512, limits 9,051 and 14,399 → 1,512 × 2,399 / 5,348 ≈ &lt;strong&gt;678 SAR&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing against a black box
&lt;/h2&gt;

&lt;p&gt;The official estimator never shows its working — it takes inputs and returns a number. So we treated it as an oracle: 19 test households, from a single person with no income to large families sitting just under the preventing limit, run through the portal and through our code, compared riyal by riyal. All 19 matched. That process is also how the quirks below surfaced. None of them are written down anywhere we could find; they only appear when a test case disagrees with your formula by a few riyals and you have to work out why.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three quirks that cost us time
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. There is a floor, and then a cliff.&lt;/strong&gt; If the straight-line result comes out below 400 SAR, the estimator pays 400 anyway — as long as income stays under the preventing limit. Cross that limit by a single riyal and the payment drops straight from 400 to 0. Our first version tapered smoothly to zero and failed exactly the near-the-limit cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The displayed limits are capped, even when the raw math is not.&lt;/strong&gt; For very large families the raw exemption limit passes 12,499 and the preventing limit passes 20,001, but the portal's figures stop there. Matching what the official tool actually shows mattered more than matching the pure algebra.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Rounding is plain, but it bites.&lt;/strong&gt; Results are rounded to the nearest riyal: 524.97 becomes 525. Trivial — until a test case lands near a boundary and you spend an hour re-checking formulas that were never wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  "How much" is only half the question
&lt;/h2&gt;

&lt;p&gt;The other half is &lt;em&gt;"when?"&lt;/em&gt; Citizen Account payments land on the 10th of each Gregorian month, with a weekend shuffle: if the 10th falls on a Friday, payment moves a day earlier to Thursday; if it falls on a Saturday, it moves to Sunday. The next payment as I write this is payment 109, due Thursday 10 December 2026. So the calculator page shows the next payment date right next to the estimate, and we keep a separate &lt;a href="https://hasibatalomr.com/citizen-account-countdown/" rel="noopener noreferrer"&gt;countdown page&lt;/a&gt; ticking down to it, for the people who only want the date.&lt;/p&gt;

&lt;p&gt;You can try the calculator itself here: &lt;a href="https://hasibatalomr.com/citizen-account-calculator/" rel="noopener noreferrer"&gt;Citizen Account calculator&lt;/a&gt;. The site is in Arabic — the calculator is the green box at the top; income goes in the first field, dependents below it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part I would do again
&lt;/h2&gt;

&lt;p&gt;If you are reimplementing any official calculator — benefits, tax, fees — budget more time for oracle testing than for the code. The code took an afternoon. The 19 test cases, and the three quirks they exposed, took longer, and they are the only reason I would trust the result in front of someone asking about real money.&lt;/p&gt;

&lt;p&gt;Have you ever reverse-engineered a formula from a government portal? I would like to hear how you tested it — especially if you found a quirk stranger than the 400-riyal cliff.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>i18n</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Hijri Age Calculation in the Browser — Umm al-Qura, Intl.DateTimeFormat, and the Bugs That Bit Us</title>
      <dc:creator>Hasibat Alomr</dc:creator>
      <pubDate>Mon, 30 Nov 2026 07:28:01 +0000</pubDate>
      <link>https://dev.to/hasibatalomr/hijri-age-calculation-in-the-browser-umm-al-qura-intldatetimeformat-and-the-bugs-that-bit-us-4joo</link>
      <guid>https://dev.to/hasibatalomr/hijri-age-calculation-in-the-browser-umm-al-qura-intldatetimeformat-and-the-bugs-that-bit-us-4joo</guid>
      <description>&lt;p&gt;A few months ago a user wrote to us, politely confused. Our calculator told him he was 34. His family insisted he was 33.&lt;/p&gt;

&lt;p&gt;Both were right. He was 33 in Gregorian years and 34 in Hijri years — and that one message basically explains why our little Arabic age calculator, &lt;a href="https://hasibatalomr.com/" rel="noopener noreferrer"&gt;Hasibat Alomr&lt;/a&gt;, shows two ages side by side instead of one.&lt;/p&gt;

&lt;p&gt;If you build anything date-related for users in Saudi Arabia or the Gulf, you run into this fast. Official life there — birth certificates, school enrollment, retirement paperwork — runs on the Hijri calendar. Phones and laptops run on Gregorian. People genuinely live on both, so our tools had to as well.&lt;/p&gt;

&lt;p&gt;This post is about the three bugs that taught me how different the two calendars really are. Two of them were my fault. One of them was the calendar's.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hijri years are shorter, and it adds up
&lt;/h2&gt;

&lt;p&gt;The Hijri calendar is lunar. A normal year has 354 days, a leap year 355 — about 11 days less than a Gregorian year. That sounds small until you compound it over a lifetime: Hijri age grows roughly 3% faster, so the gap widens by about a year every 33 years.&lt;/p&gt;

&lt;p&gt;This is also why the "just multiply by 0.97" shortcut you see in forum answers is wrong. It's close for a 10-year-old and noticeably off for a 60-year-old. We tried it in the first prototype. The error is exactly what our polite user found.&lt;/p&gt;

&lt;p&gt;Saudi Arabia's official calendar is the Umm al-Qura calendar, and its month lengths don't follow a formula you can hard-code — a month is 29 or 30 days based on astronomical calculation. You need a real calendar implementation, not a lookup table you typed from Wikipedia. (Ask me how I know.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The good news: the browser ships the calendar
&lt;/h2&gt;

&lt;p&gt;Modern browsers include Umm al-Qura inside &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt;, through the &lt;code&gt;islamic-umalqura&lt;/code&gt; extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hijriFmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'en-u-ca-islamic-umalqura'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'numeric'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'numeric'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'numeric'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Asia/Riyadh'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;hijriFmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// "20/11/1420" — 20 Dhu al-Qa'dah 1420 AH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That one API replaced the lookup-table approach entirely. For the age itself we convert the birth date and today into Hijri parts with &lt;code&gt;formatToParts&lt;/code&gt;, then do the schoolbook subtraction — years, months, days, borrowing when a number goes negative. Same algorithm as a Gregorian age calculator. The devil is in what "borrowing" means when months don't have fixed lengths, which brings me to the bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 1: I built dates at midnight, and midnight moved
&lt;/h2&gt;

&lt;p&gt;Version one created dates at UTC midnight and formatted them without thinking about time zones. For anyone west of Greenwich, UTC midnight is still the previous evening — so results were off by a day, and the calculator wished people a happy birthday a day early. Not a great look for an age calculator.&lt;/p&gt;

&lt;p&gt;The fix is boring and total: build the instant at midday UTC (&lt;code&gt;Date.UTC(y, m, d, 12)&lt;/code&gt;) so no realistic offset crosses a date line, and always format with &lt;code&gt;timeZone: 'Asia/Riyadh'&lt;/code&gt; so "today" means the user's today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 2: borrowing days from a month of unknown length
&lt;/h2&gt;

&lt;p&gt;When the day subtraction goes negative, you borrow the length of the previous month. Easy in Gregorian. In Hijri, the previous month might have 29 or 30 days and there's no pattern to memorize.&lt;/p&gt;

&lt;p&gt;Our workaround is a small trick I'm still a bit pleased with: convert the 1st of the current Hijri month to a Gregorian date, step back one day, convert that back to Hijri. The day number you land on is the length of the previous month. Three &lt;code&gt;Intl&lt;/code&gt; calls. For a calculator that runs once per click, performance is a non-issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug 3: the digits weren't digits
&lt;/h2&gt;

&lt;p&gt;This one came from real users pasting dates with Arabic-Indic numerals (٠١٢٣٤٥٦٧٨٩) or Persian digits. Our parser read them as garbage and failed silently — the worst kind of failure. Now we normalize before parsing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;normalizeDigits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;٠&lt;span class="o"&gt;-&lt;/span&gt;٩&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'٠١٢٣٤٥٦٧٨٩'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;۰&lt;span class="o"&gt;-&lt;/span&gt;۹&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'۰۱۲۳۴۵۶۷۸۹'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ten lines. Should have been there from day one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this ended up
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://hasibatalomr.com/hijri-age-calculator/" rel="noopener noreferrer"&gt;Hijri age calculator&lt;/a&gt; now runs the whole thing in the browser — both ages, side by side, and the birth date never leaves the device, which matters when the date belongs to a real person and not a test fixture. The same conversion code drives our Gregorian calculator, the age-difference tool and the date converter.&lt;/p&gt;

&lt;p&gt;If I had to compress it into advice: don't approximate a lunar calendar with a ratio, don't trust midnight, and don't assume a digit is a digit.&lt;/p&gt;

&lt;p&gt;Has anyone else here shipped something with &lt;code&gt;islamic-umalqura&lt;/code&gt;? I'm curious what broke for you — I suspect everyone's bug list looks a little different.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>i18n</category>
    </item>
  </channel>
</rss>
