It comes from the Civil Code in force in Taiwan.
If a period is fixed by days, weeks, months, or years, it ends with the ending of the last day of the period. If a period fixed by weeks, months, and years does not commence from the beginning of a week, month, or year, it ends with the ending of the day which proceeds [precedes?] the day of the last week, month, or year which corresponds to that on which it began to commence. But if there is no corresponding day in the last month, the period ends with the ending of the last day of the last month.
Is your head hurting yet? 🙂
If anyone is interested in the whole official translation of that Civil Code, it can found in the Laws & Regulations Database of The Republic of China, here.