Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A legal calculator is only as trustworthy as the rules it implements, the assumptions it makes visible, and the tests that challenge its output. Bashir Khan describes building a UAE end-of-service gratuity calculator in TypeScript with Claude Code: he traced rules to the law, kept implementation conventions separate, calculated expected test values independently, and named what the tool does not cover. His account is a useful workflow, not an independent audit or proof that AI-generated legal software is reliable.

Start with the law, not the function

Khan runs a small free site of UAE pay and labour calculators. He says he wrote most of the code with Claude Code while directing the work; he also says the article was drafted with AI assistance and then checked against the code and legal text by him. Those details matter: the method below is his account of one project, not an independently reproduced assessment.

For the gratuity calculator, Khan’s core discipline was to require a legal source for every rule entering the implementation. He recorded the relevant Article 51 subsections in the module header and used a concise debugging prompt whenever the AI suggested a rule: “which article?” That question makes a proposed line of code answerable to a provision rather than to an unverified model output. Read Khan’s account on DEV Community.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The legal scope must be explicit. Article 51 of the UAE’s Federal Decree-Law No. 33 of 2021 sets out the gratuity rules for qualifying foreign full-time workers. It is not a basis for assuming identical treatment for every worker category or every employment arrangement. The official English text of the decree-law is the authority to consult for the current rule and its scope.

What Article 51 says about gratuity

In summary, a foreign full-time worker who completes at least one year of continuous service is entitled to gratuity calculated on basic wage. Article 51(2) sets 21 days’ wage for each year of service during the first five years, then 30 days’ wage for each year beyond five. Under Article 51(3), a part of a year is treated proportionally once the one-year threshold has been met. Article 51(4) excludes unpaid absence days from the service-duration calculation, and Article 51(6) caps the gratuity at two years’ wage. Check Article 51 in the official text before applying the summary to a real case.

These are statutory rules for the stated worker scope. A calculator still has to decide how to represent wage input, dates, and service duration in software; those engineering choices should not be presented as if the statute specified them.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Keep legal rules separate from implementation conventions

Khan describes dividing monthly basic wage by 30 to obtain a daily-wage figure and using 365 days as a year-length convention. He labels these as conventions, not formulas prescribed by Article 51. That separation is important: the source rule says the calculation is based on basic wage, while a program must make its own conversion and date-handling choices to produce a numeric result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the distinction visible in code and documentation. A reader or maintainer should be able to identify which statements encode Article 51, which translate legal language into a computational model, and which reflect assumptions about input or rounding. If an assumption changes, it should not be mistaken for a change in the law.

Build tests with an independent answer key

A test is weak if the same implementation that calculates a result also supplies the expected value. Khan warns: “If you let the AI write the function and then the test, it will often run the function and paste the output into expect(). That tests nothing.” The expected result should instead be derived separately—by hand or through a clearly independent calculation—and then fixed in the test.

His examples include an eight-year service period and a case that reaches the two-year-wage ceiling. Those cases exercise different parts of Article 51: the transition from the first-five-years rate to the later-years rate, and the maximum. A useful test suite should make its expected values understandable from the legal rule and the stated assumptions, rather than merely proving that the function repeats its own output.

Khan reports that the site’s calculators had 150 hand-calculated tests when he published his account. That is a reported test count, not an independently measured accuracy rate. Passing tests can preserve a mistaken interpretation if the legal source, scope, or expected answer is wrong; test quantity alone does not establish legal correctness.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Count service time by calendar anniversaries

Date arithmetic can quietly alter a legal calculation. Khan says that dividing elapsed days by 365 can misstate a full calendar-year interval containing leap days. His described approach counts whole anniversaries first and then calculates the remaining fraction, rather than treating every year as exactly 365 elapsed days.

The article gives a test spanning 1 January 2017 through 31 December 2024 to exercise that boundary. It is a useful example of turning a calendar concern into a named test case, but it does not establish that the implementation handles every timezone, date format, or leap-day scenario correctly. The code excerpt uses local date getters in part of its example while converting dates through UTC, so the account should be read as a reported approach and test—not an exhaustive validation of date behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

State the calculator’s limits

Khan says the calculator does not model part-time pro-rata treatment or employer deductions. Those exclusions define the reported tool’s scope; they should not be read as a complete list of every circumstance that could require special treatment. A legal calculator should make unsupported cases apparent rather than implying that a result applies universally.

For a real payroll question, verify the worker category, applicable legal text, wage basis, service dates, and any relevant adjustments with an authoritative source or qualified adviser. This implementation account is educational, not individualized legal or payroll advice.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What this workflow does—and does not—establish

The practical value of Khan’s account is its separation of concerns: trace each legal rule to its provision, label software conventions, derive expected values outside the generated function, deliberately test calendar boundaries, and disclose exclusions. Those habits make assumptions easier to review and defects easier to expose.

They do not prove that AI can reliably write legal software, nor does Khan report an independently audited error rate or comparative study. The article’s value is as a concrete process example: use an AI coding partner to help implement and test a bounded rule set, while keeping legal interpretation, test expectations, and scope review visible to a human.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.