[Fast Calculation] Y2M method and M2Y method

In SpeedCalendar, the calculation of January and February is a factor that greatly affects the calculation speed. Here, we introduce two methods: (1) the Y2M method, which calculates in the order of last two digits, then month, and (2) the M2Y method, which calculates in the order of month, then last two digits.

Y2M Method

This method obtains the month value after deriving Last Two Digits value. For example, in the case of July 2022, the calculation process is:

(1) 20 -> First two-digit value is “0”
(2) 22 -> Last two digits value is “6”
(3) July -> Month value is “5”

The problem arises in the case of January and February. In this case, the value of the year has to be reduced by one. However, it is not efficient to recalculate the last two digits value after confirming that it is January or February. Therefore, we need to check whether the number of years is a multiple of 4 or not.

  • If it is January and the number of years is not a multiple of 4, subtract 1 from the already calculated yearly value plus the last two digits value.
  • If it is January and the number of years is a multiple of 4, subtract 2 from the already calculated yearly value plus the last two digits value.
  • If it is February and the number of years is not a multiple of 4, add 2 to the already calculated yearly value plus the last two digits value.
  • If the month is February and the number of years is a multiple of 4, add 1 to the already calculated yearly value plus the last two digits value

In the case of the Millennium (the last two digits are 00), if the year is a multiple of 400, we further subtract 1 from the result above.  The result is described below.

First two digits January February
16, 20, 24 5 1
15, 19, 23 0 3
18, 22 2 5
17, 21, 25 4 9

The good thing about Y2D method is that it matches the Japanese notation (big-endian, year-month-day), so if you are asked about the date in Japanese, you can calculate it immediately. On the other hand, it does not match the notation of the UK, Australia, etc. (little endian, day-month-year) or the US (middle endian, month-day-year).

M2Y method

This is a method to check the month before calculating the last two digits. In other words, after calculating the number of months, if it is January or February, the last two digits of the year minus one are used to determine the last two digits value.

The good thing about the M2Y method is that, unlike the Y2M method, there is no need to determine whether the number is a multiple of 4 or not. It is also compatible with little-endian and middle-endian notation. On the other hand, it is not compatible with the Japanese notation, which can lead to difficulties in verbal communication.

Y2M or M2Y?

It is desirable to learn both Y2M and M2Y to be able to deal with either notation, but I think the best way is to start with M2Y, which requires less memorization, and move on to Y2M when you get used to deriving the last two digits values.

Comments

Copied title and URL