<?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: Konstantin Iliev</title>
    <description>The latest articles on DEV Community by Konstantin Iliev (@konstantin_iliev).</description>
    <link>https://dev.to/konstantin_iliev</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%2F4229443%2Fac5958b2-ddd4-4b45-9d06-c77569b2efae.jpg</url>
      <title>DEV Community: Konstantin Iliev</title>
      <link>https://dev.to/konstantin_iliev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/konstantin_iliev"/>
    <language>en</language>
    <item>
      <title>A percentage calculator for marketers: lessons from 41 languages and one tricky formula</title>
      <dc:creator>Konstantin Iliev</dc:creator>
      <pubDate>Mon, 16 Nov 2026 21:30:22 +0000</pubDate>
      <link>https://dev.to/konstantin_iliev/a-percentage-calculator-for-marketers-lessons-from-41-languages-and-one-tricky-formula-1jpb</link>
      <guid>https://dev.to/konstantin_iliev/a-percentage-calculator-for-marketers-lessons-from-41-languages-and-one-tricky-formula-1jpb</guid>
      <description>&lt;p&gt;I work as an internet marketer, and half of my day is percentages. Sessions went from 12 480 to 15 210. The conversion rate fell from 3.2% to 2.7%. A channel took 1 170 of a 4 500 budget.&lt;/p&gt;

&lt;p&gt;For years I answered those on my computer's calculator or in a spreadsheet cell I typed once and forgot. I wanted one tool that opens fast, answers while I type and asks the questions the way I ask them. So I built &lt;a href="https://percentagecalculator.page/" rel="noopener noreferrer"&gt;Percentage Calculator&lt;/a&gt;: seven calculators on one page, in 41 languages. It is 100% free and has no ads.&lt;/p&gt;

&lt;p&gt;It is plain PHP, one JavaScript file and one stylesheet, with no framework and no build step. These are the parts that turned out harder than "divide by 100".&lt;/p&gt;

&lt;h2&gt;
  
  
  Seven questions, seven calculators
&lt;/h2&gt;

&lt;p&gt;Every calculator on the page is one question I ask during a normal week. Percentage change comes first because it is the one I open most.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4lr22mgqe0rb2hkw0b2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4lr22mgqe0rb2hkw0b2.png" alt="Percentage Calculator" width="800" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Calculator&lt;/th&gt;
&lt;th&gt;The question&lt;/th&gt;
&lt;th&gt;An example from my week&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Percentage change&lt;/td&gt;
&lt;td&gt;From X to Y, by how much?&lt;/td&gt;
&lt;td&gt;Sessions 12 480 → 15 210: +21.88%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Percentage of a number&lt;/td&gt;
&lt;td&gt;What is X% of Y?&lt;/td&gt;
&lt;td&gt;26% of a 4 500 budget: 1 170&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What percent&lt;/td&gt;
&lt;td&gt;X is what percent of Y?&lt;/td&gt;
&lt;td&gt;1 170 of 4 500: 26.00%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Add or subtract a percentage&lt;/td&gt;
&lt;td&gt;Y plus or minus X%&lt;/td&gt;
&lt;td&gt;A price of 100 plus 20% VAT: 120&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Original value&lt;/td&gt;
&lt;td&gt;Y after a change of X%: what was it before?&lt;/td&gt;
&lt;td&gt;120 including 20% VAT: 100 before tax&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Percentage difference&lt;/td&gt;
&lt;td&gt;How far apart are X and Y?&lt;/td&gt;
&lt;td&gt;CTR 2.4% vs 3.1% in an A/B test: 25.45%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tip&lt;/td&gt;
&lt;td&gt;Bill, tip and split&lt;/td&gt;
&lt;td&gt;60 plus 10%, two people: 33 each&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last one is not marketing. It is for the dinner after a good month.&lt;/p&gt;

&lt;h2&gt;
  
  
  Percent change when the start is negative
&lt;/h2&gt;

&lt;p&gt;The textbook formula is (new − old) ÷ old × 100. It breaks as soon as the starting value is negative, and in marketing that is not rare: profit, net revenue after refunds, a campaign that lost money.&lt;/p&gt;

&lt;p&gt;Say a loss of 2 000 shrinks to a loss of 500. The textbook formula gives 1 500 ÷ −2 000 = −75%, which reads as things got worse. They got better. Dividing by the absolute value of the start fixes the sign:&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;function&lt;/span&gt; &lt;span class="nf"&gt;percentChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// no baseline, no percentage&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&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;Now the same case is +75%. The result always shows its sign, green for up and red for down, and the worked example under the calculator shows the |…| so nobody has to guess the formula.&lt;/p&gt;

&lt;p&gt;One more trap lives here. A CTR that goes from 2% to 3% grew by 50%, not by 1%. The 1 is percentage points. The calculator answers in percent; points are a plain subtraction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Percentage difference is a different question
&lt;/h2&gt;

&lt;p&gt;Percent change needs a starting point. When two campaigns run side by side, neither of them is the baseline. Percentage difference divides the gap by the average of the two, so the order does not matter:&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;function&lt;/span&gt; &lt;span class="nf"&gt;percentDifference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;avg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;avg&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;avg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&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;Take a CTR of 2.4% in version A and 3.1% in version B. The change from A to B is +29.17%, the change from B to A is −22.58%, and the difference is 25.45% both ways. Absolute values in the average keep the answer positive even when one of the values is negative.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sentences with holes in them
&lt;/h2&gt;

&lt;p&gt;Each calculator is a sentence with the input fields inside it: "What is [20]% of [150]?" It reads like the question in my head, so I never wonder which box is which. It also means that a translation is not a list of strings.&lt;/p&gt;

&lt;p&gt;Word order moves the inputs. Japanese puts the number before the percentage, and so do Hindi, Korean and Bengali:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- English --&amp;gt;&lt;/span&gt;
What is &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"percent1"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Percentage"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;% of &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"number1"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Number"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;?

&lt;span class="c"&gt;&amp;lt;!-- Japanese --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"number1"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"数値"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; の &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"percent1"&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"パーセント"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;% はいくつですか？
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ids stay the same in every language, so one script serves all 41 pages, wherever the grammar puts the fields.&lt;/p&gt;

&lt;p&gt;Grammar can also depend on the number itself. In Turkish, "20% of 100" is 100'ün %20'si, and the endings change with the sound of each number. A fixed sentence cannot know what you will type, so the Turkish page uses a construction that works for any number: "[100] sayısının yüzde [20] oranındaki kısmı kaçtır?" Hungarian has the same problem with its article a/az, and solves it the way Hungarian forms do: a(z).&lt;/p&gt;

&lt;p&gt;One more detail. A &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; around a sentence with two inputs gives a name only to the first one, so a screen reader announces the second field with no name at all. Every input carries its own &lt;code&gt;aria-label&lt;/code&gt; in the page language instead: "Starting value", "New value", "Bill amount".&lt;/p&gt;

&lt;h2&gt;
  
  
  Typing numbers in 41 locales
&lt;/h2&gt;

&lt;p&gt;Half of the languages write 12,5 and the other half 12.5. A &lt;code&gt;type="number"&lt;/code&gt; field treats the decimal comma differently from browser to browser; in my tests Chromium dropped it silently, so 12,50 became 1250. The fields are &lt;code&gt;type="text"&lt;/code&gt; with &lt;code&gt;inputmode="decimal"&lt;/code&gt;, which still opens a number keyboard on phones, and the script reads the number itself.&lt;/p&gt;

&lt;p&gt;The page language decides what a separator means:&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;parts&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;NumberFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;formatToParts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;12345.6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;decimal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'decimal'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "," on the German page&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'group'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// "." on the German page&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rules that came out of it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A comma or a dot both work. When both appear, the last one is the decimal separator, so 1.234,56 and 1,234.56 are the same number.&lt;/li&gt;
&lt;li&gt;A single separator followed by exactly three digits is a thousands separator if it matches the page language. 1,000 on the English page is a thousand, and so is 1.000 on the German page. 0,125 stays a decimal.&lt;/li&gt;
&lt;li&gt;Spaces, apostrophes and a trailing % are ignored, and both - and − work as a minus.&lt;/li&gt;
&lt;li&gt;Native digits are converted: Persian ۱۲٫۵, Bengali ১২.৫, Devanagari, Thai, and the full-width digits a Japanese or Chinese keyboard produces.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The output goes the other way, through &lt;code&gt;Intl.NumberFormat&lt;/code&gt; with the page language. The same 12.5% shows as 12,50 % in German, %12,50 in Turkish and ۱۲٫۵۰٪ in Persian, with no formatting code of my own.&lt;/p&gt;

&lt;h2&gt;
  
  
  1.005 is not 1.005
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;(1.005).toFixed(2)&lt;/code&gt; returns "1.00", and &lt;code&gt;(2.675).toFixed(2)&lt;/code&gt; returns "2.67". Both numbers are stored in binary as a hair below the half, so &lt;code&gt;toFixed&lt;/code&gt; rounds them down. A calculator that is off by one cent on round numbers loses trust fast.&lt;/p&gt;

&lt;p&gt;The fix is to drop the binary noise before rounding:&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;function&lt;/span&gt; &lt;span class="nf"&gt;round2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toPrecision&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no "-0.00"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;toPrecision(15)&lt;/code&gt; keeps the 15 digits a double can hold reliably and throws away the rest. 100.49999999999999 becomes 100.5, and only then does &lt;code&gt;Math.round&lt;/code&gt; see it. Working on the absolute value rounds halves away from zero for negative changes too. The same core was checked against exact integer arithmetic for every cent from 0.01 to 20 000, with no difference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Right to left, but the formula stays left to right
&lt;/h2&gt;

&lt;p&gt;The Arabic, Hebrew, Persian and Urdu pages run right to left with &lt;code&gt;dir="rtl"&lt;/code&gt; on the &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; element. The stylesheet uses logical properties such as &lt;code&gt;inset-inline-end&lt;/code&gt; and &lt;code&gt;margin-inline-start&lt;/code&gt;, so the language menu opens on the correct side without a second stylesheet.&lt;/p&gt;

&lt;p&gt;The worked example under each calculator is the exception. It uses Western digits and operators, and in a right-to-left paragraph the browser reorders them into nonsense. Wrapping it in &lt;code&gt;&amp;lt;bdi dir="ltr"&amp;gt;&lt;/code&gt; keeps it in one piece:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"example"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;مثال: &lt;span class="nt"&gt;&amp;lt;bdi&lt;/span&gt; &lt;span class="na"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ltr"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;(120 − 100) ÷ |100| × 100 = +20%&lt;span class="nt"&gt;&amp;lt;/bdi&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Intl.NumberFormat&lt;/code&gt; also adds invisible direction marks around numbers in some right-to-left locales. They are correct on screen and annoying in a spreadsheet, so the copy button strips U+200E and U+200F before it writes to the clipboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  One list for 41 languages
&lt;/h2&gt;

&lt;p&gt;Every language is a plain PHP file, and one array in &lt;code&gt;languages.php&lt;/code&gt; describes them all: file name, &lt;code&gt;lang&lt;/code&gt;, &lt;code&gt;hreflang&lt;/code&gt;, native name, English name and text direction. The head of every page, the language menu and the footer list are built from that array, so a new language is one new row and one new page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;pcHeadLinks&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="nv"&gt;$langs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pcLanguages&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="nv"&gt;$out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;link rel="canonical" href="'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;pcEsc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pcUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$langs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;pcCurrentLanguage&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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'"&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$langs&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$l&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$out&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;link rel="alternate" hreflang="'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;pcEsc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$l&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'hreflang'&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="s1"&gt;'" href="'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;pcEsc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pcUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$l&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="s1"&gt;'"&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$out&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;link rel="alternate" hreflang="x-default" href="'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;pcEsc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pcBaseUrl&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="s1"&gt;'"&amp;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;File names can be anything; &lt;code&gt;hreflang&lt;/code&gt; values cannot. My Simplified Chinese page is &lt;code&gt;ch.php&lt;/code&gt; and Bengali is &lt;code&gt;bd.php&lt;/code&gt;, but their links say &lt;code&gt;zh-Hans&lt;/code&gt; and &lt;code&gt;bn&lt;/code&gt;. Portuguese has two pages, &lt;code&gt;pt-PT&lt;/code&gt; and &lt;code&gt;pt-BR&lt;/code&gt;, because "percentagem" and "porcentagem" are searched by different people.&lt;/p&gt;

&lt;p&gt;The language menu is a &lt;code&gt;&amp;lt;details&amp;gt;&lt;/code&gt; element, so it works with JavaScript switched off. A 2 KB script adds a search box that matches native and English names, so "deutsch" and "german" both find the same page, and Enter opens the first match.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4j5untj1sn13rivz8xd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4j5untj1sn13rivz8xd.png" alt="Language menu" width="620" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Small touches and the stack
&lt;/h2&gt;

&lt;p&gt;Most of the work went into details I would miss if they were not there:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The answer is a large number after an "=", in an &lt;code&gt;&amp;lt;output&amp;gt;&lt;/code&gt; element, with a copy button next to it. Before you type, it shows a dash, so it never looks like one more field to fill in.&lt;/li&gt;
&lt;li&gt;A field that holds something that is not a number gets a red border and &lt;code&gt;aria-invalid&lt;/code&gt;, instead of a silent blank result.&lt;/li&gt;
&lt;li&gt;A row of quick links under the title jumps to each calculator. On a phone it scrolls sideways, so it does not push the first calculator off the screen.&lt;/li&gt;
&lt;li&gt;Under each calculator there is a worked example with real numbers, which explains the formula faster than a paragraph.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The front end stays small: one script for all seven calculators, one stylesheet and a tiny script for the language menu, under 8 KB together when gzipped. The server side is a few plain PHP files.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd like to hear
&lt;/h2&gt;

&lt;p&gt;I use the calculator every week, and it has replaced the phone calculator for me. Three things I would like your opinion on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Translations.&lt;/strong&gt; The 41 versions were translated with the help of AI tools and checked where I could. If you are a native speaker, especially of Amharic, Marathi, Tamil, Telugu, Swahili or Filipino, I would love a correction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Missing questions.&lt;/strong&gt; If you work with numbers like I do, which percentage question do you still answer by hand? Percentage points, margin versus markup and compound growth are on my list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parsing.&lt;/strong&gt; Would you read 1.000 on a German page as one thousand, or as one with three decimals? The calculator reads it as one thousand, and I can see arguments both ways.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The calculator is at &lt;a href="https://percentagecalculator.page/" rel="noopener noreferrer"&gt;percentagecalculator.page&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>i18n</category>
    </item>
    <item>
      <title>2 million postal codes in plain PHP and SQLite: lessons from 105 countries of open data</title>
      <dc:creator>Konstantin Iliev</dc:creator>
      <pubDate>Sat, 14 Nov 2026 22:11:49 +0000</pubDate>
      <link>https://dev.to/konstantin_iliev/2-million-postal-codes-in-plain-php-and-sqlite-lessons-from-105-countries-of-open-data-2242</link>
      <guid>https://dev.to/konstantin_iliev/2-million-postal-codes-in-plain-php-and-sqlite-lessons-from-105-countries-of-open-data-2242</guid>
      <description>&lt;p&gt;I run &lt;a href="https://whattimeisit.zone" rel="noopener noreferrer"&gt;WhatTimeIsIt.zone&lt;/a&gt;, a world clock with a page for every city. Every city also has a postal code, so in November 2026 I launched a sister site, &lt;a href="https://postalcodefinder.net" rel="noopener noreferrer"&gt;PostalCodeFinder.net&lt;/a&gt;: zip codes, postcodes and postal codes of 105 countries and territories, over 2 million codes, with maps and a few free tools.&lt;/p&gt;

&lt;p&gt;No framework, no build step: plain PHP, SQLite and LiteSpeed cache on ordinary shared hosting. Here is what I learned, with the numbers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fofklasa3ml2paqii84fr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fofklasa3ml2paqii84fr.png" alt="The home page: search by code or place, or find the code where you are" width="800" height="729"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One SQLite file per country
&lt;/h2&gt;

&lt;p&gt;Postal data changes once a month, and the site only reads it. So instead of a database server, every country is one read-only SQLite file: &lt;code&gt;postal-bg.sqlite&lt;/code&gt;, &lt;code&gt;postal-us.sqlite&lt;/code&gt; and so on, plus one shared search index.&lt;/p&gt;

&lt;p&gt;The import builds a new file next to the old one and renames it over the old one when it is done. The site keeps reading the old file until the rename, so there is no window with half-imported data, and a failed import changes nothing.&lt;/p&gt;

&lt;p&gt;The files are small, except one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;United Kingdom: 2 650 206 postcodes, 901 097 of them terminated, around 247 MB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The UK file taught me two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Store IDs, not strings.&lt;/strong&gt; For a "What council am I in?" tool, every postcode needed its council, county, ward and constituency. These are 9-character government codes like &lt;code&gt;E07000240&lt;/code&gt;. Stored as small integers with a lookup table, the four columns added about 27 MB instead of several times that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;VACUUM INTO&lt;/code&gt; after a big import.&lt;/strong&gt; Inserting 2.6 million rows into a &lt;code&gt;WITHOUT ROWID&lt;/code&gt; table and its index leaves pages half empty after B-tree splits. &lt;code&gt;VACUUM INTO 'new-file'&lt;/code&gt; writes a compact copy straight to disk, without a temporary copy in memory: 277 MB became 247 MB in about 2 seconds. It now runs for any file over 64 MB.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Open data lies (a little)
&lt;/h2&gt;

&lt;p&gt;The postal codes come from GeoNames (CC BY 4.0), the UK from the ONS Postcode Directory. Both are excellent. Both have surprises when you build 370 000 pages from them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The 300 km wrong turn.&lt;/strong&gt; In Malaysia, postal code 88550 of Kota Kinabalu had coordinates near Semporna, 300 km away. My import split places that span more than 60 km, so the site suddenly had two "Kota Kinabalu" pages with the same title. The fix was a rule rather than a list of exceptions: if the codes on both sides of a code (in code order) belong to a place, the code goes back to that place and takes the coordinates of its neighbor. In the first 13 countries this caught 17 codes in Malaysia, 12 in South Africa and 1 in Australia.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Companies that look like towns.&lt;/strong&gt; Germany has around 6 000 rows that are not places at all: postal codes of big companies and institutions, like "Deutsche Post AG Niederlassung BRIEF Cottbus", broadcasters, courts and ministries. They now are recognized by their names (legal forms, banks, courts, all-caps abbreviations) and become rows in a table on their city's page instead of fake towns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Codes without a point.&lt;/strong&gt; For Bulgaria I use a licensed source instead of GeoNames, which has only one code for Sofia. The real data has 86 codes for Sofia, but 84 of them are post offices without coordinates. A radius search used to say "1113 is not a postal code". Now such codes use the center of their place, and the page says so with an "≈".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Licences decide too.&lt;/strong&gt; Northern Ireland postcodes are in the ONS file, but not under the open licence, so the site shows the BT districts without the full postcodes. And 56 countries have no postal codes at all: they get one page that explains what to write in the postal code field of a form.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fast enough "nearby" on shared hosting
&lt;/h2&gt;

&lt;p&gt;Every place and code page lists the codes nearby. The first version searched a 30 km box, which in Singapore is almost the whole country: 121 135 codes, around 800 ms per page.&lt;/p&gt;

&lt;p&gt;Now it searches 1 km first, then 5 km, then 30 km, and stops as soon as it has enough codes, with an index on latitude and longitude. Pages dropped under 20 ms. The radius tool uses the same index in the shared search file: all of Singapore takes about 0.4 seconds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqndnxdgj9lefh62vi308.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqndnxdgj9lefh62vi308.png" alt="Zip codes within 10 miles of 10001, with the circle on the map" width="800" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  370 000 pages, indexed in waves
&lt;/h2&gt;

&lt;p&gt;A code gets its own page only when it is not one-to-one with a place; otherwise it is a row on the place page. With that rule the 105 countries make about 372 000 URLs in 108 sitemap files.&lt;/p&gt;

&lt;p&gt;They did not go into the sitemap at once. The first wave was 13 countries with the most searches; 92 more followed in the same week. Each country has a wave number, and pages of countries not yet released get &lt;code&gt;noindex&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For Bing and Seznam there is IndexNow. Instead of sending everything after each monthly import, the import takes a fingerprint of the country before and after: every page path maps to a hash of the data the page shows (the name, the region, the codes and their points, the link to the time page). New paths, paths with a different hash and removed paths go into a queue, and a daily cron job sends up to 10 000 of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Images from code
&lt;/h2&gt;

&lt;p&gt;Every place, code and tool page has its own Open Graph image. They are not files: PHP GD draws the name, the kind of page and the codes on a prepared background on the first request, and LiteSpeed caches the PNG for 30 days. Montserrat has no Arabic or CJK glyphs, so a page whose name would need them falls back to the general image instead of showing boxes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4fnrqn8mq4aw0uik8cfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4fnrqn8mq4aw0uik8cfi.png" alt="Images from code" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The rest
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The link between the two sites.&lt;/strong&gt; A place has the same path on both sites (&lt;code&gt;/united-states/new-york/buffalo&lt;/code&gt;), and the import writes a small SQLite file that WhatTimeIsIt reads: 23 014 of its places have the same place here and 12 127 link to the nearest one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests.&lt;/strong&gt; One PHP file with 408 checks, from the router and the importers to the exact robots.txt text, run before every merge. No PHPUnit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What would you do differently?
&lt;/h2&gt;

&lt;p&gt;The site is at &lt;a href="https://postalcodefinder.net" rel="noopener noreferrer"&gt;postalcodefinder.net&lt;/a&gt;, with the tools at &lt;a href="https://postalcodefinder.net/tools" rel="noopener noreferrer"&gt;/tools&lt;/a&gt;. I would love to hear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Would you keep one SQLite file per country, or one big database?&lt;/li&gt;
&lt;li&gt;Does IndexNow bring you anything measurable, compared to the sitemap alone?&lt;/li&gt;
&lt;li&gt;What would you want from a postal code site that the big ones do not do?&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>php</category>
      <category>sqlite</category>
    </item>
    <item>
      <title>A calculator with an expiry date: 3.3 million views for Bulgaria's switch from lev to euro</title>
      <dc:creator>Konstantin Iliev</dc:creator>
      <pubDate>Sat, 07 Nov 2026 11:00:40 +0000</pubDate>
      <link>https://dev.to/konstantin_iliev/a-calculator-with-an-expiry-date-33-million-views-for-bulgarias-switch-from-lev-to-euro-47b4</link>
      <guid>https://dev.to/konstantin_iliev/a-calculator-with-an-expiry-date-33-million-views-for-bulgarias-switch-from-lev-to-euro-47b4</guid>
      <description>&lt;p&gt;On 1 January 2026 Bulgaria replaced the lev with the euro. For about a year before and after that date, millions of people had the same small problem: how much is this in euro? How much was my salary in leva? Is this price right?&lt;/p&gt;

&lt;p&gt;In June 2025 I launched &lt;a href="https://eurocalculator.eu" rel="noopener noreferrer"&gt;eurocalculator.eu&lt;/a&gt;, a converter between the lev and the euro, in Bulgarian. It is about as simple as a website gets, and it has had 3.3 million page views from 309,000 users so far. Here is what building a site for a one-time event taught me.&lt;/p&gt;

&lt;h2&gt;
  
  
  The traffic curve of a one-time event
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F24u2zvec3drns63g42h4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F24u2zvec3drns63g42h4.png" alt="Google Analytics: page views per day from June 2025 to November 2026, with a peak of about 70,000 views a day in early January 2026" width="782" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The chart tells most of the story:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;June 2025:&lt;/strong&gt; the site goes live, seven months before the changeover.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;July 2025:&lt;/strong&gt; a first bump after EU finance ministers took the final decision on 8 July and confirmed the conversion rate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;August to December 2025:&lt;/strong&gt; a steady 5,000 to 10,000 views a day, with a clear weekly rhythm. Shops had to show prices in both currencies from 8 August, so people checked prices all the time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The first days of January 2026:&lt;/strong&gt; a spike to about 70,000 views a day.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;February 2026 onwards:&lt;/strong&gt; a long tail. Today it is about 2,000 views a day.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most of the traffic came in a few weeks around the changeover. If I had launched in December, the site would probably not have ranked in time. Launching early was the most important decision I made.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two inputs and one constant
&lt;/h2&gt;

&lt;p&gt;The conversion rate is fixed: &lt;strong&gt;1 EUR = 1.95583 BGN&lt;/strong&gt;. It is not a random number: the lev was pegged one to one to the Deutsche Mark, and 1.95583 is the rate at which the Mark was converted to the euro. So the core of the site is two inputs and a constant:&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="nx"&gt;exchangeRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.95583&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// fixed, never changes&lt;/span&gt;

&lt;span class="nx"&gt;bgnInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;bgn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bgnInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;eurInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bgn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bgn&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;exchangeRate&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toFixed&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type in either field and the other one updates. There is no server call, no API and no build step. The official rule is just as short: divide the lev amount by the full rate, without rounding the rate, and round the result to two decimals, rounding up when the third decimal is 5 or more.&lt;/p&gt;

&lt;p&gt;And yes, that is floating point with money. In this direction it is safe: since 195583 is odd, the exact result can never land on a half cent, so there is no tie for &lt;code&gt;toFixed()&lt;/code&gt; to get wrong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8k6ldr9rjxdhalyskk8c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8k6ldr9rjxdhalyskk8c.png" alt="The lev-to-euro calculator: 100 leva is 51.13 euro" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The rest of the page answers the questions people actually asked: why exactly 1.95583, how prices are recalculated, where to exchange leva, and whether prices would double (they didn't: in the countries that joined before Bulgaria the one-time effect was a few tenths of a percent).&lt;/p&gt;

&lt;p&gt;For the "how much did this go up?" part, a currency converter is not enough: you convert the old price to euro and then need the percentage change between the two prices. That is what my other small tool, &lt;a href="https://percentagecalculator.page/" rel="noopener noreferrer"&gt;Percentage Calculator&lt;/a&gt;, does with its increase and decrease mode, and the euro calculator links to it in the footer.&lt;/p&gt;

&lt;h2&gt;
  
  
  A feature built to be deleted
&lt;/h2&gt;

&lt;p&gt;In January 2026 both currencies were in circulation for one month. You could pay in leva, but the change came back in euro, unless the shop had no euro coins yet. That makes for some confusing moments at the till.&lt;/p&gt;

&lt;p&gt;So on 20 December 2025 I added a change calculator: enter the bill and the amount paid, each in leva or euro, and it shows the change in euro and its value in leva. The logic converts everything to euro first:&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="nx"&gt;billInEur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;billCurrency&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;EUR&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;paidInEur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;paidCurrency&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;EUR&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;change&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;paidInEur&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;billInEur&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;change&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;changeInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Not enough: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;format2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;change&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s2"&gt; € missing.`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;changeEur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;format2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;change&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;On 1 February 2026 the lev stopped being legal tender, and on 31 January I removed the change calculator. It lived for six weeks, and that was exactly right. Not every feature has to last forever, and it is easier to remove one when you knew from the start that you would.&lt;/p&gt;

&lt;h2&gt;
  
  
  Talking to users through the page
&lt;/h2&gt;

&lt;p&gt;A converter doesn't need a blog, but people had questions about the site itself. "Will the calculator still work in 2026?" came up again and again in the last days of December.&lt;/p&gt;

&lt;p&gt;So the home page has a short news section: the launch, the change calculator, the first million visits, its removal, and the answer to that question. Yes, it stays: people will need to convert old invoices, tax returns, salaries and pensions for years. Each news item is also a &lt;code&gt;BlogPosting&lt;/code&gt; in the page's schema.org data, and the questions and answers are a &lt;code&gt;FAQPage&lt;/code&gt;, so search engines can read them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Life after the changeover
&lt;/h2&gt;

&lt;p&gt;After January the main question disappeared, but the visitors kept asking for other currencies. In March 2026 I added seven new pairs: the euro against the US dollar, Turkish lira, British pound, Romanian leu, Czech koruna, Hungarian forint and Polish złoty.&lt;/p&gt;

&lt;p&gt;Unlike the lev, these rates change every day. The European Central Bank publishes its euro reference rates at around 16:00 CET on working days, and its Data Portal has a simple API that can return the latest value as CSV:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://data-api.ecb.europa.eu/service/data/EXR/D.USD.EUR.SP00.A'&lt;/span&gt;
     &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'?lastNObservations=1&amp;amp;format=csvdata'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$ch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;curl_init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;curl_setopt_array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;CURLOPT_RETURNTRANSFER&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;CURLOPT_TIMEOUT&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nv"&gt;$csv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;curl_exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ch&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$csv&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;curl_getinfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;CURLINFO_HTTP_CODE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// keep the last saved rate&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Line 0 is the header, line 1 holds the data:&lt;/span&gt;
&lt;span class="c1"&gt;// EXR.D.USD.EUR.SP00.A,D,USD,EUR,SP00,A,2026-11-06,1.1165,...&lt;/span&gt;
&lt;span class="nv"&gt;$lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;preg_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/\R/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$csv&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nv"&gt;$fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;str_getcsv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;is_numeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// TIME_PERIOD&lt;/span&gt;
&lt;span class="nv"&gt;$rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// OBS_VALUE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rate is saved in a small JSON file, so most visits just read the cache. After the publication time, a visit triggers a new request to the ECB. If the ECB can't be reached, the page keeps the last saved rate. If even that is missing, it uses an approximate rate. The page always says which one you are looking at: today's ECB reference rate, the last saved one, or an approximate rate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvticdluy837m6xyg5nn5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvticdluy837m6xyg5nn5.png" alt="The euro to Turkish lira calculator with the ECB reference rate" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Small touches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"Save the app" button.&lt;/strong&gt; The site is installable as a PWA. The button uses &lt;code&gt;beforeinstallprompt&lt;/code&gt; where the browser supports it, and otherwise shows short instructions: "Share, then Add to Home Screen" on iPhone, Ctrl+D elsewhere. For a tool people open again and again during a few months, being one tap away matters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A row of flags at the top&lt;/strong&gt; switches between the currency pairs. In a site with no menu, it is the navigation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;For an event with a date, launch months before it.&lt;/strong&gt; The traffic comes in a few weeks, and by then it is too late to start ranking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plan for the day after.&lt;/strong&gt; The first question goes away, but the visitors, the links and the trust stay. Ask them what they need next.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the URL alive.&lt;/strong&gt; Some people will need to convert an old lev amount for years.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simple is enough.&lt;/strong&gt; Two inputs, a constant and a few lines of JavaScript answered a question that 309,000 people had.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  And the money?
&lt;/h2&gt;

&lt;p&gt;The site runs Google AdSense with Auto ads, so Google decides where the ads go and I don't place them by hand. I won't share the exact amount, but so far it has earned a five-figure sum in US dollars. Not bad for two inputs and a constant.&lt;/p&gt;

&lt;p&gt;Have you built something for a one-time event? What did you do with it after the event was over? I'd love to hear in the comments.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I wrote this post with the help of, based on the site's code and my own data. I checked the facts and numbers before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>php</category>
    </item>
    <item>
      <title>A world clock that doesn't trust your clock: lessons from 64 500 city pages in plain PHP</title>
      <dc:creator>Konstantin Iliev</dc:creator>
      <pubDate>Fri, 06 Nov 2026 00:39:18 +0000</pubDate>
      <link>https://dev.to/konstantin_iliev/a-world-clock-that-doesnt-trust-your-clock-lessons-from-64-500-city-pages-in-plain-php-37a6</link>
      <guid>https://dev.to/konstantin_iliev/a-world-clock-that-doesnt-trust-your-clock-lessons-from-64-500-city-pages-in-plain-php-37a6</guid>
      <description>&lt;p&gt;I built &lt;a href="https://whattimeisit.zone" rel="noopener noreferrer"&gt;WhatTimeIsIt.zone&lt;/a&gt;, a site that answers one question for about 64 500 places in 245 countries and territories: what time is it there right now? Each place has its own page with the time, the time zone, the next clock change, sunrise and sunset, the moon, the weather and the next public holiday. There are also 25+ small tools (a time zone converter, a time zone map, holidays in 247 countries, calendars and so on), in English and Bulgarian.&lt;/p&gt;

&lt;p&gt;The stack is deliberately boring: plain PHP 8 and MariaDB on a shared hosting plan with LiteSpeed, no framework, no front-end framework, a few small vanilla JavaScript files. A &lt;code&gt;git push&lt;/code&gt; to &lt;code&gt;main&lt;/code&gt; deploys it.&lt;/p&gt;

&lt;p&gt;"Show the time" sounds like a one-liner, but it turned out to be full of small traps. Here are the ones I found most interesting.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Your device clock is often wrong, so measure it
&lt;/h2&gt;

&lt;p&gt;A clock in the browser is only as good as &lt;code&gt;Date.now()&lt;/code&gt;, and the device clock can be off by seconds or even minutes. So the page measures it. It asks the server for the time five times and keeps the answer with the fastest round trip, because that one has the smallest error:&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;function&lt;/span&gt; &lt;span class="nf"&gt;sync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;one&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/time&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no-store&lt;/span&gt;&lt;span class="dl"&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;rtt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;t0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// The server's time when the answer arrived, minus the device time&lt;/span&gt;
        &lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;rtt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;rtt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;skew&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;rtt&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;one&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;done&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;samples&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The skew is then added to every tick of the clock, and the page tells you the result: "Your clock is exact (±0.01 s)" or "Your clock is 1.3 s fast". The precision is half of the best round trip. When you come back to the tab after more than ten minutes, it measures again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodslhzg3doxriqn6cbx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodslhzg3doxriqn6cbx7.png" alt="The clock for London with the line &amp;quot;Your clock is exact (±0.01 s)&amp;quot;" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Your browser's time zone data can be out of date too
&lt;/h2&gt;

&lt;p&gt;This one surprised me. &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; uses the time zone database that ships with the browser's copy of ICU, and that copy can be years old. While testing I found that with ICU 74 (time zone data 2023c), Kazakhstan was an hour ahead (it moved to a single UTC+5 in 2024), and Morocco, British Columbia and Paraguay were wrong after their recent changes. A newer zone such as &lt;code&gt;America/Coyhaique&lt;/code&gt; (2025) was simply unknown.&lt;/p&gt;

&lt;p&gt;The same applies on the server: PHP's &lt;code&gt;intl&lt;/code&gt; extension has its own ICU copy, separate from the IANA database that &lt;code&gt;DateTimeZone&lt;/code&gt; uses.&lt;/p&gt;

&lt;p&gt;So the site has one source of truth: the IANA database bundled with PHP, which I keep up to date (a weekly job reports which version the hosting runs). The server computes the offset; ICU only formats. In the browser, each page carries the offsets of the zones it shows: the current one and any change in the next three days. The clock never asks the browser what the offset is:&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="c1"&gt;// Z = { "Asia/Almaty": [300], "Europe/London": [0], ... }&lt;/span&gt;
&lt;span class="c1"&gt;// A zone with a change in the next 3 days also gets [moment in ms, new offset],&lt;/span&gt;
&lt;span class="c1"&gt;// e.g. on 26 March 2027: "Europe/London": [0, [1806195600000, 60]]&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;zoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tz&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Z&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tz&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// With a known offset, shift the moment and let Intl format it as UTC&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tz&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;zoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tz&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tz&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="nx"&gt;ts&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="nx"&gt;e4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UTC&lt;/span&gt;&lt;span class="dl"&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;Zone names from ICU ("Eastern European Summer Time") are shown only when ICU agrees with PHP on the offset. Otherwise the name could be wrong too.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. PHP's sunrise was a minute or two off
&lt;/h2&gt;

&lt;p&gt;Every page shows sunrise and sunset, computed on the server with no API. I started with PHP's &lt;code&gt;date_sun_info()&lt;/code&gt; and then checked it against independent astronomy libraries. In my tests, PHP returned sunrise and sunset when the sun was about 1.1° below the horizon, instead of the standard 0.833° (atmospheric refraction plus the radius of the sun's disc). That is 1 to 2 minutes of difference, which is exactly the kind of thing people notice on a site about time. The site now refines both moments to −0.833°.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Cleaning up 64 500 place names
&lt;/h2&gt;

&lt;p&gt;The places come from GeoNames. It is a great dataset, but in countries with a non-Latin script it writes names in a scholarly transcription: Thāne, Ghāziābād, Orël, Pátra, Ḩamāh. English speakers (and Wikipedia) write Thane, Ghaziabad, Oryol, Patras, Hama.&lt;/p&gt;

&lt;p&gt;GeoNames also links many places to their English Wikipedia article, so the title of that article is a good English name. But you can't take it blindly. When I tried it on every country, I got Potenza → Potentia (the link pointed to the ancient city), Svoge → Svogue and Middletown → Middletown Township. So the rule is narrow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;only for names with these marks, in countries whose script is not Latin (Japan is left out: Wikipedia writes Kōfu too);&lt;/li&gt;
&lt;li&gt;take the Wikipedia title if it is the same name once the marks are removed, or a very close spelling;&lt;/li&gt;
&lt;li&gt;accept a more distant spelling (Orël → Oryol) only if the GeoNames English name agrees;&lt;/li&gt;
&lt;li&gt;reject titles about something else: a district, an airport, a bigger city;&lt;/li&gt;
&lt;li&gt;otherwise just remove the marks (Bārākpur → Barakpur).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The comparison folds both names first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;\Normalizer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;\Normalizer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;FORM_D&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;mb_strtolower&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;preg_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/\p{Mn}+/u'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// drop the marks&lt;/span&gt;
    &lt;span class="nv"&gt;$s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;preg_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/[‘’'`ʻʼ]/u"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;             &lt;span class="c1"&gt;// and apostrophes&lt;/span&gt;
    &lt;span class="nv"&gt;$s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;preg_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/[\-–.]/u'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;preg_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/\s+/u'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$s&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;Before writing anything, I ran the rules as a Python prototype on all places, then ported them to PHP and checked that both gave exactly the same 5 501 changes: 3 469 names from Wikipedia, 120 from GeoNames and 1 912 with the marks removed. The URLs did not change, since addresses on the site are permanent.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A second language with 58 000 names nobody wrote
&lt;/h2&gt;

&lt;p&gt;The Bulgarian version needs every place name in Cyrillic. GeoNames has a real Bulgarian name for about 10% of the places, so the rest are transliterated: from the Ukrainian, Serbian, Greek or Russian name where it exists (never Russian for places in Ukraine), otherwise from the Latin name with rules for the language of each country (Spanish, Polish, pinyin and so on). English words in names follow Bulgarian spelling rules too, so "Village" doesn't come out letter by letter.&lt;/p&gt;

&lt;p&gt;Compared with the 6 641 places that do have a real Bulgarian name, 63% of the automatic names match exactly and 93% differ by at most two letters. Not perfect, but much better than showing Latin letters on a Bulgarian page.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Small things that kept it fast
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Each page carries only its own CSS&lt;/strong&gt;, inlined. A tool page gets the shared styles plus its own file, nothing else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The day and night map on the home page uses no map library.&lt;/strong&gt; The land is a 39 KB SVG (10 KB compressed) from Natural Earth via world-atlas, and the night is computed from the sun's position in three steps: below the horizon, civil and nautical twilight.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Best time to call" is 24 grid cells and a line of text.&lt;/strong&gt; The page shows the city's working day next to yours and the hours you share.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxad2yucxeitu092arzaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxad2yucxeitu092arzaf.png" alt="The day and night map with the largest cities" width="799" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp0pqh9s93tqcvs5we6e8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp0pqh9s93tqcvs5we6e8.png" alt="The &amp;quot;Best time to call London&amp;quot; block: 24 hours for London and for the visitor" width="799" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The site is also an installable PWA that keeps working offline, and a &lt;a href="https://apps.microsoft.com/detail/9PG7RTZC69B6" rel="noopener noreferrer"&gt;Windows app in the Microsoft Store&lt;/a&gt;. The Store app is a PWABuilder package that opens the live site, so changes to the site need no new package.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd like to hear
&lt;/h2&gt;

&lt;p&gt;If you have run into stale time zone data in a browser or on a server, I'd love to hear how you dealt with it. And if a time tool you need is missing, tell me in the comments.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I wrote this post with the help of AI, based on the project's code and my notes. I checked the facts and numbers before publishing.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>php</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
