<?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: Jack West</title>
    <description>The latest articles on DEV Community by Jack West (@jack_westttt).</description>
    <link>https://dev.to/jack_westttt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4126668%2F85a8dbfa-9d34-4478-9307-b89195b3336e.webp</url>
      <title>DEV Community: Jack West</title>
      <link>https://dev.to/jack_westttt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jack_westttt"/>
    <language>en</language>
    <item>
      <title>I Built a UAE Gratuity Calculator Here's the Logic (21/30-Day Rule in Code)</title>
      <dc:creator>Jack West</dc:creator>
      <pubDate>Mon, 12 Oct 2026 16:21:51 +0000</pubDate>
      <link>https://dev.to/jack_westttt/i-built-a-uae-gratuity-calculator-heres-the-logic-2130-day-rule-in-code-48d3</link>
      <guid>https://dev.to/jack_westttt/i-built-a-uae-gratuity-calculator-heres-the-logic-2130-day-rule-in-code-48d3</guid>
      <description>&lt;p&gt;UAE labour law (Federal Decree-Law No. 33 of 2021, Article 51) defines end-of-service gratuity with a two-tier formula. I turned it into a free web tool — here's the exact logic, including the edge cases most implementations get wrong.&lt;br&gt;
Live tool: &lt;a href="https://thegratuitycalculatoruae.com/" rel="noopener noreferrer"&gt;https://thegratuitycalculatoruae.com/&lt;/a&gt;&lt;br&gt;
Repo: &lt;a href="https://github.com/jackkkwesttt-byte/Gratuity-calculator-uae" rel="noopener noreferrer"&gt;https://github.com/jackkkwesttt-byte/Gratuity-calculator-uae&lt;/a&gt;&lt;br&gt;
The formula&lt;br&gt;
Daily wage = basic monthly salary ÷ 30&lt;br&gt;
First 5 years of service: 21 days' wage per year&lt;br&gt;
Every year after 5: 30 days' wage per year&lt;br&gt;
Eligibility: minimum 1 full year of service&lt;br&gt;
Cap: total can never exceed 2 years of basic salary&lt;br&gt;
Unpaid leave days are excluded from the service count&lt;br&gt;
The implementation&lt;br&gt;
function calculateGratuity(basicSalary, yearsOfService, unpaidLeaveDays = 0) {&lt;br&gt;
  // No gratuity under one year of service&lt;br&gt;
  if (yearsOfService &amp;lt; 1) return 0;&lt;/p&gt;

&lt;p&gt;const dailyWage = basicSalary / 30;&lt;/p&gt;

&lt;p&gt;// Unpaid leave doesn't count toward service&lt;br&gt;
  const effectiveYears = yearsOfService - unpaidLeaveDays / 365;&lt;/p&gt;

&lt;p&gt;const firstTier = Math.min(effectiveYears, 5) * 21 * dailyWage;&lt;br&gt;
  const secondTier = Math.max(effectiveYears - 5, 0) * 30 * dailyWage;&lt;/p&gt;

&lt;p&gt;const total = firstTier + secondTier;&lt;/p&gt;

&lt;p&gt;// Statutory cap: 2 years of basic salary&lt;br&gt;
  return Math.min(total, basicSalary * 24);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// Example: AED 8,000 basic, 3 years service&lt;br&gt;
console.log(calculateGratuity(8000, 3)); // 16800&lt;br&gt;
Edge cases worth handling&lt;br&gt;
Fractional years. Someone with 5 years and 4 months isn't at the 30-day tier for the partial year — the split happens exactly at the 5-year mark. Math.min/Math.max on the tier boundary handles this; don't round years first.&lt;br&gt;
The cap. Easy to forget. A 30-year employee at AED 20,000/month computes 855 days' wage ≈ AED 570,000 — but the statute caps it at 24 months = AED 480,000. The cap only binds past ~25.5 years of service, which is exactly why it gets forgotten. Always apply it.&lt;br&gt;
Basic vs gross salary. This is a data problem, not a math problem — the formula only ever takes basic salary. If your UI has one salary field, label it "Basic Salary (excluding allowances)" or users will inflate their own result.&lt;br&gt;
Unpaid leave. Most calculators ignore this. Subtracting unpaid days from the service period is the legally correct behavior.&lt;br&gt;
Why this was fun to build&lt;br&gt;
It's a rare case where the entire business logic fits in 15 lines but the domain edge cases (tier boundary, cap, leave exclusion) are where correctness lives. The UI is the easy part — getting the law right in code is the actual work.&lt;br&gt;
If you're in the UAE private sector, run your own numbers against your settlement letter: &lt;a href="https://thegratuitycalculatoruae.com/" rel="noopener noreferrer"&gt;https://thegratuitycalculatoruae.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>calculator</category>
      <category>uae</category>
    </item>
  </channel>
</rss>
