Dates as Fractions

Today is 4/28. As a fraction, today is $\frac{4}{28} = \frac{1}{7} \approx 0.143$. But how close is that to the proportion of the year that has passed? We are on day 119 of a year with 366 days, and $\frac{119}{366} \approx 0.325$. That’s a difference of approximately 0.182. That’s not very close.

Perhaps there are days whose rational numbers are closer? I had to find out, so I wrote a program. I’m gun-shy of date libraries, so I started with just this simple list of month lengths:

MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
YEAR_LENGTH = MONTH_LENGTHS.sum

I hardcoded February as a non-leap year.

Next up, because I like pivoting around data rather than code, I modeled the subject of our study using a class. Its methods interpret the date as various rational numbers: as a month-over-day, as a day-of-year, and as a day-over-month.

class Date
  attr_reader :month, :day, :doy

  def initialize(month, day, doy)
    @month = month
    @day = day
    @doy = doy
  end

  def doyProportion
    @doy.to_f / YEAR_LENGTH
  end

  def monthOverDay
    @month.to_f / @day
  end

  def dayOverMonth
    @day.to_f / @month
  end
end

To make a list of all the dates of the year, I decided to iterate through the interval [1, 365], maintaining separate month and day counters as I go. Upon reaching the end of month, I reset the day counter back to 1.

doy = 1
month = 1
day = 1

dates = []
while month < 13
  dates << Date.new(month, day, doy)
  doy += 1
  if day < MONTH_LENGTHS[month - 1]
    day += 1
  else
    day = 1
    month += 1
  end
end

Now I had all the pieces I needed to conduct my investigation. I sorted my list by the absolute difference between the month-over-day and the day-of-year proportion:

sorted = dates.sort_by do |date|
  (date.monthOverDay - date.doyProportion).abs
end

Who do you think the winner was?

Spoilers ahead.

In Table 1, we have the top ten dates whose month-over-days are nearest to their day-of-year proportions.

date day of year month-over-day day-of-year proportion difference
1/19 19 0.0526 0.0521 0.0006
4/14 104 0.2857 0.2849 0.0008
8/13 225 0.6154 0.6164 0.0011
3/15 74 0.2000 0.2027 0.0027
2/16 47 0.1250 0.1288 0.0038
1/20 20 0.0500 0.0548 0.0048
1/18 18 0.0556 0.0493 0.0062
7/13 194 0.5385 0.5315 0.0070
2/15 46 0.1333 0.1260 0.0073
9/13 256 0.6923 0.7014 0.0091
Table 1. The ten dates of a non-leap year whose rational numbers are nearest.

Congratulations, January 19! Adding in the leap day changes this list very little.

Which dates do you think had the largest differences between their two rational numbers? You don’t really need a program to tell you the answers, which are shown in Table 2.

date day of year month-over-day day-of-year proportion difference
11/2 306 5.5 0.8384 4.6616
5/1 121 5.0 0.3315 4.6685
12/2 336 6.0 0.9205 5.0795
6/1 152 6.0 0.4164 5.5836
7/1 182 7.0 0.4986 6.5014
8/1 213 8.0 0.5836 7.4164
9/1 244 9.0 0.6685 8.3315
10/1 274 10.0 0.7507 9.2493
11/1 305 11.0 0.8356 10.1644
12/1 335 12.0 0.9178 11.0822
Table 2. The ten dates of a non-leap year whose rational numbers are farthest apart.

Congratulations, December 1!

America is one of the few countries that places months before days in dates. Sometimes the month-day-year ordering is called middle-endian ordering. Many more countries use little-endian ordering. They would say that today is 28/4.

Let’s examine figure out which dates are closest in little-endian ordering. We make just a slight change to our sorting criteria to consider the day-over-month rather than the month-over-day:

sorted = dates.sort_by do |date|
  (date.dayOverMonth - date.doyProportion).abs
end

The dates whose rational numbers are nearest are shown in Table 3.

date day of year day-over-month day-of-year proportion difference
1/4 91 0.2500 0.2493 0.0007
6/9 249 0.6667 0.6822 0.0155
11/12 345 0.9167 0.9452 0.0285
8/10 281 0.8000 0.7699 0.0301
5/8 217 0.6250 0.5945 0.0305
9/11 313 0.8182 0.8575 0.0394
10/11 314 0.9091 0.8603 0.0488
12/12 346 1.0000 0.9479 0.0521
4/7 185 0.5714 0.5068 0.0646
2/5 122 0.4000 0.3342 0.0658
Table 3. The ten dates whose rational numbers are nearest in little-endian ordering.

Congratulations, 1 April!

Once again, can you guess which dates are at the bottom of this list? You can, if you believe in yourself. The answers are shown in Table 4.

date day of year day-over-month day-of-year proportion difference
22/1 22 22.0 0.0603 21.9397
23/1 23 23.0 0.063 22.937
24/1 24 24.0 0.0658 23.9342
25/1 25 25.0 0.0685 24.9315
26/1 26 26.0 0.0712 25.9288
27/1 27 27.0 0.074 26.926
28/1 28 28.0 0.0767 27.9233
29/1 29 29.0 0.0795 28.9205
30/1 30 30.0 0.0822 29.9178
31/1 31 31.0 0.0849 30.9151
Table 4. The ten dates whose rational numbers are farthest apart in little-endian ordering.

Congratulations, 31 January!

I am satisfied with the outcome of my investigation. I now have four new holidays to celebrate.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *