<?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: Robert Perkins</title>
    <description>The latest articles on DEV Community by Robert Perkins (@robert_perkins_21a60d83d5).</description>
    <link>https://dev.to/robert_perkins_21a60d83d5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3944416%2F35192329-b20d-46ef-be9b-3a60c63fb010.jpg</url>
      <title>DEV Community: Robert Perkins</title>
      <link>https://dev.to/robert_perkins_21a60d83d5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/robert_perkins_21a60d83d5"/>
    <language>en</language>
    <item>
      <title>Date Shear: A New Term for a Common Programming Pain Point</title>
      <dc:creator>Robert Perkins</dc:creator>
      <pubDate>Thu, 21 May 2026 18:01:03 +0000</pubDate>
      <link>https://dev.to/robert_perkins_21a60d83d5/date-shear-a-new-term-for-a-common-programming-pain-point-2997</link>
      <guid>https://dev.to/robert_perkins_21a60d83d5/date-shear-a-new-term-for-a-common-programming-pain-point-2997</guid>
      <description>&lt;p&gt;One of the sneakiest, hardest to explain bugs. The process works fine any day you test it, but occasionally - and &lt;em&gt;only occasionally&lt;/em&gt; it's just... wrong. Test it again and it's fine, no matter what day you test it.&lt;/p&gt;

&lt;p&gt;This particular issue stems from a habit of grabbing a datetime whenever you need it, but coding as if you were getting the same value each time. It's an easy to explain issue, but there's not a term for it (as far as I can tell), so, I coined one: &lt;strong&gt;Date Shear&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Date Shear?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Date Shear (noun):&lt;/strong&gt; Insidiously difficult to reproduce bugs that occur due to code fetching the "current time" multiple times, while the logic expects the same value. The result can be catastrophically incorrect behavior if the code is executed across a day, month or year boundary.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  A Common Example
&lt;/h3&gt;

&lt;p&gt;Imagine building a Quarterly report based on the current day:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Just before&lt;/em&gt; midnight, a GetDate() or similar method gets the current datetime, and uses that to determine the start date for the "current" quarter.&lt;/li&gt;
&lt;li&gt;(Clock ticks midnight)&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Just after&lt;/em&gt; midnight, a GetDate() or similar method gets the current datetime, again (but it's now in the next month) and uses that to determine the end date for the "current" quarter.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, you end up with the start of one quarter and - potentially - the end of the next quarter. This only happens if the request crosses into the next day, on the last day of the month, in the last month of a quarter.&lt;/p&gt;

&lt;p&gt;Adding to the annoyance is that reports are often run by companies as part of an overnight batch process, increasing the likelihood of this occurring in a production environment... but testers are less likely to be testing functionality in the middle of the night - and daytime testing won't reproduce the issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Naming This Matters
&lt;/h3&gt;

&lt;p&gt;They say that "naming something gives it power"... but I would say that naming something gives &lt;em&gt;you&lt;/em&gt; power over it. When we name a specific type of bug, we make it easier to communicate during code reviews and architectural planning. Instead of saying, &lt;em&gt;"We need to double check the date handling to see if there's something fishy in there,"&lt;/em&gt; you can simply say, &lt;em&gt;"We need to guard against Date Shear here."&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Solution for Date Shear
&lt;/h3&gt;

&lt;p&gt;In simple single-script or single-method processes, the solution is simple. Grab a datetime at the beginning, store it in a variable and reuse it. In some cases, taking a parameter of the date in question is a good way to handle it. &lt;/p&gt;

&lt;p&gt;For processes that call other processes (that may call further processes), taking the date in question in as a parameter allows them to all "be on the same page".&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;What do you think?&lt;/strong&gt; Have you encountered "Date Shear" in your own projects? Is there a better name for this that I'm somehow missing?&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>discuss</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
