<?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: Nomad Wozo</title>
    <description>The latest articles on DEV Community by Nomad Wozo (@wozo).</description>
    <link>https://dev.to/wozo</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%2F4180682%2F3c234f3f-1bb1-458e-973d-d8d64d64f436.jpg</url>
      <title>DEV Community: Nomad Wozo</title>
      <link>https://dev.to/wozo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wozo"/>
    <language>en</language>
    <item>
      <title>Calculating Credit Card Interest in JavaScript: Average Daily Balance and the Daily Periodic Rate</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Sun, 29 Nov 2026 20:15:09 +0000</pubDate>
      <link>https://dev.to/wozo/calculating-credit-card-interest-in-javascript-average-daily-balance-and-the-daily-periodic-rate-366a</link>
      <guid>https://dev.to/wozo/calculating-credit-card-interest-in-javascript-average-daily-balance-and-the-daily-periodic-rate-366a</guid>
      <description>&lt;p&gt;A monthly interest shortcut — take the statement balance, multiply by the APR, divide by 12 — is easy to write and usually wrong. Many credit card issuers figure the finance charge from an &lt;strong&gt;average daily balance&lt;/strong&gt; and a &lt;strong&gt;daily periodic rate&lt;/strong&gt;. The Consumer Financial Protection Bureau (CFPB) puts the practical consequence in plain language: because interest accrues daily, not monthly, if you don't have a grace period, the sooner you pay off all or some of your balance, the less interest you will pay.&lt;/p&gt;

&lt;p&gt;This article walks through that calculation in JavaScript, using integer cents and a hypothetical billing cycle. It is a teaching model, not a replica of any issuer's system. Real methods vary, and the cardholder agreement is the source that applies to a given account. This is general information about a common calculation method, not financial, legal, or tax advice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two rates, and the average
&lt;/h2&gt;

&lt;p&gt;The APR on a credit card is an annualized rate. The rate that actually gets applied day by day is the daily periodic rate. According to the CFPB, that daily rate generally can be calculated by dividing the APR by either 360 or 365, depending on the card issuer. The CFPB's model credit-card contract definitions use 365: the daily periodic rate for a balance equals the APR for that balance divided by 365. The code below follows that 365-day convention.&lt;/p&gt;

&lt;p&gt;The average daily balance method, in those same model definitions, works like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For each day in the billing cycle, start with that balance's beginning amount, add new charges, and subtract payments or credits. That is the day's daily balance.&lt;/li&gt;
&lt;li&gt;Add the daily balances and divide by the number of days in the billing period. That is the average daily balance.&lt;/li&gt;
&lt;li&gt;Apply the daily periodic rate to the average daily balance, then multiply by the number of days in the cycle. That is the interest charge for that balance for that period.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The model definitions describe a version that also adds the prior day's interest into the daily balance (daily compounding) and a version that does not. The worked code is the version without compounding. In that version, &lt;code&gt;average daily balance × daily periodic rate × days&lt;/code&gt; equals &lt;code&gt;sum of daily balances × daily periodic rate&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the balances in integer cents
&lt;/h2&gt;

&lt;p&gt;Each day's balance is an amount of money, so it belongs in integer cents. The average of those balances may not be. In the example below it is $45,500.00 / 30, or $1,516.66.... If you round that average to $1,516.67 and only then apply the rate, you have introduced a rounding decision the method does not ask for. Compute the finance charge from the &lt;strong&gt;sum&lt;/strong&gt; of the daily balances and round once, at the end, to the nearest cent.&lt;/p&gt;

&lt;p&gt;Because the charge is &lt;code&gt;sum × APR / 365&lt;/code&gt;, the arithmetic can stay in integers with a half-up rational multiply. 21.99% is exactly 2199 / 10000.&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;mulDivRoundHalfUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;den&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Non-negative integer (n * num / den), rounded half up.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&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;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;den&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="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="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dailyBalancesCents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;startCents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;events&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;net&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&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="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fill&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="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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cents&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;cents&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;balances&lt;/span&gt; &lt;span class="o"&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="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;bal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;startCents&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="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;day&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="n"&gt;day&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;bal&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="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="n"&gt;bal&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="n"&gt;bal&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="c1"&gt;// no negative interest on a credit balance here&lt;/span&gt;
    &lt;span class="n"&gt;balances&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="n"&gt;bal&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balances&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;financeChargeCents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aprNum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aprDen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;daysInYear&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;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balances&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&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="o"&gt;=&amp;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="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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;sumCents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;interestCents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;mulDivRoundHalfUp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aprNum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aprDen&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;daysInYear&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A payment is a negative &lt;code&gt;cents&lt;/code&gt; value on the day it posts; a purchase is a positive one. A credit balance is an amount the issuer owes the cardholder, so this sketch floors the daily balance at zero and charges no interest in that case.&lt;/p&gt;

&lt;h2&gt;
  
  
  A hypothetical cycle, paid early and paid late
&lt;/h2&gt;

&lt;p&gt;All of the following figures are hypothetical. They are not from a statement.&lt;/p&gt;

&lt;p&gt;Take a 30-day billing cycle with a $2,000.00 purchase balance already on the account at the start of day 1, a 21.99% APR, and a daily periodic rate of APR / 365. There is no grace period, so interest accrues on that balance each day. No new purchases post during the cycle. A $500.00 payment posts either on day 2 or on day 28.&lt;/p&gt;

&lt;p&gt;Running the functions above (Node 24) produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Payment of $500.00 posts on day 2:
  sum of daily balances: $45,500.00
  average daily balance: $1,516.66... ($45,500.00 / 30)
  finance charge: $27.41
Payment of $500.00 posts on day 28:
  sum of daily balances: $58,500.00
  average daily balance: $1,950.00
  finance charge: $35.24
Difference (late minus early): $7.83
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The early payment leaves $2,000.00 on the account for one day and $1,500.00 for the other 29, so the sum of daily balances is $2,000.00 + 29 × $1,500.00 = $45,500.00. The late payment leaves $2,000.00 on the account for 27 days and $1,500.00 for three, so the sum is $58,500.00. Same starting balance, same payment, same APR, same 30 days — $7.83 more interest because the $500.00 stayed on the account for 26 extra days.&lt;/p&gt;

&lt;p&gt;The same run also prints $36.15 with no payment on a constant $2,000.00 balance, $36.65 for &lt;code&gt;starting balance × APR / 12&lt;/code&gt;, and $27.49 for &lt;code&gt;ending balance × APR / 12&lt;/code&gt;. Neither monthly shortcut changes when the payment posts. $36.65 also differs from the no-payment charge because a 30-day cycle is not 1/12 of a 365-day year. $27.49 is close to the early-payment charge by coincidence, and too low once the payment is late.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where a grace period changes the picture
&lt;/h2&gt;

&lt;p&gt;A grace period, as the CFPB defines it, is the period between the end of a billing cycle and the payment due date. During that time you may not be charged interest if you pay the balance in full by the due date. Issuers are not required to offer one, though most credit cards provide a grace period on purchases. It typically does not apply to cash advances, which generally begin accruing interest on the transaction date.&lt;/p&gt;

&lt;p&gt;If a card has a grace period and the balance is paid in full by the due date each month, the finance charge on purchases is $0. If the grace period is lost because the balance was not paid in full, the CFPB notes that interest is charged on the unpaid portion, and that interest on purchases in the new cycle generally starts on the date each purchase is made.&lt;/p&gt;

&lt;p&gt;Regulation Z, 12 CFR 1026.54, does not require a grace period. It does limit what an issuer may do after a grace period is lost: it may not impose finance charges based on balances from billing cycles before the most recent one (the two-cycle or "double-cycle" method), and it may not charge interest on the portion of a balance subject to a grace period that was repaid before that grace period expired.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this model leaves out
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;360 versus 365.&lt;/strong&gt; Swap the day-count to 360 and the same hypothetical charges become $27.79 and $35.73. The cardholder agreement says which divisor the issuer uses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Daily compounding.&lt;/strong&gt; Under the CFPB model definition that adds the prior day's interest into the daily balance, the finance charge on this same example is a little higher. The method is different; the timing effect is the same.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Several APRs at once.&lt;/strong&gt; Purchases, cash advances, and balance transfers often have different rates, each with its own daily balance. The statement has to show each category.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payment allocation.&lt;/strong&gt; When a payment is more than the minimum, federal rules generally require the excess to go to the highest-APR balance first. That is a separate problem from computing the average daily balance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Posting, cutoffs, and fees.&lt;/strong&gt; The day that matters is the day the issuer posts the transaction, subject to the account's payment instructions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Integer cents and an explicit day count are the same habits that belong in any in-browser interest calculator. They are the approach used in the loan and compound-interest tools at &lt;a href="https://finance.wooooju.com" rel="noopener noreferrer"&gt;FINORA&lt;/a&gt;, a set of free calculators that run in the browser. For a real account, start from that account's cardholder agreement, not from a default of 365 and not from &lt;code&gt;APR / 12&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;CFPB, "How does my credit card company calculate the amount of interest I owe?" &lt;a href="https://www.consumerfinance.gov/ask-cfpb/how-does-my-credit-card-company-calculate-the-amount-of-interest-i-owe-en-51/" rel="noopener noreferrer"&gt;https://www.consumerfinance.gov/ask-cfpb/how-does-my-credit-card-company-calculate-the-amount-of-interest-i-owe-en-51/&lt;/a&gt; (accessed Nov 29, 2026)&lt;/li&gt;
&lt;li&gt;CFPB, "What is a \"daily periodic rate\" on a credit card?" &lt;a href="https://www.consumerfinance.gov/ask-cfpb/what-is-a-daily-periodic-rate-on-a-credit-card-en-46/" rel="noopener noreferrer"&gt;https://www.consumerfinance.gov/ask-cfpb/what-is-a-daily-periodic-rate-on-a-credit-card-en-46/&lt;/a&gt; (accessed Nov 29, 2026)&lt;/li&gt;
&lt;li&gt;CFPB, "What is a grace period for a credit card?" &lt;a href="https://www.consumerfinance.gov/ask-cfpb/what-is-a-grace-period-for-a-credit-card-en-47/" rel="noopener noreferrer"&gt;https://www.consumerfinance.gov/ask-cfpb/what-is-a-grace-period-for-a-credit-card-en-47/&lt;/a&gt; (accessed Nov 29, 2026)&lt;/li&gt;
&lt;li&gt;CFPB, "Credit cards key terms" &lt;a href="https://www.consumerfinance.gov/consumer-tools/credit-cards/answers/key-terms/" rel="noopener noreferrer"&gt;https://www.consumerfinance.gov/consumer-tools/credit-cards/answers/key-terms/&lt;/a&gt; (accessed Nov 29, 2026)&lt;/li&gt;
&lt;li&gt;CFPB, "Credit card contract definitions" &lt;a href="https://www.consumerfinance.gov/data-research/credit-card-data/know-you-owe-credit-cards/credit-card-contract-definitions/" rel="noopener noreferrer"&gt;https://www.consumerfinance.gov/data-research/credit-card-data/know-you-owe-credit-cards/credit-card-contract-definitions/&lt;/a&gt; (accessed Nov 29, 2026)&lt;/li&gt;
&lt;li&gt;CFPB, 12 CFR 1026.54, "Limitations on the imposition of finance charges" &lt;a href="https://www.consumerfinance.gov/rules-policy/regulations/1026/54/" rel="noopener noreferrer"&gt;https://www.consumerfinance.gov/rules-policy/regulations/1026/54/&lt;/a&gt; (accessed Nov 29, 2026)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>finance</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A Holiday Flag Isn't Enough: Modeling Early Closes in a Business-Day Cutoff (NYSE vs. SIFMA, Dec 2026)</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Sat, 28 Nov 2026 20:14:50 +0000</pubDate>
      <link>https://dev.to/wozo/a-holiday-flag-isnt-enough-modeling-early-closes-in-a-business-day-cutoff-nyse-vs-sifma-dec-dn0</link>
      <guid>https://dev.to/wozo/a-holiday-flag-isnt-enough-modeling-early-closes-in-a-business-day-cutoff-nyse-vs-sifma-dec-dn0</guid>
      <description>&lt;p&gt;Most business-day code asks one question about a date: &lt;em&gt;is it a holiday?&lt;/em&gt; That works for "add 3 business days." It breaks the moment your rule has a &lt;strong&gt;cutoff time&lt;/strong&gt;, because some days are neither fully open nor fully closed.&lt;/p&gt;

&lt;p&gt;Christmas Eve 2026 is the clean example. It's a Thursday, not a holiday, and still the U.S. stock market closes early. Whether an order or request submitted at 1:30 p.m. Eastern counts for that day or for the next one depends on a close time that a boolean holiday flag can't hold.&lt;/p&gt;

&lt;p&gt;This post covers what the official calendars say, how two of them disagree on the same day, and a small Python model that gets the cutoff right. Every output below came from a real run of the script (Python 3.13, &lt;code&gt;zoneinfo&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  What the official calendars say
&lt;/h2&gt;

&lt;p&gt;The NYSE publishes its holiday and early-close calendar on its &lt;a href="https://www.nyse.com/trade/hours-calendars" rel="noopener noreferrer"&gt;Holidays &amp;amp; Trading Hours page&lt;/a&gt;. For the 2026–2028 table, its footnotes say each market closes early at 1:00 p.m. ET (1:15 p.m. for eligible options) on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Friday, November 27, 2026 (day after Thanksgiving)&lt;/li&gt;
&lt;li&gt;Thursday, December 24, 2026&lt;/li&gt;
&lt;li&gt;Friday, November 26, 2027&lt;/li&gt;
&lt;li&gt;Monday, July 3, 2028&lt;/li&gt;
&lt;li&gt;Friday, November 24, 2028&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same page lists the regular core session as 9:30 a.m. to 4:00 p.m. ET. It also notes that some NYSE venues' late trading sessions close at 5:00 p.m. on early-close days, so "the market closed at 1:00" is only true of the core session.&lt;/p&gt;

&lt;p&gt;The bond market keeps a different list. SIFMA's &lt;a href="https://www.sifma.org/resources/guides-playbooks/holiday-schedule" rel="noopener noreferrer"&gt;U.S. holiday schedule&lt;/a&gt; recommends 2:00 p.m. ET early closes on May 22, July 2, November 27, December 24 and December 31, 2026, and a 12:00 p.m. ET early close on Good Friday, April 3, 2026. SIFMA describes these as recommendations that apply to U.S. dollar fixed-income trading, and says early closes don't change the closing time for settlements.&lt;/p&gt;

&lt;p&gt;Putting the two side by side for 2026:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fri 2026-04-03  NYSE: closed       SIFMA: early 12:00
Fri 2026-05-22  NYSE: open 16:00   SIFMA: early 14:00
Thu 2026-07-02  NYSE: open 16:00   SIFMA: early 14:00
Fri 2026-11-27  NYSE: early 13:00  SIFMA: early 14:00
Thu 2026-12-24  NYSE: early 13:00  SIFMA: early 14:00
Thu 2026-12-31  NYSE: open 16:00   SIFMA: early 14:00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things stand out. On Good Friday the NYSE is closed while SIFMA recommends a short bond session. On May 22, July 2 and December 31 the NYSE table shows no early close at all, but SIFMA does. And on the two days both have a half day, the times differ by an hour. "Is the market open?" has no single answer; the question needs a venue.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug: a flat 4:00 p.m. rule
&lt;/h2&gt;

&lt;p&gt;Here's the common shape of the bug:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;counts_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;date&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="nf"&gt;is_closed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&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="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&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="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;next_open_day&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It treats every open day as having the same close. For a timestamp of 1:30 p.m. ET on December 24, 2026, it says "still open."&lt;/p&gt;

&lt;h2&gt;
  
  
  A model with a close time per date
&lt;/h2&gt;

&lt;p&gt;Store a &lt;em&gt;session&lt;/em&gt; per date instead of a flag: open (with a close time), early (with a different close time), or closed. Keep a calendar per venue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;          &lt;span class="c1"&gt;# "open", "early", "closed"&lt;/span&gt;
    &lt;span class="n"&gt;close&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;   &lt;span class="c1"&gt;# local close time, None if closed&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;nyse_session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;weekday&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="mi"&gt;5&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;NYSE_CLOSED&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"closed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;NYSE_EARLY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"early"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;NYSE_EARLY&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"open"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;NYSE_REGULAR_CLOSE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;counts_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;session_fn&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;nyse_session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""First day whose session is still open at ts (ts carries a time zone)."""&lt;/span&gt;
    &lt;span class="n"&gt;local&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;astimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ET&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;           &lt;span class="c1"&gt;# ET = ZoneInfo("America/New_York")&lt;/span&gt;
    &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;session_fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"closed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&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;lt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;close&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;d&lt;/span&gt;
        &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter. The comparison is against the close time &lt;em&gt;of that date&lt;/em&gt;, not a constant. And the timestamp is converted to the venue's zone first, so a caller in Seoul or London gets the same answer as one in New York.&lt;/p&gt;

&lt;p&gt;Running it for a 1:30 p.m. ET order on Thursday, December 24, 2026:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;naive 4:00 p.m. rule  -&amp;gt; Thu 2026-12-24
with the early close  -&amp;gt; Mon 2026-12-28
12:59 p.m. ET         -&amp;gt; Thu 2026-12-24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next open day is Monday, December 28, because Friday the 25th is the Christmas holiday on the NYSE table and the 26th and 27th are a weekend. The naive rule is wrong by a full business day, and the error only shows up on the handful of days each year when it matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Half days across the year-end boundary
&lt;/h2&gt;

&lt;p&gt;The 2027 table has a quirk worth testing. Christmas Day falls on a Saturday, so the NYSE closes on Friday, December 24, 2027, and the NYSE table lists no early close for the Thursday before it. Then in 2028, because January 1 is a Saturday, the NYSE page says no New Year's Day holiday is observed, so December 31, 2027 is an ordinary trading day.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thu 2027-12-23 17:00 ET -&amp;gt; counts for Mon 2027-12-27
Fri 2027-12-31 10:00 ET -&amp;gt; counts for Fri 2027-12-31
Fri 2027-12-31 17:00 ET -&amp;gt; counts for Mon 2028-01-03
NYSE Fri 2027-12-24: closed | Fri 2027-12-31: open
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The after-Thanksgiving half day behaves the same way. One minute either side of the 1:00 p.m. close flips the answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fri 2026-11-27 13:01 ET -&amp;gt; counts for Mon 2026-11-30
Fri 2027-11-26 12:59 ET -&amp;gt; counts for Fri 2027-11-26
Fri 2027-11-26 13:01 ET -&amp;gt; counts for Mon 2027-11-29
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Store the venue's local time, not a UTC instant
&lt;/h2&gt;

&lt;p&gt;It's tempting to store each early close as a UTC time. Don't. The rule is "1:00 p.m. in New York," and the UTC equivalent moves with daylight saving time. The script converts two early-close moments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thu 2026-12-24 13:00 ET (EST)
   UTC            Thu 2026-12-24 18:00 UTC
   Europe/London  Thu 2026-12-24 18:00 GMT
   Asia/Seoul     Fri 2026-12-25 03:00 KST
   Asia/Tokyo     Fri 2026-12-25 03:00 JST
Mon 2028-07-03 13:00 ET (EDT)
   UTC            Mon 2028-07-03 17:00 UTC
   Europe/London  Mon 2028-07-03 18:00 BST
   Asia/Seoul     Tue 2028-07-04 02:00 KST
   Asia/Tokyo     Tue 2028-07-04 02:00 JST
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same local close is 18:00 UTC in winter and 17:00 UTC in summer. For anyone east of Greenwich, it also lands on the &lt;em&gt;next calendar date&lt;/em&gt;. If a dashboard or SLA shows "closes 03:00 KST on the 25th," the business date that belongs to that session is still the 24th in New York. Keep the business date (venue-local) and the instant as two separate fields.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Model a &lt;strong&gt;session per date&lt;/strong&gt; (open / early / closed with a close time), not a holiday boolean.&lt;/li&gt;
&lt;li&gt;Keep &lt;strong&gt;one calendar per venue or rule set&lt;/strong&gt;. NYSE, SIFMA's bond recommendations, banks and your own business each have different lists.&lt;/li&gt;
&lt;li&gt;Treat recommendations as recommendations. SIFMA says its early closes are not mandates, so make the close time configurable.&lt;/li&gt;
&lt;li&gt;Compare &lt;strong&gt;in the venue's zone&lt;/strong&gt;, and store the close as a local time plus a zone name.&lt;/li&gt;
&lt;li&gt;Re-copy the dates from the publisher each year, and assert that every date is the weekday you expect. My script does that for every table entry.&lt;/li&gt;
&lt;li&gt;Note what you left out. This model covers the NYSE core session only, not late sessions or options.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Counting days after the cutoff
&lt;/h2&gt;

&lt;p&gt;Once the cutoff logic has told you which business day a request counts for, you usually still have to count forward, for example "three business days after that." For that part I use a plain date-level calculator where you enter your own closures, &lt;a href="https://workdays.wooooju.com/en/" rel="noopener noreferrer"&gt;WorkdayMap&lt;/a&gt;. It doesn't model times of day, which is why the session model above is a separate step.&lt;/p&gt;

&lt;p&gt;If you have a cutoff rule that doesn't fit a per-date close time, I'd like to hear about it in the comments.&lt;/p&gt;

</description>
      <category>python</category>
      <category>datetime</category>
      <category>timezones</category>
      <category>fintech</category>
    </item>
    <item>
      <title>Formatting Timer Readouts with Intl.DurationFormat: What It Does and What It Leaves to You</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Fri, 27 Nov 2026 20:17:47 +0000</pubDate>
      <link>https://dev.to/wozo/formatting-timer-readouts-with-intldurationformat-what-it-does-and-what-it-leaves-to-you-a2p</link>
      <guid>https://dev.to/wozo/formatting-timer-readouts-with-intldurationformat-what-it-does-and-what-it-leaves-to-you-a2p</guid>
      <description>&lt;p&gt;Most timer readouts are built from &lt;code&gt;padStart(2, "0")&lt;/code&gt; and a colon. That works until you want localized digits, or a spoken-friendly string like "25 minutes". &lt;code&gt;Intl.DurationFormat&lt;/code&gt; covers both, and MDN labels it Baseline 2025: "Since March 2025, this feature works across the latest devices and browser versions."&lt;/p&gt;

&lt;p&gt;I tried it on a timer readout and found four places where it does less than you might assume, plus one engine difference I measured. Everything below ran on Node 24.22.1 and desktop Chrome 156 on Linux. I did not test Firefox or Safari, and I only used the &lt;code&gt;en&lt;/code&gt; locale unless noted.&lt;/p&gt;

&lt;h2&gt;
  
  
  The basic readout
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;digital&lt;/code&gt; style prints &lt;code&gt;1:50:00&lt;/code&gt;-style output. With only &lt;code&gt;style: "digital"&lt;/code&gt;, five seconds comes out as &lt;code&gt;0:00:05&lt;/code&gt;. Adding &lt;code&gt;hoursDisplay: "auto"&lt;/code&gt; hides the hours until they are nonzero: &lt;code&gt;00:05&lt;/code&gt;, then &lt;code&gt;1:00:03&lt;/code&gt;.&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;splitMs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalMs&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;sign&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;totalMs&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="o"&gt;?&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;rest&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalMs&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hours&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3_600_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;%=&lt;/span&gt; &lt;span class="mi"&gt;3_600_000&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;minutes&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;60_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;%=&lt;/span&gt; &lt;span class="mi"&gt;60_000&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;seconds&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&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;milliseconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&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;hours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;hours&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;milliseconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;milliseconds&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;clock&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;DurationFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"digital"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;hoursDisplay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"auto"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Elapsed: truncate to whole seconds, or any nonzero milliseconds get printed.&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;formatElapsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;splitMs&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Countdown: round up so the readout reaches 00:00 at the deadline.&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;formatRemaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;splitMs&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;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&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;Each line of that helper exists because of one of the points below.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. It does not carry
&lt;/h2&gt;

&lt;p&gt;Pass &lt;code&gt;{ seconds: 125 }&lt;/code&gt; and you get &lt;code&gt;00:125&lt;/code&gt;, not &lt;code&gt;02:05&lt;/code&gt;. The formatter prints the fields you give it. That is why &lt;code&gt;splitMs&lt;/code&gt; exists. MDN says &lt;code&gt;format()&lt;/code&gt; also accepts a &lt;code&gt;Temporal.Duration&lt;/code&gt;; I did not try that.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Nonzero milliseconds show up uninvited
&lt;/h2&gt;

&lt;p&gt;Feed &lt;code&gt;splitMs(125123)&lt;/code&gt; straight in and the readout is &lt;code&gt;02:05.123&lt;/code&gt;. The milliseconds unit is displayed whenever it is nonzero. If your display stops at seconds, cut the value to whole seconds first, as &lt;code&gt;formatElapsed&lt;/code&gt; does.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. It truncates, so choose floor or ceiling on purpose
&lt;/h2&gt;

&lt;p&gt;MDN's constructor page says fractional units are formatted with &lt;code&gt;roundingMode: "trunc"&lt;/code&gt;, and ECMA-402 sets the same &lt;code&gt;"trunc"&lt;/code&gt; rounding mode in its number-formatting steps for these fields. The formatter never rounds up. With &lt;code&gt;fractionalDigits: 0&lt;/code&gt;, 2 seconds and 990 ms printed as &lt;code&gt;0:00:02&lt;/code&gt; for me. For a stopwatch that matches intuition: 1.9 seconds reads &lt;code&gt;00:01&lt;/code&gt;. For a countdown, truncation means the last second reads &lt;code&gt;00:00&lt;/code&gt; while 0.9 seconds remain. So &lt;code&gt;formatRemaining&lt;/code&gt; rounds up before formatting, and &lt;code&gt;formatRemaining(900)&lt;/code&gt; returns &lt;code&gt;00:01&lt;/code&gt;. That is my design choice, not a rule from the spec. Pick one convention and use it everywhere, because a readout that flips between the two will look wrong next to the real deadline.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Signs must agree, and integers only
&lt;/h2&gt;

&lt;p&gt;MDN: "Each property's value should be an integer, and their signs should be consistent." Both &lt;code&gt;{ minutes: 1, seconds: -5 }&lt;/code&gt; and &lt;code&gt;{ seconds: 1.5 }&lt;/code&gt; threw a &lt;code&gt;RangeError&lt;/code&gt; for me. The spec's &lt;code&gt;IsValidDuration&lt;/code&gt; step is what rejects mixed signs. For overtime, negate every field, which &lt;code&gt;splitMs&lt;/code&gt; does: &lt;code&gt;formatRemaining(-1500)&lt;/code&gt; gives &lt;code&gt;-00:01&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The off-by-one I measured
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;fractionalDigits&lt;/code&gt; accepts 0 to 9. I swept every combination of 60 seconds and 1,000 milliseconds (60,000 inputs, minute zero, &lt;code&gt;en&lt;/code&gt;) at 0, 1, 2, and 3 fractional digits, and compared each result with a string built by slicing integer digits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome 156: 0 mismatches at every setting.&lt;/li&gt;
&lt;li&gt;Node 24.22.1 (V8 13.6.233.17-node.58): 0 mismatches at 0 and 1 digits, 21 at 2 digits, 396 at 3 digits. Every miss was one low in the last place. One second and 360 ms with two digits printed &lt;code&gt;1.35&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The spec works with exact mathematical values here and a related validity check carries a note that its sum "cannot be implemented directly using floating-point arithmetic." I can't tell you which engine versions have the problem; I have two data points. If you show hundredths, test your targets, or build the fraction yourself:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;splitMs&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./splitMs.js"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;makeCentiFormatter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&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;clock&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;DurationFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"digital"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hoursDisplay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"auto"&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;numbers&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="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;minimumIntegerDigits&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;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="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="n"&gt;locale&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;1.1&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&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="s2"&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;milliseconds&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="n"&gt;whole&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;splitMs&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&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;centis&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;milliseconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;10&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;clock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="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="n"&gt;whole&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;milliseconds&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="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&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;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;centis&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran the same 60,000-input sweep against this helper on Node 24.22.1 and got 0 mismatches. It also keeps the locale's decimal mark and digits: &lt;code&gt;de&lt;/code&gt; printed &lt;code&gt;00:02,34&lt;/code&gt; for 2,345 ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detect it, and don't test against strings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;canFormatDurations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;typeof&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;DurationFormat&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"function"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When that is false, fall back to &lt;code&gt;padStart&lt;/code&gt;. And MDN warns: "You should not compare the results of format() to hardcoded constants." Output can differ between implementations, so my example strings are what I saw, not guarantees. Test your own code on structure instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  A label for assistive tech
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;long&lt;/code&gt; style turns &lt;code&gt;{ minutes: 1, seconds: 5 }&lt;/code&gt; into &lt;code&gt;1 minute, 5 seconds&lt;/code&gt;. That could work as an &lt;code&gt;aria-label&lt;/code&gt; you update on start, pause, and finish rather than every tick. That is my suggestion; I did not test it with screen readers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources, all checked on 2026-11-27
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat" rel="noopener noreferrer"&gt;MDN: Intl.DurationFormat&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat" rel="noopener noreferrer"&gt;MDN: Intl.DurationFormat() constructor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format" rel="noopener noreferrer"&gt;MDN: Intl.DurationFormat.prototype.format()&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tc39.es/ecma402/#sec-isvalidduration" rel="noopener noreferrer"&gt;ECMA-402: IsValidDuration&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disclosure: I build &lt;a href="https://timer.wooooju.com/en/" rel="noopener noreferrer"&gt;moment.&lt;/a&gt;. It has no signup and runs in 11 languages, and the feature list is a countdown, Pomodoro cycles, repeating intervals, laps, and D-Day dates. The snippets here are standalone examples, not that app's code. A timer like this can only alert you when time is up. The formatting just decides what the number looks like on the way there.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>i18n</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Store the Wall Time, Not the UTC Instant — Morocco's 2026 Time Change</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Thu, 26 Nov 2026 20:24:33 +0000</pubDate>
      <link>https://dev.to/wozo/store-the-wall-time-not-the-utc-instant-moroccos-2026-time-change-38m1</link>
      <guid>https://dev.to/wozo/store-the-wall-time-not-the-utc-instant-moroccos-2026-time-change-38m1</guid>
      <description>&lt;p&gt;We've all heard "store everything in UTC." For a timestamp that already happened, that's the right default. For a meeting that has not happened yet, it can quietly go wrong. The time you actually promised is a civil time in a city — 10:00 in Casablanca on 15 October 2026 — and that city's offset can still change after you save the event. Morocco did exactly that this year.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed
&lt;/h2&gt;

&lt;p&gt;On Sunday, 20 September 2026, at 02:00, clocks in Morocco went back 60 minutes. Decree No. 2.26.530, adopted on 25 June 2026 and published in Bulletin Officiel No. 7521 on 29 June, returned legal time to Greenwich Mean Time and ended the extra hour Morocco had been using. An 18 September press release from the Head of Government's office repeated the same 02:00 switch.&lt;/p&gt;

&lt;p&gt;IANA recorded the new rule in tzdata 2026c, released 8 July 2026: Morocco "move[s] back to permanent UTC, without daylight saving time transitions, on 2026-09-20 at 02:00." I rechecked that in Python's &lt;code&gt;tzdata&lt;/code&gt; 2026.6 (IANA 2026f), after &lt;code&gt;zoneinfo.reset_tzpath(())&lt;/code&gt; so the package — not the OS copy — is what &lt;code&gt;ZoneInfo&lt;/code&gt; reads.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;zoneinfo&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ZoneInfo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reset_tzpath&lt;/span&gt;

&lt;span class="nf"&gt;reset_tzpath&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="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ZoneInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Africa/Casablanca"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;utc&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&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="mi"&gt;59&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;59&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tzinfo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&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="mi"&gt;0&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="n"&gt;tzinfo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&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="s2"&gt;"-&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;astimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2026-09-20T00:59:59+00:00 -&amp;gt; 2026-09-20T01:59:59+01:00
2026-09-20T01:00:00+00:00 -&amp;gt; 2026-09-20T01:00:00+00:00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is 02:00 local UTC+1 falling back to 01:00 UTC+0. Afterward, &lt;code&gt;Africa/Casablanca&lt;/code&gt; stays at UTC+0; this dataset has no later transitions in 2026 or 2027.&lt;/p&gt;

&lt;h2&gt;
  
  
  The UTC instant you stored is now an hour off
&lt;/h2&gt;

&lt;p&gt;Release 2026c is the first that includes the 20 September change. Older data (2026b or earlier) would still have treated mid-October 2026 in Casablanca as UTC+1: the 2026 Ramadan fallback had already ended on 22 March, and nothing in those rules ended UTC+1 later that year. If you had converted "15 October 2026, 10:00 in Casablanca" to UTC in June, you would have stored 09:00 UTC. With current tzdata, that civil time is 10:00 UTC. The old instant now displays as 09:00 in Casablanca.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;casa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ZoneInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Africa/Casablanca"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;wall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&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="n"&gt;tzinfo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;casa&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"stored wall -&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wall&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"correct instant -&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wall&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;astimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;stale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&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="n"&gt;tzinfo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"stale instant -&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stale&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;astimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;casa&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stored wall -&amp;gt; 2026-10-15T10:00:00+00:00
correct instant -&amp;gt; 2026-10-15T10:00:00+00:00
stale instant -&amp;gt; 2026-10-15T09:00:00+00:00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The meeting did not move. The legal clock in Casablanca did. A stored instant cannot follow a rule that had not been published yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  This was already a moving target
&lt;/h2&gt;

&lt;p&gt;The 2018–2026 arrangement was not year-round UTC+1 either. IANA models &lt;code&gt;Africa/Casablanca&lt;/code&gt; in those years as UTC+1 except during Ramadan, when clocks fell back to UTC+0. In 2026 the transitions were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;15 February, 03:00 UTC+1 → 02:00 UTC+0&lt;/li&gt;
&lt;li&gt;22 March, 02:00 UTC+0 → 03:00 UTC+1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both match the same zoneinfo data. A standing 10:00 Casablanca meeting was 18:00 in Seoul on 1 February, 19:00 on 1 March, and 18:00 again on 1 April. Those dates move every year with the Islamic calendar, so hard-coding "+1 except in March" would have been wrong even before the September decree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Another recent case: Paraguay
&lt;/h2&gt;

&lt;p&gt;Paraguay's Law No. 7354 set official time to UTC−3. It takes effect on the first Sunday of October 2024, and was published in Gaceta Oficial No. 204 on 14 October 2024. In tzdata 2026f, &lt;code&gt;America/Asuncion&lt;/code&gt; has no transitions after 6 October 2024 and is UTC−3 year-round, including July 2025; under the previous rules, mid-July was UTC−4. If you booked "15 July 2025, 09:00 in Asunción" in early 2024 and stored 13:00 UTC, current data shows that civil time as 12:00 UTC. The stale instant is 10:00 in Asunción — an hour late.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to store instead
&lt;/h2&gt;

&lt;p&gt;Keep the civil date and time, plus an IANA zone name, as the source of truth:&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;meeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;wall&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-10-15T10:00"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Africa/Casablanca"&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;Convert to an instant only when you need one — reminders, calendar math, a UI in another zone — and convert with up-to-date time zone data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# wall time + IANA zone, converted only when you need an instant&lt;/span&gt;
&lt;span class="n"&gt;meeting_wall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"2026-10-15T10:00"&lt;/span&gt;
&lt;span class="n"&gt;meeting_zone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Africa/Casablanca"&lt;/span&gt;
&lt;span class="n"&gt;instant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisoformat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;meeting_wall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;tzinfo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;ZoneInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;meeting_zone&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;astimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 2026-10-15T10:00:00+00:00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript's Temporal API uses the same split: a &lt;code&gt;PlainDateTime&lt;/code&gt; is a wall clock, a &lt;code&gt;ZonedDateTime&lt;/code&gt; attaches a named zone, and an &lt;code&gt;Instant&lt;/code&gt; is a point on the UTC timeline. I did not run Temporal here (&lt;code&gt;typeof Temporal&lt;/code&gt; is &lt;code&gt;undefined&lt;/code&gt; in Node.js v24.22.1), but that is the model to aim for.&lt;/p&gt;

&lt;p&gt;Two habits follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ship current tzdata, or the ICU / OS equivalent. A host still on 2026b would still treat October 2026 in Casablanca as UTC+1.&lt;/li&gt;
&lt;li&gt;When a government publishes a change, update the data and re-derive instants from the stored wall times. Do not edit a pile of UTC timestamps by hand and hope you found them all.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I use a small two-city overlap checker at &lt;a href="https://time.wooooju.com" rel="noopener noreferrer"&gt;https://time.wooooju.com&lt;/a&gt; when I want to see how a civil time lands in another city. The storage rule does not depend on that tool: save the wall clock and the IANA name, and convert with current tzdata only when you need an instant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Decree No. 2.26.530 (25 June 2026), Bulletin Officiel No. 7521 (29 June 2026): &lt;a href="https://www.sgg.gov.ma/BO/AR/3111/2026/BO_7521_Ar.pdf" rel="noopener noreferrer"&gt;PDF, Secrétariat Général du Gouvernement&lt;/a&gt;; record in the &lt;a href="https://bdj.mmsp.gov.ma/Fr/Document/10664-D%C3%A9cret-n-2-26-530du-9-moharrem-1448-25-juin-2026.aspx?KeyPath=" rel="noopener noreferrer"&gt;Base de données juridiques (MMSP)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Head of Government of Morocco, press release, 18 September 2026: &lt;a href="https://www.cg.gov.ma/ar/node/13036" rel="noopener noreferrer"&gt;Return to legal time on Greenwich Mean Time&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;IANA Time Zone Database, &lt;a href="https://www.iana.org/time-zones/releases/2026c" rel="noopener noreferrer"&gt;release 2026c&lt;/a&gt; (8 July 2026); &lt;a href="https://data.iana.org/time-zones/tzdb-2026f/NEWS" rel="noopener noreferrer"&gt;NEWS&lt;/a&gt; and &lt;a href="https://data.iana.org/time-zones/tzdb-2026f/africa" rel="noopener noreferrer"&gt;&lt;code&gt;africa&lt;/code&gt;&lt;/a&gt; in tzdb 2026f&lt;/li&gt;
&lt;li&gt;Python &lt;a href="https://docs.python.org/3/library/zoneinfo.html" rel="noopener noreferrer"&gt;&lt;code&gt;zoneinfo&lt;/code&gt;&lt;/a&gt; (verified with &lt;code&gt;tzdata&lt;/code&gt; 2026.6 / IANA 2026f)&lt;/li&gt;
&lt;li&gt;Paraguay, Law No. 7354: &lt;a href="https://www.gacetaoficial.gov.py/index/detalle_publicacion/89723" rel="noopener noreferrer"&gt;Gaceta Oficial No. 204, 14 October 2024&lt;/a&gt;; &lt;a href="https://silpy.congreso.gov.py/web/descarga/ley-144874" rel="noopener noreferrer"&gt;law text (PDF)&lt;/a&gt;; IANA &lt;a href="https://data.iana.org/time-zones/tzdb-2026f/southamerica" rel="noopener noreferrer"&gt;&lt;code&gt;southamerica&lt;/code&gt;&lt;/a&gt; in tzdb 2026f&lt;/li&gt;
&lt;li&gt;MDN, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal" rel="noopener noreferrer"&gt;Temporal&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>datetime</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Week 1 of 2027 Starts on January 4: ISO Week Numbers for Business-Day Planning</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Thu, 26 Nov 2026 07:42:56 +0000</pubDate>
      <link>https://dev.to/wozo/week-1-of-2027-starts-on-january-4-iso-week-numbers-for-business-day-planning-3bf4</link>
      <guid>https://dev.to/wozo/week-1-of-2027-starts-on-january-4-iso-week-numbers-for-business-day-planning-3bf4</guid>
      <description>&lt;p&gt;I used to treat week numbers as a solved problem. Store a year and a week, render a planner, ship. Then a deadline labeled "week 1 of 2027" and a deadline labeled "the first week of January" landed on two ranges with no days in common.&lt;/p&gt;

&lt;p&gt;The gap is ISO week numbering. It's the system Python's &lt;code&gt;date.isocalendar()&lt;/code&gt; implements, the one Excel documents as System 2 / &lt;code&gt;ISOWEEKNUM&lt;/code&gt;, and it does not follow the calendar year the way a lot of US-style &lt;code&gt;WEEKNUM&lt;/code&gt; defaults do. If you plan work in week buckets, that difference shows up right at the year boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an ISO week actually is
&lt;/h2&gt;

&lt;p&gt;The current standard is &lt;a href="https://www.iso.org/standard/70907.html" rel="noopener noreferrer"&gt;ISO 8601-1:2019&lt;/a&gt; (confirmed in 2024; the full text is paywalled). I am relying here on two public restatements I opened today, which agree with each other:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Microsoft's &lt;a href="https://support.microsoft.com/en-us/office/weeknum-function-e5c43a03-b4ab-426c-b411-b18c13c75340" rel="noopener noreferrer"&gt;WEEKNUM&lt;/a&gt; help calls this System 2: "The week containing the first Thursday of the year is the first week of the year, and is numbered as week 1. This system is the methodology specified in ISO 8601." &lt;code&gt;return_type&lt;/code&gt; 21 selects it. &lt;a href="https://support.microsoft.com/en-us/office/isoweeknum-function-1c2d0afe-d25b-4ab1-8894-8d0520e90e0e" rel="noopener noreferrer"&gt;&lt;code&gt;ISOWEEKNUM&lt;/code&gt;&lt;/a&gt; is the dedicated function for the same week number.&lt;/li&gt;
&lt;li&gt;Python's &lt;a href="https://docs.python.org/3/library/datetime.html#datetime.date.isocalendar" rel="noopener noreferrer"&gt;&lt;code&gt;date.isocalendar()&lt;/code&gt;&lt;/a&gt; docs say an ISO year "consists of 52 or 53 full weeks," a week "starts on a Monday and ends on a Sunday," and "the first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those two rules are equivalent, because an ISO week is always Mondayâ€“Sunday: the week that contains the first Thursday also contains January 4. ISO weekday numbers run Monday = 1 through Sunday = 7, which is not JavaScript's &lt;code&gt;getDay()&lt;/code&gt; (Sunday = 0).&lt;/p&gt;

&lt;h2&gt;
  
  
  The 2026â€“2027 boundary, day by day
&lt;/h2&gt;

&lt;p&gt;I checked the crossing with Python 3.13. The interesting dates are not January 1 alone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&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="mi"&gt;10&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="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%A"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{y}-W{w:02d}-{wd}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2026-W53-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;53&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="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2026-W53-7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;53&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;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2027-W01-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2027&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;53&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="c1"&gt;# ValueError: Invalid week: 53&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2025-12-28 Sunday    2025-W52-7
2025-12-29 Monday    2026-W01-1
2026-01-01 Thursday  2026-W01-4
2026-01-04 Sunday    2026-W01-7
2026-12-28 Monday    2026-W53-1
2026-12-31 Thursday  2026-W53-4
2027-01-01 Friday    2026-W53-5
2027-01-03 Sunday    2026-W53-7
2027-01-04 Monday    2027-W01-1
2027-01-10 Sunday    2027-W01-7
2026-W53-1 2026-12-28
2026-W53-7 2027-01-03
2027-W01-1 2027-01-04
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things in that list surprise people:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Monday, December 29, 2025 is already ISO week 1 of &lt;strong&gt;2026&lt;/strong&gt;. The ISO year started before New Year's Day.&lt;/li&gt;
&lt;li&gt;2026 has a week 53. It runs Monday, December 28, 2026 through Sunday, January 3, 2027. Friday, January 1, 2027 is &lt;code&gt;2026-W53-5&lt;/code&gt;, not week 1 of 2027.&lt;/li&gt;
&lt;li&gt;ISO week 1 of 2027 starts on &lt;strong&gt;Monday, January 4&lt;/strong&gt;. And 2027 has no week 53: &lt;code&gt;date.fromisocalendar(2027, 53, 1)&lt;/code&gt; raises &lt;code&gt;ValueError&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nearby years that do have an ISO week 53 are 2015, 2020, 2026, and 2032. Week 53 is not a data-entry bug. Some years just have 53 ISO weeks.&lt;/p&gt;

&lt;p&gt;The same function also matches examples published on the docs I used: Python's own 2004 walkthrough (&lt;code&gt;2003-12-29&lt;/code&gt; is &lt;code&gt;2004-W01-1&lt;/code&gt;, &lt;code&gt;2004-01-04&lt;/code&gt; is &lt;code&gt;2004-W01-7&lt;/code&gt;), and Microsoft's &lt;code&gt;ISOWEEKNUM&lt;/code&gt; example (&lt;code&gt;2012-03-09&lt;/code&gt; is ISO week 10, a Friday).&lt;/p&gt;

&lt;h2&gt;
  
  
  Two meanings of "week 1 of 2027"
&lt;/h2&gt;

&lt;p&gt;Excel's default &lt;code&gt;WEEKNUM&lt;/code&gt; is System 1: "The week containing January 1 is the first week of the year," and the default week begins on Sunday. I did not run Excel. Applying that documented rule to the calendar gives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System 1, week 1 of 2027: Sunday, December 27, 2026 through Saturday, January 2, 2027.&lt;/li&gt;
&lt;li&gt;ISO week 1 of 2027: Monday, January 4 through Sunday, January 10, 2027.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those ranges do not overlap. January 3, 2027 is in System 1 week 2, and it is still ISO week 53 of 2026. If one team uses Python, ISO-8601 APIs, or &lt;code&gt;ISOWEEKNUM&lt;/code&gt; / &lt;code&gt;WEEKNUM(..., 21)&lt;/code&gt;, and another uses default &lt;code&gt;WEEKNUM&lt;/code&gt;, "ship in week 1" is two different weeks.&lt;/p&gt;

&lt;p&gt;Even in 2026, where the ranges almost line up, they are not the same. System 1 week 1 of 2026 is December 28, 2025 through January 3, 2026. ISO week 1 of 2026 is December 29, 2025 through January 4, 2026. Each side has one day the other does not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;YEAR()&lt;/code&gt; + &lt;code&gt;ISOWEEKNUM()&lt;/code&gt; bug
&lt;/h2&gt;

&lt;p&gt;A second trap is combining a calendar year with an ISO week number. For January 1, 2027, &lt;code&gt;ISOWEEKNUM&lt;/code&gt; should return 53 (same week number as &lt;code&gt;isocalendar()&lt;/code&gt;), and &lt;code&gt;YEAR&lt;/code&gt; returns 2027. Stored together, that becomes the key &lt;code&gt;(2027, 53)&lt;/code&gt;. That key is invalid: 2027 has only 52 ISO weeks. The ISO year for that Friday is 2026.&lt;/p&gt;

&lt;p&gt;The safer options I use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store the ISO year and the ISO week together, not &lt;code&gt;calendar_year&lt;/code&gt; + &lt;code&gt;iso_week&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Or skip week numbers as a primary key and store the Monday of the week as a date. You can always derive the week label for display.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;monday_of_iso_week&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iso_year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;week&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="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iso_year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;week&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="c1"&gt;# "Week 53 of 2026" as a concrete range:&lt;/span&gt;
&lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;monday_of_iso_week&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;53&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# 2026-12-28&lt;/span&gt;
&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromisocalendar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;53&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;# 2027-01-03&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a ticket says "done in week 53," resolve it to those dates before you count business days inside the week. Counting "five business days in week 1 of 2027" only makes sense after you have agreed which Monday you mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  A JavaScript version that stays in agreement with Python
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Date&lt;/code&gt; still has no built-in ISO week number. This is the function I used. It treats the input as a date-only &lt;code&gt;YYYY-MM-DD&lt;/code&gt; in UTC, so a local time zone cannot slide the calendar day. The ISO year is the year of that week's Thursday. Week 1 is the week that contains January 4 of that ISO year.&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;isoWeek&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isoDate&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="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;M&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;D&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;isoDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;map&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;utc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;M&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="no"&gt;D&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;weekday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDay&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;0&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Mon=1...Sun=7&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;thursday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;thursday&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setUTCDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDate&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="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;weekday&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;isoYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;thursday&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCFullYear&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jan4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isoYear&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="mi"&gt;4&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jan4Weekday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jan4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDay&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;0&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;jan4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDay&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;week1Monday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jan4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;week1Monday&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setUTCDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jan4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDate&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jan4Weekday&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="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;week&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;thursday&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;week1Monday&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;86400000&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;isoYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;week&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;weekday&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;I compared it with Python's &lt;code&gt;date.isocalendar()&lt;/code&gt; on 4,762 consecutive dates, from 2019-12-29 through 2033-01-10, in Node v24.22.1. Zero mismatches, including the 2004 and 2012 documentation examples and the 2020 / 2026 / 2032 week-53 boundaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I now do with this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If a plan is week-based, I write down the numbering system in the same place as the week number. "ISO 2027-W01" and "the calendar week that contains 2027-01-01" are different instructions.&lt;/li&gt;
&lt;li&gt;I never store &lt;code&gt;year=2027, week=53&lt;/code&gt; from a calendar date in January. I store the ISO year, or I store a Monday.&lt;/li&gt;
&lt;li&gt;I don't special-case week 53 away. In 2026 it is a real, seven-day week that happens to straddle New Year's Day.&lt;/li&gt;
&lt;li&gt;When I need to count business days inside that week, I start from the Monday and Sunday I already resolved, then apply the weekend and holiday rules for that workplace. The week number itself does not know those rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see the actual calendar days in a span, I keep a small calculator at &lt;a href="https://workdays.wooooju.com/en/" rel="noopener noreferrer"&gt;WorkdayMap&lt;/a&gt; that walks the dates and shows which ones were counted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;p&gt;Fetched 2026-11-25 (Asia/Seoul):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.iso.org/standard/70907.html" rel="noopener noreferrer"&gt;ISO 8601-1:2019 catalog page&lt;/a&gt; â€” current part of the standard (published 2019, confirmed 2024). Abstract only; full text not retrieved.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.iso.org/iso-8601-date-and-time-format.html" rel="noopener noreferrer"&gt;ISO 8601 overview&lt;/a&gt; â€” general date-and-time format page; it does not itself define week 1.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.python.org/3/library/datetime.html#datetime.date.isocalendar" rel="noopener noreferrer"&gt;Python 3 &lt;code&gt;datetime.date.isocalendar()&lt;/code&gt;&lt;/a&gt; â€” ISO year / week / weekday rule and the 2004 example.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://support.microsoft.com/en-us/office/weeknum-function-e5c43a03-b4ab-426c-b411-b18c13c75340" rel="noopener noreferrer"&gt;Excel WEEKNUM&lt;/a&gt; â€” System 1 vs System 2 (ISO 8601), &lt;code&gt;return_type&lt;/code&gt; 21.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://support.microsoft.com/en-us/office/isoweeknum-function-1c2d0afe-d25b-4ab1-8894-8d0520e90e0e" rel="noopener noreferrer"&gt;Excel ISOWEEKNUM&lt;/a&gt; â€” &lt;code&gt;ISOWEEKNUM("2012-03-09")&lt;/code&gt; documented as 10.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Date arithmetic in this post was run on 2026-11-25 (Asia/Seoul) with Python 3.13.5 and Node v24.22.1. I did not execute Excel; the System 1 ranges above follow Microsoft's documented rule applied to those calendar dates.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>datetime</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Backing Out an APR From a Loan's Payments in JavaScript (the Reg Z Way)</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Tue, 24 Nov 2026 07:46:17 +0000</pubDate>
      <link>https://dev.to/wozo/backing-out-an-apr-from-a-loans-payments-in-javascript-the-reg-z-way-1ii5</link>
      <guid>https://dev.to/wozo/backing-out-an-apr-from-a-loans-payments-in-javascript-the-reg-z-way-1ii5</guid>
      <description>&lt;p&gt;I've written the "monthly payment" function more times than I'd like to admit. The function that goes the other way, from a payment schedule back to an APR, is the one people tend to get wrong, usually by quietly returning the note rate and calling it APR. Here's how I compute it in plain JavaScript, following the method Regulation Z actually spells out.&lt;/p&gt;

&lt;h2&gt;
  
  
  The note rate and the APR answer different questions
&lt;/h2&gt;

&lt;p&gt;The note rate tells you how the payment is calculated. The APR tells the borrower what the credit costs once certain upfront charges are counted. The trick is that Reg Z doesn't add fees to the rate; it takes them out of the money you actually received.&lt;/p&gt;

&lt;p&gt;Under 12 CFR 1026.18(b), the &lt;strong&gt;amount financed&lt;/strong&gt; starts from the principal and then subtracts "any prepaid finance charge" (&lt;a href="https://www.consumerfinance.gov/rules-policy/regulations/1026/18/" rel="noopener noreferrer"&gt;CFPB, 1026.18&lt;/a&gt;). The payment schedule doesn't change. So the APR is the rate at which that smaller amount financed is exactly paid off by the same payments.&lt;/p&gt;

&lt;p&gt;That gives us a clean way to think about the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compute the payment from the note rate and the full principal.&lt;/li&gt;
&lt;li&gt;Compute the amount financed (principal minus prepaid finance charges).&lt;/li&gt;
&lt;li&gt;Solve for the periodic rate that makes the present value of the payments equal the amount financed.&lt;/li&gt;
&lt;li&gt;Annualize it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 1: the payment, rounded like a real lender would
&lt;/h2&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;monthlyPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;annualRate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;months&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;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;annualRate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&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;exact&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;principal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;months&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="k"&gt;return&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="n"&gt;exact&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="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="c1"&gt;// the borrower pays cents, not floats&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;principal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20000&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;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;monthlyPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.07&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 396.02&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rounding matters here. The unrounded payment is $396.0240, and the schedule the borrower sees says $396.02. Your APR should be solved against the payment they actually make.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: present value of the payment stream
&lt;/h2&gt;

&lt;p&gt;Appendix J describes the &lt;strong&gt;actuarial method&lt;/strong&gt;: each unit-period, the unpaid balance of the amount financed grows by the finance charge earned and shrinks by the payment (&lt;a href="https://www.consumerfinance.gov/rules-policy/regulations/1026/j/" rel="noopener noreferrer"&gt;CFPB, Appendix J&lt;/a&gt;). For a regular monthly loan, that's the same as saying the amount financed equals the present value of the payments at the unit-period rate.&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;presentValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;months&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="n"&gt;i&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="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;months&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// (1 - (1+i)^-n) / i, written to stay accurate for tiny i&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&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;expm1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;months&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;log1p&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&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="n"&gt;i&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;h2&gt;
  
  
  Step 3: solve for the rate
&lt;/h2&gt;

&lt;p&gt;Present value falls as the rate rises, so a plain bisection is boring and bulletproof. I start with it and only reach for Newton's method if I need the speed.&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;solvePeriodicRate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amountFinanced&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;months&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;lo&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;hi&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="c1"&gt;// 0% to 100% per month brackets any sane loan&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;k&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;k&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;++&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;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hi&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;presentValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;months&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;amountFinanced&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;hi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mid&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lo&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hi&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A hundred halvings of a 0-to-1 interval is far past double precision, so there's no tolerance to tune. Newton's method from a starting guess of the note rate converged in four iterations on the example below, which is nice, but bisection can't diverge on a weird input and Newton can.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: annualize the way the regulation says
&lt;/h2&gt;

&lt;p&gt;Appendix J's general rule: the APR is the nominal rate "determined by multiplying the unit-period rate by the number of unit-periods in a year." For monthly payments that's &lt;code&gt;i * 12&lt;/code&gt;. Not &lt;code&gt;(1 + i) ** 12 - 1&lt;/code&gt;. That second formula is an effective annual rate, a legit number, just not the one Reg Z asks for.&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;prepaidFinanceCharge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// e.g., an origination fee paid at closing&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;amountFinanced&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;principal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;prepaidFinanceCharge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 19,500&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;solvePeriodicRate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amountFinanced&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&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;apr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;12&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="nb"&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="n"&gt;apr&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;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 8.068&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So a $20,000, 60-month loan at a 7% note rate with a $500 prepaid finance charge carries an APR of about 8.07%. Same payment, same term; the borrower just walked away with $19,500 of actual credit.&lt;/p&gt;

&lt;h2&gt;
  
  
  A sanity test that catches a sneaky bug
&lt;/h2&gt;

&lt;p&gt;Run the solver with no fees at all, against the rounded payment:&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="nf"&gt;solvePeriodicRate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;396.02&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ≈ 6.9996, not 7.0000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That tiny gap is the two-tenths of a cent you rounded off each month. It's correct behavior. If your test asserts &lt;code&gt;=== 7&lt;/code&gt;, the test is wrong, not the solver. Assert within a tolerance instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  How precise does the answer need to be?
&lt;/h2&gt;

&lt;p&gt;Reg Z has an answer for that too. Under 1026.22(a)(2), the APR for a regular transaction is considered accurate if it is within 1/8 of 1 percentage point of the actual rate; for an irregular transaction, 1026.22(a)(3) allows 1/4 of 1 percentage point (&lt;a href="https://www.consumerfinance.gov/rules-policy/regulations/1026/22/" rel="noopener noreferrer"&gt;CFPB, 1026.22&lt;/a&gt;). That's the tolerance for a disclosure, not a license to be sloppy in code. I still solve to full precision and display two or three decimals. But it's a useful yardstick when you're comparing your output against a lender's paperwork and you're off in the third decimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things this sketch deliberately skips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Odd first periods.&lt;/strong&gt; If the first payment isn't exactly one month out, Appendix J has rules for fractional unit-periods, and the simple annuity formula no longer applies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Which fees count.&lt;/strong&gt; Deciding what's a finance charge is a legal question (1026.4), not a math one. Make it an explicit input, never a guess.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variable rates and mortgages.&lt;/strong&gt; There are extra rules for both. Use this for intuition and simple installment loans, not compliance software.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I keep these four steps in mind whenever I touch the loan math in &lt;a href="https://finance.wooooju.com" rel="noopener noreferrer"&gt;FINORA&lt;/a&gt;, my set of browser-based loan, compound interest, and ROI calculators. If you've built an APR solver and hit an edge case I skipped, tell me in the comments. I'm collecting them.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>finance</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What a Browser Timer Should Do When the Tab Is Frozen, Cached, or Discarded</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Mon, 23 Nov 2026 07:48:05 +0000</pubDate>
      <link>https://dev.to/wozo/what-a-browser-timer-should-do-when-the-tab-is-frozen-cached-or-discarded-45ic</link>
      <guid>https://dev.to/wozo/what-a-browser-timer-should-do-when-the-tab-is-frozen-cached-or-discarded-45ic</guid>
      <description>&lt;p&gt;Most timer bugs people talk about are about drift or throttling. This post is about a different failure: the page stops running entirely, then comes back later, or never comes back at all. Browsers do this on purpose to save memory, battery, and CPU, and there are a few events you can use to survive it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The states that matter
&lt;/h2&gt;

&lt;p&gt;Chrome's Page Lifecycle documentation describes a page moving through these states: active, passive, hidden, frozen, terminated, and discarded. Three of them matter for anything that tracks time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hidden.&lt;/strong&gt; The user switched tabs, minimized the window, or moved to another app on mobile. MDN's &lt;code&gt;visibilitychange&lt;/code&gt; reference says the move to hidden "is the last event that's reliably observable by the page," and recommends treating it as the likely end of the session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frozen.&lt;/strong&gt; Chrome's guide says that in this state "the browser suspends execution of freezable tasks," which means "JavaScript timers and fetch callbacks don't run." The same thing happens to a page held in the back/forward cache. The web.dev article on bfcache explains that browsers "pause any pending timers or unresolved promises" for cached pages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discarded.&lt;/strong&gt; The browser unloads the page to free memory. According to the Chrome guide, "No tasks, event callbacks, or JavaScript of any kind can run in this state," and the discard itself fires no event. The tab title and favicon often stay visible, so to the user it looks like your page is still open.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The freeze and discard behavior comes from the WICG Page Lifecycle draft, a Draft Community Group Report dated 9 June 2022. It is not a W3C standard, and the &lt;code&gt;freeze&lt;/code&gt;, &lt;code&gt;resume&lt;/code&gt;, and &lt;code&gt;document.wasDiscarded&lt;/code&gt; APIs are Chromium features. Treat them as extras. Everything below still works without them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks
&lt;/h2&gt;

&lt;p&gt;Picture a countdown whose state lives only in memory: a &lt;code&gt;setTimeout&lt;/code&gt; for the end, plus a variable holding the time remaining.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Frozen or cached:&lt;/strong&gt; the pending timeout is paused. When the page resumes, the callback can fire late, and an in-memory "remaining" value is stale by however long the page sat frozen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discarded:&lt;/strong&gt; memory is gone. When the user comes back to the tab, the browser reloads the page from scratch. Without saved state, the countdown starts over or is simply lost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Closed on mobile:&lt;/strong&gt; Chrome's guide notes that when users close the tab or the browser app on mobile, &lt;code&gt;beforeunload&lt;/code&gt;, &lt;code&gt;pagehide&lt;/code&gt;, and &lt;code&gt;unload&lt;/code&gt; may not fire. Saving state in those handlers alone loses data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A four-step pattern
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Save at hidden, not at unload
&lt;/h3&gt;

&lt;p&gt;Write the minimum you need to rebuild the timer, which is the end time as a wall-clock timestamp plus a status, every time the page becomes hidden. Chrome's guide recommends persisting view state to &lt;code&gt;sessionStorage&lt;/code&gt; "that you'd want restored if the page were discarded and reloaded later."&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="no"&gt;KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'countdown-state'&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;saveState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// state: { endsAt: number (epoch ms), status: 'running' | 'paused' | 'done' }&lt;/span&gt;
  &lt;span class="n"&gt;sessionStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;persistIfHidden&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hidden&lt;/span&gt; &lt;span class="o"&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;visibilityState&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'hidden'&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="n"&gt;hidden&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;currentState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;saveState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currentState&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="nb"&gt;document&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="s1"&gt;'visibilitychange'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;persistIfHidden&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;Save on every Start, Pause, and Reset as well, so a crash between visibility changes doesn't lose the latest action.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Rebuild on load, and note whether it was a discard
&lt;/h3&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;restoreState&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sessionStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY&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="n"&gt;raw&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&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="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'running'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;endsAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'done'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// it finished while the page wasn't running&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;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;currentState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;restoreState&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'wasDiscarded'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;wasDiscarded&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Chromium only: the tab was discarded while hidden and has just reloaded.&lt;/span&gt;
  &lt;span class="c1"&gt;// Useful for telling the user, not required for correctness.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MDN notes that &lt;code&gt;sessionStorage&lt;/code&gt; is partitioned by origin and by tab and "survives over page reloads and restores," so two tabs running the same page keep separate countdowns.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Recompute on bfcache restore
&lt;/h3&gt;

&lt;p&gt;A page restored from the back/forward cache does not run its load code again. web.dev says &lt;code&gt;pageshow&lt;/code&gt; fires on the initial load "and any time the page is restored from bfcache," with &lt;code&gt;event.persisted&lt;/code&gt; set to true for the restore case.&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="nb"&gt;window&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="s1"&gt;'pageshow'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;persisted&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;currentState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;rescheduleFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currentState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// recompute remaining from endsAt, reset the timeout&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;&lt;code&gt;rescheduleFrom&lt;/code&gt; stands in for your own code. It should clear any old timeout, compute &lt;code&gt;endsAt - Date.now()&lt;/code&gt;, and either schedule a fresh timeout or go straight to the finished state.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Optionally handle &lt;code&gt;freeze&lt;/code&gt; and &lt;code&gt;resume&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;In Chromium you can listen for &lt;code&gt;freeze&lt;/code&gt; and &lt;code&gt;resume&lt;/code&gt; on &lt;code&gt;document&lt;/code&gt;. Chrome's guide recommends stopping timers and closing connections on freeze. Since step 1 already saved state at hidden, which comes before frozen, the main job here is clearing stale timeouts on freeze and calling &lt;code&gt;rescheduleFrom&lt;/code&gt; again on resume.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this pattern can't do
&lt;/h2&gt;

&lt;p&gt;None of these events let code run while a page is frozen or discarded. If a countdown ends during that time, the page can't play a sound or update the screen at that moment. All it can do is notice afterward, once the page runs again, that the end time has passed, and show that clearly. For an alert that must go off on schedule while the tab sleeps, you need something outside the page's own event loop, and that's a separate topic.&lt;/p&gt;

&lt;p&gt;So a timer page can promise to remember when it ends and to report correctly when you come back. It can't promise to wake itself up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Chrome for Developers, Page Lifecycle API: &lt;a href="https://developer.chrome.com/docs/web-platform/page-lifecycle-api" rel="noopener noreferrer"&gt;https://developer.chrome.com/docs/web-platform/page-lifecycle-api&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;web.dev, "Back/forward cache" article&lt;/li&gt;
&lt;li&gt;MDN Web Docs, &lt;code&gt;visibilitychange&lt;/code&gt; event, &lt;code&gt;pageshow&lt;/code&gt; event, &lt;code&gt;pagehide&lt;/code&gt; event, and &lt;code&gt;Window: sessionStorage&lt;/code&gt; references&lt;/li&gt;
&lt;li&gt;WICG, Page Lifecycle, Draft Community Group Report, 9 June 2022&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Four Rate-Conversion Bugs in Interest Calculators: APR vs APY, Monthly Rates, and Tiny Exponents</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Sun, 22 Nov 2026 07:45:49 +0000</pubDate>
      <link>https://dev.to/wozo/four-rate-conversion-bugs-in-interest-calculators-apr-vs-apy-monthly-rates-and-tiny-exponents-c60</link>
      <guid>https://dev.to/wozo/four-rate-conversion-bugs-in-interest-calculators-apr-vs-apy-monthly-rates-and-tiny-exponents-c60</guid>
      <description>&lt;p&gt;I've shipped a few interest calculators, and the bugs that bit me were rarely about rounding cents. They came from converting rates: annual to monthly, nominal to effective, APR to "the rate I should actually plug in." Here are the four I see most in code reviews, with small fixes in plain JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Treating APR, the note rate, and APY as the same number
&lt;/h2&gt;

&lt;p&gt;Three different numbers get called "the interest rate," and a calculator that mixes them up will be confidently wrong.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The note rate&lt;/strong&gt; (what most loan formulas want) is the cost of borrowing per year, before fees.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;APR&lt;/strong&gt; is broader. The CFPB explains that a mortgage APR "reflects the interest rate, any points, mortgage broker fees, and other charges," which is why it's usually higher than the interest rate (&lt;a href="https://www.consumerfinance.gov/ask-cfpb/what-is-the-difference-between-a-mortgage-interest-rate-and-an-apr-en-135/" rel="noopener noreferrer"&gt;CFPB&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;APY&lt;/strong&gt; is a savings-side number that includes compounding. Regulation DD defines it as reflecting "the interest rate and the frequency of compounding," annualized on a 365-day year (&lt;a href="https://www.consumerfinance.gov/rules-policy/regulations/1030/a/" rel="noopener noreferrer"&gt;12 CFR 1030, Appendix A&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you let a user type "APR" into a field and then feed it into an amortization formula as the note rate, your monthly payment will come out too high, because fees are now being charged interest. My rule: label the input explicitly ("interest rate, not APR") and keep the APR as a separate, derived output if you show it at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Forgetting to convert the annual rate to a per-period rate
&lt;/h2&gt;

&lt;p&gt;This one looks silly written down, but I've caught it in production code:&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;pmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ratePerPeriod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;periods&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="n"&gt;principal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;ratePerPeriod&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ratePerPeriod&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;periods&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;pmt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.065&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 1264.14  correct-ish monthly payment&lt;/span&gt;
&lt;span class="nf"&gt;pmt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.065&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// 13000.00 annual rate used as monthly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The formula doesn't care what a "period" is. If &lt;code&gt;periods&lt;/code&gt; is months, the rate must be per month too. The cheap guard is a unit in the variable name (&lt;code&gt;monthlyRate&lt;/code&gt;, &lt;code&gt;termMonths&lt;/code&gt;) and a sanity test: a $200k, 30-year loan at 6.5% should land near $1,264, not $13,000.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Dividing by 12 when the source rate is already effective
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;annualRate / 12&lt;/code&gt; is right when the annual number is a &lt;strong&gt;nominal&lt;/strong&gt; rate compounded monthly, which is the usual convention for US mortgages. It's wrong when the annual number is an &lt;strong&gt;effective&lt;/strong&gt; rate like an APY or an "annual return" that a user typed in for an ROI projection.&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;annualEffective&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.06&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;naive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;annualEffective&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                 &lt;span class="c1"&gt;// 0.005&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;exact&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;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;annualEffective&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&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="c1"&gt;// 0.0048675...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gap looks tiny, but compounded over 30 years of monthly contributions it adds up to a visibly inflated balance. The same confusion runs the other way when you display APY from a nominal rate:&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;apy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nominal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;periodsPerYear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;nominal&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;periodsPerYear&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;periodsPerYear&lt;/span&gt;&lt;span class="p"&gt;)&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="nf"&gt;apy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.06&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// 0.06168  -&amp;gt; 6.17%&lt;/span&gt;
&lt;span class="nf"&gt;apy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.06&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;365&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 0.06183  -&amp;gt; 6.18%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those two results happen to match the worked examples in Regulation DD's appendix, which computes 6.17% for $61.68 earned on $1,000 over 365 days and 6.18% for $30.37 earned on a 182-day CD, using &lt;code&gt;APY = 100 [(1 + Interest/Principal)^(365/Days in term) - 1]&lt;/code&gt;. That formula is handy as a test fixture: if your code can't reproduce the regulator's own examples, something is off.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Losing precision when the per-period rate is tiny
&lt;/h2&gt;

&lt;p&gt;Daily compounding, or hourly accrual on a large balance, means computing &lt;code&gt;(1 + r)^n&lt;/code&gt; where &lt;code&gt;r&lt;/code&gt; is very small and &lt;code&gt;n&lt;/code&gt; is big. Doubles carry about 15 significant digits, and MDN notes that &lt;code&gt;1 + 1e-16&lt;/code&gt; is exactly &lt;code&gt;1&lt;/code&gt; in this arithmetic, so the low digits of &lt;code&gt;r&lt;/code&gt; vanish the moment you add 1 (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p" rel="noopener noreferrer"&gt;MDN: Math.log1p&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Math.log1p&lt;/code&gt; and &lt;code&gt;Math.expm1&lt;/code&gt; exist for exactly this (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1" rel="noopener noreferrer"&gt;MDN: Math.expm1&lt;/a&gt;):&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;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1e-12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1e6&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;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&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="c1"&gt;// 0.0000010000894  (wrong after 4 digits)&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;expm1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&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;log1p&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// 0.0000010000005  (accurate)&lt;/span&gt;

&lt;span class="c1"&gt;// a growth-factor helper that stays accurate for small rates&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;growth&lt;/span&gt; &lt;span class="o"&gt;=&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="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;expm1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&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;log1p&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns (1+r)^n - 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For everyday monthly mortgage math you won't notice the difference. But if your app lets people model daily compounding on savings, or runs the same function inside a solver (say, backing out an APR with Newton's method), the small-rate error becomes noise that slows or derails convergence. Using the log1p/expm1 form costs nothing and removes the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Name every rate with its unit and type: &lt;code&gt;nominalAnnual&lt;/code&gt;, &lt;code&gt;effectiveAnnual&lt;/code&gt;, &lt;code&gt;monthlyRate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Convert once, at the boundary, with a single helper. Don't scatter &lt;code&gt;/ 12&lt;/code&gt; across files.&lt;/li&gt;
&lt;li&gt;Keep APR as an output that includes fees, never as the input to the payment formula.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;Math.log1p&lt;/code&gt;/&lt;code&gt;Math.expm1&lt;/code&gt; for growth factors with small rates.&lt;/li&gt;
&lt;li&gt;Turn published worked examples (like the Reg DD ones) into unit tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ran into most of these while building &lt;a href="https://finance.wooooju.com" rel="noopener noreferrer"&gt;FINORA&lt;/a&gt;, a set of browser-based compound interest, loan, and ROI calculators, and the checklist above came straight out of those bug fixes. If you've hit a rate-conversion bug I didn't list, I'd love to hear about it in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>finance</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Three Business-Day Bugs I Keep Seeing: Weekend Sets, Substitute Holidays, and Off-by-One End Dates</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Sat, 21 Nov 2026 07:50:33 +0000</pubDate>
      <link>https://dev.to/wozo/three-business-day-bugs-i-keep-seeing-weekend-sets-substitute-holidays-and-off-by-one-end-dates-434</link>
      <guid>https://dev.to/wozo/three-business-day-bugs-i-keep-seeing-weekend-sets-substitute-holidays-and-off-by-one-end-dates-434</guid>
      <description>&lt;p&gt;Every few months somebody on a team I'm helping says "it's just business days, how hard can it be?" and then we spend an afternoon arguing about whether a Friday counts. Here are the three bugs I run into most often, with the sources I check before I trust any calendar logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. "Weekend" is not a constant
&lt;/h2&gt;

&lt;p&gt;The most common shortcut is &lt;code&gt;day === 0 || day === 6&lt;/code&gt;. In JavaScript, &lt;code&gt;Date.prototype.getDay()&lt;/code&gt; returns 0 for Sunday through 6 for Saturday (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;), so that line hard-codes a Saturday/Sunday weekend.&lt;/p&gt;

&lt;p&gt;That assumption breaks fast once you leave the US. The UAE's official government portal says federal entities moved to a four-and-a-half-day week effective January 1, 2022: Monday to Thursday plus a half day Friday, with Saturday and Sunday as the official weekend. Same page, one emirate over: the Government of Sharjah works Monday to Thursday, and its official weekend is three days, Friday through Sunday (&lt;a href="https://u.ae/en/information-and-services/jobs/Sector-of-employment/working-in-uae-government-sector/working-hours-in-the-public-sector" rel="noopener noreferrer"&gt;u.ae, working hours in the public sector&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;So "the UAE weekend" isn't even one value, and it changed within the last few years. If your data model stores a country code and derives the weekend from it, you will be wrong for someone. Store the weekend as data, per calendar, and expect it to change.&lt;/p&gt;

&lt;p&gt;Bonus trap: languages disagree on numbering. JS &lt;code&gt;getDay()&lt;/code&gt; is Sunday = 0. Python's &lt;code&gt;date.isoweekday()&lt;/code&gt; follows ISO 8601, Monday = 1 through Sunday = 7, while &lt;code&gt;date.weekday()&lt;/code&gt; is Monday = 0 (&lt;a href="https://docs.python.org/3/library/datetime.html#datetime.date.isoweekday" rel="noopener noreferrer"&gt;Python docs&lt;/a&gt;). I've seen a backend and frontend disagree by a whole day because one side sent &lt;code&gt;5&lt;/code&gt; and meant Friday, the other read Saturday.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Substitute holidays have their own rules
&lt;/h2&gt;

&lt;p&gt;A holiday list that only contains fixed dates misses substitute (observed) days, and the rules for those are country-specific and sometimes holiday-specific.&lt;/p&gt;

&lt;p&gt;South Korea is a good example. Under the Regulations on Public Holidays of Government Offices, substitute holidays have existed for most national holidays since 2021, and a May 2023 revision added Buddha's Birthday and Christmas. Yonhap reported that Buddha's Birthday 2023 fell on a Saturday, so the following Monday became the day off (&lt;a href="https://en.yna.co.kr/view/AEN20230502006500315" rel="noopener noreferrer"&gt;Yonhap, May 2, 2023&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The detail that bites people: the regulation treats holidays differently. Most get a substitute when they land on a Saturday &lt;em&gt;or&lt;/em&gt; Sunday, but the three-day Lunar New Year and Chuseok blocks only trigger one when a day overlaps a Sunday or another holiday. And if the computed substitute itself lands on a Saturday, it rolls to the next non-holiday (&lt;a href="https://law.go.kr/LSW/lsRvsDocListP.do?chrClsCd=010202&amp;amp;lsId=002404&amp;amp;lsRvsGubun=all" rel="noopener noreferrer"&gt;Korean Law Information Center, Article 3&lt;/a&gt;). A generic "if weekend, move to Monday" function gets this wrong.&lt;/p&gt;

&lt;p&gt;My rule now: don't compute substitute days yourself unless you've read the actual regulation. Pull observed dates from an official published calendar and store them as explicit rows.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Inclusive vs. exclusive end dates
&lt;/h2&gt;

&lt;p&gt;"How many business days from March 2 to March 6?" Is that 4 or 5? Both answers are defensible, and that's the problem. Contracts, payroll, and shipping SLAs pick differently, and the UI rarely says which one it used.&lt;/p&gt;

&lt;p&gt;I now treat ranges as half-open &lt;code&gt;[start, end)&lt;/code&gt; internally, the same convention most date libraries use for intervals, and make inclusivity an explicit flag at the edge:&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;// weekend: Set of getDay() values, e.g. new Set([6, 0]) or new Set([5, 6, 0]) for Sharjah&lt;/span&gt;
&lt;span class="c1"&gt;// holidays: Set of "YYYY-MM-DD" strings, including substitute days&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;businessDays&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;weekend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;holidays&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inclusiveEnd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCFullYear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCMonth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDate&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;stop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCFullYear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCMonth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDate&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inclusiveEnd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setUTCDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDate&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;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;count&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;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setUTCDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDate&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;1&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toISOString&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;slice&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="mi"&gt;10&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="n"&gt;weekend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCDay&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;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;holidays&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&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="n"&gt;count&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;Two choices in there are deliberate. Everything runs in UTC on date-only values, so a DST shift can't produce a 23-hour "day" that the loop double-counts or skips. And the weekend is a parameter, not a constant.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I sanity-check
&lt;/h2&gt;

&lt;p&gt;Unit tests catch regressions, but they only check what I already believed. When I change calendar logic I compare a handful of ranges against an independent tool. Lately I've used &lt;a href="https://workdays.wooooju.com" rel="noopener noreferrer"&gt;WorkdayMap&lt;/a&gt; for that because it lets me set a custom workweek and holidays, which is exactly the part I'm usually unsure about. If my number and the tool's disagree, the bug is almost always one of the three above.&lt;/p&gt;

&lt;p&gt;What's the weirdest calendar rule you've had to encode? I'm collecting them.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>datetime</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>If Your Business-Day Calendar Stores July 4, It Will Be Wrong in 2026 and 2027</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Thu, 19 Nov 2026 04:27:16 +0000</pubDate>
      <link>https://dev.to/wozo/if-your-business-day-calendar-stores-july-4-it-will-be-wrong-in-2026-and-2027-a2k</link>
      <guid>https://dev.to/wozo/if-your-business-day-calendar-stores-july-4-it-will-be-wrong-in-2026-and-2027-a2k</guid>
      <description>&lt;p&gt;Hard-coding July 4 as Independence Day will mis-schedule federal business days in both 2026 and 2027. The U.S. Office of Personnel Management's Federal Holidays page, which lists public holidays for federal employees under 5 U.S.C. 6103, says most federal employees work a Monday through Friday schedule. For those employees, when a holiday falls on a nonworkday — Saturday or Sunday — the holiday usually is observed on Friday (if it falls on Saturday) or Monday (if it falls on Sunday).&lt;/p&gt;

&lt;p&gt;The 2026 table lists Independence Day on Friday, July 03. The footnote on that row states that if a holiday falls on a Saturday, for most federal employees the preceding Friday is treated as a holiday for pay and leave purposes (5 U.S.C. 6103(b)). July 4, 2026 is a Saturday.&lt;/p&gt;

&lt;p&gt;The 2027 table marks three observed dates the same way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Juneteenth National Independence Day: Friday, June 18 (June 19, 2027 is a Saturday)&lt;/li&gt;
&lt;li&gt;Independence Day: Monday, July 05 (July 4, 2027 is a Sunday)&lt;/li&gt;
&lt;li&gt;Christmas Day: Friday, December 24 (December 25, 2027 is a Saturday)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OPM's "Federal Holidays — In Lieu Of Determination" fact sheet restates the Monday-Friday rule: a Saturday holiday is observed on the Friday immediately before, and a Sunday holiday is observed on the Monday immediately after. The same fact sheet also says this general rule is for that workweek. Other basic workweeks and compressed schedules can have different "in lieu of" days, agencies generally may not let employees pick a different day, and part-time employees are not entitled to an "in lieu of" holiday.&lt;/p&gt;

&lt;p&gt;A year-boundary case is already on the 2028 table. New Year's Day is listed as Friday, December 31, because January 1, 2028 falls on a Saturday, so the observed day is still in 2027. A function that only looks up holidays inside the calendar year being counted will miss that Friday.&lt;/p&gt;

&lt;p&gt;If you store only the statutory month-day values — January 1, June 19, July 4, November 11, December 25 — you need a second step that applies the weekend observance rule for a Monday-Friday calendar, or you should load the observed dates OPM publishes for each year. Private employers and securities exchanges may close on different days than this federal-employee calendar; this article is only about the dates on OPM's list.&lt;/p&gt;

&lt;p&gt;Source: U.S. Office of Personnel Management, "Federal Holidays" and "Federal Holidays — In Lieu Of Determination" (confirmed 2026-11-19, KST):&lt;br&gt;
&lt;a href="https://www.opm.gov/policy-data-oversight/pay-leave/federal-holidays" rel="noopener noreferrer"&gt;https://www.opm.gov/policy-data-oversight/pay-leave/federal-holidays&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.opm.gov/policy-data-oversight/pay-leave/work-schedules/fact-sheets/Federal-Holidays-In-Lieu-Of-Determination" rel="noopener noreferrer"&gt;https://www.opm.gov/policy-data-oversight/pay-leave/work-schedules/fact-sheets/Federal-Holidays-In-Lieu-Of-Determination&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>dates</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The FDA Lists a 3-Minute Rest With 145 F — That Wait Is Part of the Safe Temperature</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Wed, 18 Nov 2026 00:56:21 +0000</pubDate>
      <link>https://dev.to/wozo/the-fda-lists-a-3-minute-rest-with-145degf-that-wait-is-part-of-the-safe-temperature-1acp</link>
      <guid>https://dev.to/wozo/the-fda-lists-a-3-minute-rest-with-145degf-that-wait-is-part-of-the-safe-temperature-1acp</guid>
      <description>&lt;p&gt;Color and texture will not tell you whether a piece of meat is safe. The FDA's Safe Food Handling page says so directly: a food thermometer is the only way to ensure the safety of meat, poultry, seafood, and egg products for all cooking methods.&lt;/p&gt;

&lt;p&gt;The same page publishes a "Safe Minimum Internal Temperatures" chart, measured with a food thermometer. For whole cuts, the number is paired with a rest:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Beef, pork, veal, and lamb chops, roasts, and steaks: 145°F, then rest 3 minutes&lt;/li&gt;
&lt;li&gt;Ham, uncooked (fresh or smoked): 145°F, then rest 3 minutes&lt;/li&gt;
&lt;li&gt;Ground meat: 160°F&lt;/li&gt;
&lt;li&gt;Ham, fully cooked, when reheated: 140°F&lt;/li&gt;
&lt;li&gt;Poultry (ground, parts, whole, and stuffing): 165°F&lt;/li&gt;
&lt;li&gt;Egg dishes: 160°F (eggs themselves: cook until the yolk and white are firm)&lt;/li&gt;
&lt;li&gt;Fin fish: 145°F, or until the flesh is opaque and separates easily with a fork&lt;/li&gt;
&lt;li&gt;Leftovers and casseroles: 165°F&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The chart treats the rest on those 145°F rows as part of the instruction, not an optional serving pause. Ground meat and poultry are listed at higher temperatures, and those rows do not carry a 3-minute rest. If you pull a steak at 145°F and slice immediately, you have not followed the line written for that cut.&lt;/p&gt;

&lt;p&gt;A simple way to observe the rest is to check the temperature, take the cut off the heat, and run a kitchen timer for three minutes, only then cutting into the meat. That timer step is a way to follow the chart; it is not extra wording from the FDA.&lt;/p&gt;

&lt;p&gt;The same page has another wait that is easy to skip. For microwave cooking, it says to cover food, stir, and rotate for even cooking, and always allow standing time, which completes the cooking, before checking the internal temperature with a food thermometer.&lt;/p&gt;

&lt;p&gt;Source: U.S. Food and Drug Administration, "Safe Food Handling" (confirmed 2026-11-17, KST): &lt;a href="https://www.fda.gov/food/buy-store-serve-safe-food/safe-food-handling" rel="noopener noreferrer"&gt;https://www.fda.gov/food/buy-store-serve-safe-food/safe-food-handling&lt;/a&gt;&lt;/p&gt;

</description>
      <category>food</category>
      <category>safety</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Intl.DateTimeFormat Gotchas When Showing a City's Local Time</title>
      <dc:creator>Nomad Wozo</dc:creator>
      <pubDate>Sat, 14 Nov 2026 12:09:57 +0000</pubDate>
      <link>https://dev.to/wozo/intldatetimeformat-gotchas-when-showing-a-citys-local-time-16ac</link>
      <guid>https://dev.to/wozo/intldatetimeformat-gotchas-when-showing-a-citys-local-time-16ac</guid>
      <description>&lt;p&gt;I was wiring a small world clock: given one instant, show the wall time in New York, London, and Seoul. &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; is the right API for this — you pass an IANA time zone and a locale, and the runtime does the offset and DST math. The surprises sit in the options that look obvious: &lt;code&gt;timeZone: "EST"&lt;/code&gt;, &lt;code&gt;timeZoneName: "short"&lt;/code&gt;, and &lt;code&gt;hour12&lt;/code&gt; next to &lt;code&gt;hourCycle&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Every snippet below was run on Node.js v24.22.1 (ICU 78.3, CLDR 48, tzdb 2026e). The process default time zone on this machine is &lt;code&gt;Asia/Seoul&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;Date#getHours()&lt;/code&gt; is the host's hour, not the city's
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;Date&lt;/code&gt; stores an instant (milliseconds since the Unix epoch). &lt;code&gt;getHours()&lt;/code&gt;, &lt;code&gt;getDate()&lt;/code&gt;, and &lt;code&gt;toString()&lt;/code&gt; convert that instant in the &lt;em&gt;runtime&lt;/em&gt; zone. They will not give you New York's clock just because you are thinking about New York.&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;instant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2026-11-14T12:00:00Z"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// noon UTC&lt;/span&gt;

&lt;span class="nb"&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="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getHours&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// 21  (Seoul, UTC+9)&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUTCHours&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// 12&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Sat Nov 14 2026 21:00:00 GMT+0900 (Korean Standard Time)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"America/New_York"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"numeric"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;timeZoneName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"short"&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="nb"&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="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 7:00 AM EST&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you omit &lt;code&gt;timeZone&lt;/code&gt;, the formatter uses the same default as &lt;code&gt;Date.prototype.toString()&lt;/code&gt; — here, &lt;code&gt;Asia/Seoul&lt;/code&gt;. Always pass the city zone you mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;"EST"&lt;/code&gt; is not Eastern Time. In tzdb it is Panama.
&lt;/h2&gt;

&lt;p&gt;This is the bug that looks right in November and wrong in July. Pass &lt;code&gt;timeZone: "EST"&lt;/code&gt; and you might assume you will get US Eastern Time, with daylight saving in the summer. You will not.&lt;/p&gt;

&lt;p&gt;On this runtime, &lt;code&gt;EST&lt;/code&gt; canonicalizes to &lt;code&gt;America/Panama&lt;/code&gt;. Panama has been on UTC−5 without DST for a long time, and IANA's &lt;code&gt;backward&lt;/code&gt; file links the old System V name &lt;code&gt;EST&lt;/code&gt; there. &lt;code&gt;MST&lt;/code&gt; is the same class of footgun: it links to &lt;code&gt;America/Phoenix&lt;/code&gt; (Arizona, no DST), not &lt;code&gt;America/Denver&lt;/code&gt;.&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;summer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2026-07-14T16:00:00Z"&lt;/span&gt;&lt;span class="p"&gt;)&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;timeZone&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"EST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"America/New_York"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"MST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"America/Denver"&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"short"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"numeric"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"numeric"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hourCycle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"h23"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeZoneName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"shortOffset"&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="nb"&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="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolvedOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;summer&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EST               America/Panama    Jul 14, 11:00 GMT-5
America/New_York  America/New_York  Jul 14, 12:00 GMT-4
MST               America/Phoenix   Jul 14, 09:00 GMT-7
America/Denver    America/Denver    Jul 14, 10:00 GMT-6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At that instant New York is on EDT (UTC−4). The &lt;code&gt;EST&lt;/code&gt; formatter is still on UTC−5, so it is an hour behind the city you thought you asked for. &lt;code&gt;resolvedOptions().timeZone&lt;/code&gt; is how you see the alias the runtime actually used.&lt;/p&gt;

&lt;p&gt;Three more naming traps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abbreviations are not unique identifiers. IANA's own guidance is not to use them that way — in English-speaking North America "CST" is US Central Standard Time; in China it is China Standard Time.&lt;/li&gt;
&lt;li&gt;Some abbreviations just throw. &lt;code&gt;KST&lt;/code&gt; and &lt;code&gt;EDT&lt;/code&gt; are a &lt;code&gt;RangeError: Invalid time zone specified&lt;/code&gt; on this Node build.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Etc/GMT+5&lt;/code&gt; is not UTC+5. The IANA &lt;code&gt;etcetera&lt;/code&gt; file keeps POSIX signs, which count positive offsets &lt;em&gt;west&lt;/em&gt; of Greenwich, so &lt;code&gt;Etc/GMT+5&lt;/code&gt; is UTC−5. The same noon-UTC instant formats as &lt;code&gt;07:00 GMT-5&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use a city identifier from the tz database: &lt;code&gt;America/New_York&lt;/code&gt;, &lt;code&gt;America/Denver&lt;/code&gt;, &lt;code&gt;Asia/Seoul&lt;/code&gt;. Offset-only IDs like &lt;code&gt;"-05:00"&lt;/code&gt; are valid in &lt;code&gt;Intl&lt;/code&gt;, but they do not follow DST.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;timeZoneName: "short"&lt;/code&gt; is a localized label, not a stable code
&lt;/h2&gt;

&lt;p&gt;Even after you pass a real IANA zone, &lt;code&gt;timeZoneName: "short"&lt;/code&gt; is not a reliable ticker. It is a localized string, and the exact text is implementation- and locale-dependent. Formatting noon UTC on 2026-11-14 in &lt;code&gt;America/New_York&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Locale&lt;/th&gt;
&lt;th&gt;&lt;code&gt;short&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;shortOffset&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;shortGeneric&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;en-US&lt;/td&gt;
&lt;td&gt;EST&lt;/td&gt;
&lt;td&gt;GMT-5&lt;/td&gt;
&lt;td&gt;ET&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;en-GB&lt;/td&gt;
&lt;td&gt;GMT-5&lt;/td&gt;
&lt;td&gt;GMT-5&lt;/td&gt;
&lt;td&gt;New York Time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;fr-FR&lt;/td&gt;
&lt;td&gt;UTC−5&lt;/td&gt;
&lt;td&gt;UTC−5&lt;/td&gt;
&lt;td&gt;heure : New York&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ko-KR&lt;/td&gt;
&lt;td&gt;GMT-5&lt;/td&gt;
&lt;td&gt;GMT-5&lt;/td&gt;
&lt;td&gt;뉴욕 시간&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;en-GB&lt;/code&gt; does not print &lt;code&gt;EST&lt;/code&gt;. &lt;code&gt;fr-FR&lt;/code&gt; uses &lt;code&gt;UTC&lt;/code&gt; and a minus sign (U+2212), not &lt;code&gt;GMT-5&lt;/code&gt;. &lt;code&gt;en-US&lt;/code&gt; has no short abbreviation for &lt;code&gt;Asia/Seoul&lt;/code&gt; — the same options print &lt;code&gt;9:00 PM GMT+9&lt;/code&gt;, not &lt;code&gt;KST&lt;/code&gt;. In July, &lt;code&gt;Europe/London&lt;/code&gt; at &lt;code&gt;2026-07-14T16:00:00Z&lt;/code&gt; is &lt;code&gt;5:00 PM GMT+1&lt;/code&gt; in &lt;code&gt;en-US&lt;/code&gt; but &lt;code&gt;17:00 BST&lt;/code&gt; in &lt;code&gt;en-GB&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;MDN notes that time zone display may fall back to another format when a preferred string is unavailable. That is why &lt;code&gt;shortGeneric&lt;/code&gt; in &lt;code&gt;en-GB&lt;/code&gt; becomes &lt;code&gt;New York Time&lt;/code&gt; rather than &lt;code&gt;ET&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you are building a world clock and you want the offset to be comparable across locales, prefer &lt;code&gt;timeZoneName: "shortOffset"&lt;/code&gt; or &lt;code&gt;"longOffset"&lt;/code&gt;, and pull the label out with &lt;code&gt;formatToParts()&lt;/code&gt; instead of scraping the formatted string.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;hour12&lt;/code&gt; silently wins, and midnight has four spellings
&lt;/h2&gt;

&lt;p&gt;ECMA-402 defines four hour cycles: &lt;code&gt;h11&lt;/code&gt; and &lt;code&gt;h23&lt;/code&gt; run 0–11 and 0–23; &lt;code&gt;h12&lt;/code&gt; and &lt;code&gt;h24&lt;/code&gt; run 1–12 and 1–24. The difference is obvious at local midnight and noon. For &lt;code&gt;America/New_York&lt;/code&gt; on &lt;code&gt;2026-11-14T05:00:00Z&lt;/code&gt; (midnight) and &lt;code&gt;2026-11-14T17:00:00Z&lt;/code&gt; (noon):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        midnight                  noon
h11     Sat, Nov 14, 00:00 AM     Sat, Nov 14, 00:00 PM
h12     Sat, Nov 14, 12:00 AM     Sat, Nov 14, 12:00 PM
h23     Sat, Nov 14, 00:00        Sat, Nov 14, 12:00
h24     Sat, Nov 14, 24:00        Sat, Nov 14, 12:00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;h24&lt;/code&gt; keeps the calendar date and prints &lt;code&gt;24:00&lt;/code&gt;. That is what the spec says to do with hour 0; it does not roll the date back to November 13.&lt;/p&gt;

&lt;p&gt;If you also pass &lt;code&gt;hour12&lt;/code&gt;, it overrides &lt;code&gt;hourCycle&lt;/code&gt;. MDN is explicit, and the runtime agrees:&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;fmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"America/New_York"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"numeric"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;hourCycle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"h23"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;hour12&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="nb"&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="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolvedOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hourCycle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// h12&lt;/span&gt;
&lt;span class="nb"&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="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2026-11-14T05:00:00Z"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 12:00 AM&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The locale decides &lt;em&gt;which&lt;/em&gt; 12-hour cycle you get. &lt;code&gt;hour12: true&lt;/code&gt; on &lt;code&gt;en-US&lt;/code&gt; becomes &lt;code&gt;h12&lt;/code&gt; (&lt;code&gt;12:00 AM&lt;/code&gt;). On &lt;code&gt;ja-JP&lt;/code&gt; it becomes &lt;code&gt;h11&lt;/code&gt; (&lt;code&gt;午前0:00&lt;/code&gt;). Locale defaults without either option also differ: &lt;code&gt;en-US&lt;/code&gt; and &lt;code&gt;ko-KR&lt;/code&gt; use &lt;code&gt;h12&lt;/code&gt;; &lt;code&gt;en-GB&lt;/code&gt; and &lt;code&gt;ja-JP&lt;/code&gt; use &lt;code&gt;h23&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you care about the cycle, set &lt;code&gt;hourCycle&lt;/code&gt; and leave &lt;code&gt;hour12&lt;/code&gt; unset.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't parse &lt;code&gt;format()&lt;/code&gt;, and don't &lt;code&gt;Number()&lt;/code&gt; Arabic digits
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;format()&lt;/code&gt; is a display string. Field order, separators, calendar, and digits all follow the locale:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;en-US  11/14/2026, 07:00
en-GB  14/11/2026, 07:00
ko-KR  2026. 11. 14. 07:00
th-TH  14/11/2569 07:00           // Buddhist calendar (year 2569)
ar-EG  ١٤/١١/٢٠٢٦، ٠٧:٠٠         // Arabic-Indic digits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Number("07")&lt;/code&gt; is &lt;code&gt;7&lt;/code&gt;. &lt;code&gt;Number("٠٧")&lt;/code&gt; is &lt;code&gt;NaN&lt;/code&gt;. &lt;code&gt;th-TH&lt;/code&gt; will happily hand you a year you can add to, except it is 543 years ahead of the Gregorian year.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;formatToParts()&lt;/code&gt; gives you named fields. If those fields are going into arithmetic — sorting rows, computing an offset — pin &lt;code&gt;calendar: "gregory"&lt;/code&gt; and &lt;code&gt;numberingSystem: "latn"&lt;/code&gt; so the values are ASCII digits in the Gregorian calendar. Leave the user's locale for the string you actually render.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dateStyle&lt;/code&gt; / &lt;code&gt;timeStyle&lt;/code&gt; cannot be combined with individual options such as &lt;code&gt;hour&lt;/code&gt; or &lt;code&gt;timeZoneName&lt;/code&gt; — that is a TypeError. Ask for the style &lt;em&gt;or&lt;/em&gt; the parts, not both.&lt;/p&gt;

&lt;h2&gt;
  
  
  A helper that returns numbers, not a sentence
&lt;/h2&gt;

&lt;p&gt;Here is the pattern I ended up with for "what is the wall clock in this city?":&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;cityWallTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"en-US"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;weekday&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"short"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"numeric"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hourCycle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"h23"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeZoneName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"shortOffset"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;calendar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"gregory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;numberingSystem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"latn"&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="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="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;fmt&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="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&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="s2"&gt;"literal"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&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="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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&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="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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;asUTC&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="no"&gt;UTC&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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;)&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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;weekday&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;weekday&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;hour&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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;minute&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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;second&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="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeZoneName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeZoneName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;offsetMinutes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;asUTC&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTime&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;60_000&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;instant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2026-11-14T12:00:00Z"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&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;cityWallTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"America/New_York"&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="nb"&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;cityWallTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Europe/London"&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="nb"&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;cityWallTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Asia/Seoul"&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="nb"&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;cityWallTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Pacific/Auckland"&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;America/New_York  Sat 2026-11-14 07:00:00  GMT-5  offsetMinutes: -300
Europe/London     Sat 2026-11-14 12:00:00  GMT+0   offsetMinutes: 0
Asia/Seoul        Sat 2026-11-14 21:00:00  GMT+9   offsetMinutes: 540
Pacific/Auckland  Sun 2026-11-15 01:00:00  GMT+13  offsetMinutes: 780
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Auckland is already Sunday. That is the whole reason to do this with a named zone and parts, not with &lt;code&gt;getHours()&lt;/code&gt; and a hardcoded offset.&lt;/p&gt;

&lt;p&gt;The offset trick is: format the instant in the city, then interpret those civil fields as if they were UTC. The millisecond difference is the offset. It also holds for half-hour and 45-minute zones: &lt;code&gt;Asia/Kolkata&lt;/code&gt; is 330 minutes year-round here, and &lt;code&gt;Pacific/Chatham&lt;/code&gt; is 765 minutes on 2026-07-14 and 825 on 2026-11-14.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Always pass a tzdb city identifier (&lt;code&gt;America/New_York&lt;/code&gt;), never &lt;code&gt;EST&lt;/code&gt; / &lt;code&gt;MST&lt;/code&gt; / &lt;code&gt;KST&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Log &lt;code&gt;resolvedOptions().timeZone&lt;/code&gt;. Aliases are real: this Node build reports &lt;code&gt;Asia/Calcutta&lt;/code&gt; when you pass &lt;code&gt;Asia/Kolkata&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Prefer &lt;code&gt;timeZoneName: "shortOffset"&lt;/code&gt; when the offset is the thing the user needs to compare.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;hourCycle&lt;/code&gt; explicitly, and do not also set &lt;code&gt;hour12&lt;/code&gt; if you care which cycle you get.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;formatToParts()&lt;/code&gt; for structure. Pin &lt;code&gt;calendar: "gregory"&lt;/code&gt; and &lt;code&gt;numberingSystem: "latn"&lt;/code&gt; when the values have to be numbers.&lt;/li&gt;
&lt;li&gt;Store UTC instants (or offset-aware strings). Format at the edge.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I ran into these while building a small city-to-city converter, WorldTimeSync: &lt;a href="https://time.wooooju.com/en/" rel="noopener noreferrer"&gt;https://time.wooooju.com/en/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;Intl.DateTimeFormat()&lt;/code&gt; constructor&lt;/a&gt; (&lt;code&gt;hour12&lt;/code&gt; overrides &lt;code&gt;hourCycle&lt;/code&gt;; &lt;code&gt;timeZoneName&lt;/code&gt; values and fallback)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;formatToParts()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;resolvedOptions()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tc39.es/ecma402/" rel="noopener noreferrer"&gt;ECMA-402&lt;/a&gt; (hour cycles; &lt;code&gt;h24&lt;/code&gt; maps hour 0 to 24)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://data.iana.org/time-zones/tzdb/backward" rel="noopener noreferrer"&gt;IANA tzdb &lt;code&gt;backward&lt;/code&gt;&lt;/a&gt; (&lt;code&gt;EST&lt;/code&gt; → &lt;code&gt;America/Panama&lt;/code&gt;, &lt;code&gt;MST&lt;/code&gt; → &lt;code&gt;America/Phoenix&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://data.iana.org/time-zones/tzdb/etcetera" rel="noopener noreferrer"&gt;IANA tzdb &lt;code&gt;etcetera&lt;/code&gt;&lt;/a&gt; (POSIX sign on &lt;code&gt;Etc/GMT±N&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.iana.org/time-zones/repository/tz-link.html" rel="noopener noreferrer"&gt;IANA: Time zone and daylight saving time data&lt;/a&gt; (abbreviations are not unique identifiers)&lt;/li&gt;
&lt;/ul&gt;

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