<?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: abdoartistico</title>
    <description>The latest articles on DEV Community by abdoartistico (@abdoartistico).</description>
    <link>https://dev.to/abdoartistico</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3810625%2F309822e0-c771-4d74-9230-5f7736103e7d.png</url>
      <title>DEV Community: abdoartistico</title>
      <link>https://dev.to/abdoartistico</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdoartistico"/>
    <language>en</language>
    <item>
      <title>Building a Production-Ready Islamic Prayer Times Library in TypeScript</title>
      <dc:creator>abdoartistico</dc:creator>
      <pubDate>Fri, 06 Mar 2026 22:00:44 +0000</pubDate>
      <link>https://dev.to/abdoartistico/building-a-production-ready-islamic-prayer-times-library-in-typescript-2lfh</link>
      <guid>https://dev.to/abdoartistico/building-a-production-ready-islamic-prayer-times-library-in-typescript-2lfh</guid>
      <description>&lt;p&gt;Building a simple clock to calculate the Islamic call to prayer (&lt;em&gt;Adhan&lt;/em&gt;) seems straightforward at first. Since the timing of the five daily prayers is based entirely on the position of the sun, you just need a bit of astronomy, right?&lt;/p&gt;

&lt;p&gt;Well, yes. But if you try to build a production app, you quickly realize that &lt;strong&gt;astronomy is easy, but geography is hard.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In this tutorial, we will look at how to calculate prayer times using TypeScript, investigate the geographical edge cases that break naive implementations, and look at an open-source mapping engine we built to solve them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: The Basic Calculations (The Easy Part)
&lt;/h2&gt;

&lt;p&gt;At the core, you need to calculate solar declination based on a user's latitude and longitude. Instead of recreating NASA-level math from scratch, the brilliant &lt;a href="https://github.com/batoulapps/adhan-js" rel="noopener noreferrer"&gt;adhan.js library&lt;/a&gt; handles the astronomy perfectly.&lt;/p&gt;

&lt;p&gt;Let's assume we want to get the prayer times for London, UK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Coordinates&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CalculationMethod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PrayerTimes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;adhan&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// London, UK Coordinates&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;londonCoords&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;Coordinates&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;51.5074&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.1278&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&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;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Today&lt;/span&gt;

&lt;span class="c1"&gt;// We must choose a calculation method. &lt;/span&gt;
&lt;span class="c1"&gt;// For London, the "Muslim World League" is largely standard.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;CalculationMethod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MuslimWorldLeague&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prayerTimes&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;PrayerTimes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;londonCoords&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fajr:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prayerTimes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fajr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Maghrib:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;prayerTimes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maghrib&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple, right? Run this, and you get incredibly precise times. However, this implementation will fail spectacularly if you try to scale it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: The Geographical Nightmare
&lt;/h2&gt;

&lt;p&gt;Did you notice this line?&lt;br&gt;
&lt;code&gt;const params = CalculationMethod.MuslimWorldLeague();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are over a dozen authoritative mathematical models globally for calculating the angles for &lt;em&gt;Fajr&lt;/em&gt; (Dawn) and &lt;em&gt;Isha&lt;/em&gt; (Night). &lt;/p&gt;

&lt;p&gt;If a user opens your app in &lt;strong&gt;New York&lt;/strong&gt;, they expect the ISNA (Islamic Society of North America) method. If they open it in &lt;strong&gt;Makkah&lt;/strong&gt;, they expect the Umm Al-Qura fixed-interval method. If they open it in &lt;strong&gt;Karachi&lt;/strong&gt;, they expect the University of Islamic Sciences method, plus a different "school of thought" adjustment (Hanafi) for the &lt;em&gt;Asr&lt;/em&gt; (Afternoon) prayer.&lt;/p&gt;

&lt;p&gt;If you just default everyone to &lt;code&gt;MuslimWorldLeague()&lt;/code&gt;, your times will be off by up to &lt;strong&gt;45 minutes&lt;/strong&gt; in certain parts of the world. Your users will uninstall your app immediately.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: The Solution (Intelligent Mapping)
&lt;/h2&gt;

&lt;p&gt;You cannot ask users &lt;em&gt;"Hey, do you follow the ISNA or the Egyptian General Authority rules?"&lt;/em&gt; because 99% of people have no idea. They just know when their local mosque calls the Adhan.&lt;/p&gt;

&lt;p&gt;To solve this, your application needs an intelligent mapping layer that takes the user's location and automatically assigns the correct calculation parameters. &lt;/p&gt;

&lt;p&gt;When building &lt;strong&gt;&lt;a href="https://islamichotspot.com" rel="noopener noreferrer"&gt;Islamic Hotspot&lt;/a&gt;&lt;/strong&gt; (a platform providing times for 500+ global cities), we spent weeks manually mapping 100+ ISO country codes to their exact calculation parameters. &lt;/p&gt;

&lt;p&gt;Instead of forcing you to do that research from scratch, &lt;strong&gt;we open-sourced our entire TypeScript mapping engine.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can drop the &lt;a href="https://github.com/abdoartistico/islamic-prayer-times-utility" rel="noopener noreferrer"&gt;islamic-prayer-times-utility&lt;/a&gt; package right into your Node project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;islamic-prayer-times-utility
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, instead of guessing the method, you can dynamically assign it based on the user's country code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getCalculationMethodForCountry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getMethodName&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;islamic-prayer-times-utility&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// If a user in Saudi Arabia connects:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;saudiMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getCalculationMethodForCountry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SA&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getMethodName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;saudiMethod&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "Umm Al-Qura (Makkah)"&lt;/span&gt;

&lt;span class="c1"&gt;// If a user in the US connects:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;usMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getCalculationMethodForCountry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getMethodName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;usMethod&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "ISNA"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By putting this utility in front of your calculations, your app instantly becomes hyper-accurate globally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: The Lunar Calendar Offset
&lt;/h2&gt;

&lt;p&gt;The second major headache is dates. The Hijri (Islamic) calendar is lunar. While libraries like &lt;code&gt;hijri-converter&lt;/code&gt; can do the math perfectly for the standard Tabular calendar (which Saudi Arabia uses), they fail regionally. &lt;/p&gt;

&lt;p&gt;Countries in North Africa (like Morocco, Algeria, and Tunisia) strictly follow physical local moon sightings. This means their calendar is frequently &lt;strong&gt;one day behind&lt;/strong&gt; the mathematically predicted Tabular calendar.&lt;/p&gt;

&lt;p&gt;Our open-source wrapper handles this automatically as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;gregorianToHijriDateForCountry&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;islamic-prayer-times-utility&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&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;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Getting the Hijri date in Morocco (Automatically handles the -1 day offset!)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;moroccanHijri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;gregorianToHijriDateForCountry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;moroccanHijri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;formatted&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs accurately localized date&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Building localized applications requires moving beyond standard math into cultural and geographical research. &lt;/p&gt;

&lt;p&gt;If you are building an Islamic app, I highly recommend using &lt;code&gt;adhan.js&lt;/code&gt; for your astronomy, and our mapping engine to handle the geography. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Mapping Engine (Open Source):&lt;/strong&gt; &lt;a href="https://github.com/abdoartistico/islamic-prayer-times-utility" rel="noopener noreferrer"&gt;islamic-prayer-times-utility on GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;See this code running in Production:&lt;/strong&gt; &lt;a href="https://islamichotspot.com" rel="noopener noreferrer"&gt;IslamicHotspot.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have you ever run into weird geolocation edge cases while building apps? Let me know in the comments!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
