title: Better way of getting day of year for a different calendar
body: <p>I'm trying to get the day of month for following calendar:</p>
  <p><a href="https://i.stack.imgur.com/7MARA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7MARA.png" alt="enter image description here" /></a></p>
  <p>I wrote two different functions that accomplish this:</p>
  <pre><code>public int DayOfYear(int year, int month, int day)
  {
   
      var months = new[] {31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 31};
  
      var dayOfYear = day;
  
      if (month == 1) return dayOfYear;
      for (var i = 0; i &lt; month-1; i++)
      {
          dayOfYear += months[i];
      }
  
      return  dayOfYear;
  }
  </code></pre>
  <p>And to do this without a loop:</p>
  <pre><code>public int DayOfYear(int year, int month, int day)
  {
   
      var dayOfYear = day;
          
      if (month &lt;= 5)
          dayOfYear += 31 * (month-1);
      else
          dayOfYear += 31 * 5 + 30 * ((month - 5) - 2);
  
      if (month == 12)
          dayOfYear += 31;
          
          
      return dayOfYear;
  }
  </code></pre>
  <p>For the 12th month lets assume it has always 31 days. I feel that there is a beter mathematical way of doing this, but I can't really come up with it.</p>
  <p>An example: (522, 12, 14) is the 349th day of the year according to my calendar. This is correct using both functions. And (522, 1, 1) would be the first day of the year.</p>
  <p>For some visualization, (522, 5, 18) would be done as following:
  <code>31 + 31 + 31 + 31 + 18</code></p>
  <p>And (522, 9, 18) as:</p>
  <p><code>31 + 31 + 31 + 31 + 31 + 30 + 30 + 30 + 18</code></p>