TimeSpan Tools 가이드

Month-End and Leap-Year Date Math

Understand calendar-aware addition and subtraction for short months, leap days, recurring dates, and month-end rules.

Calendar units are not fixed durations

Adding one day, one month, and one year are calendar operations, not interchangeable numbers of seconds. Months have different lengths and leap years add a day to February. Adding 30 days to January 31 is therefore not the same operation as adding one calendar month. Before calculating, decide whether the requirement describes elapsed duration or a calendar relationship. Use hours or days for a fixed interval; use months or years only with a documented calendar rule.

Choose a month-end policy

A target month may not contain the source day number. January 31 plus one month cannot produce February 31. One common policy clamps the result to the final valid day of the target month, producing February 28 in a common year or February 29 in a leap year. Another policy carries overflow into the following month. Billing, payroll, and contract systems may specify different behavior. State the policy and show the resulting date instead of presenting calendar arithmetic as universally defined.

Handle February 29 deliberately

A leap-day anniversary moved by one calendar year reaches a year without February 29. A clamping policy returns February 28, while some domains choose March 1. Neither choice should be hidden. For age, benefits, legal anniversaries, and recurring events, follow the governing rule. Test movement from a leap year to a common year, from a common year into a leap year, and across century years, remembering that years divisible by 100 are not leap years unless divisible by 400.

Order of operations can change the answer

Adding one month and then one day can differ from adding one day and then one month because the intermediate date may be at a month boundary. Likewise, twelve successive one-month moves can differ from one one-year move under some clamping conventions. Apply operations in the order the rule specifies and preserve intermediate results when an audit trail matters. Do not combine unlike calendar units into an assumed total number of days.

Date-only math and time zones

A date-only calculation normally stays in the calendar domain and does not need a time zone. Once a local time is attached, midnight transitions and daylight-saving changes can affect the elapsed duration between results. For example, two local noon readings on adjacent dates may be 23 or 25 elapsed hours apart. Decide whether the task promises the same local clock time or a fixed duration, then use a named zone for date-time calculations.

Recurring schedules need a stable rule

“The last day of every month” is different from “the 31st of every month” and from “every 30 days.” Model the rule that users actually intend. A last-day schedule should recompute each target month’s final date. A fixed day-of-month schedule needs a policy for missing days. A duration schedule should move along the timeline. Keep the rule, original date, and time zone when applicable so future occurrences can be recalculated after calendar or civil-time changes.

Useful boundary test cases

Test January 31 plus and minus one month, March 31 minus one month, February 29 plus one year, December 31 plus one day, and operations that cross a leap year. Test reversed operations rather than assuming addition and subtraction always undo each other after clamping. If times are included, add dates around both forward and backward daylight-saving transitions. Display the applied unit and policy beside the result so a user can reproduce it.

자주 묻는 질문

Is one month the same as 30 days?

No. Calendar months range from 28 to 31 days.

What is January 31 plus one month?

It depends on the documented policy. TimeSpan Tools uses calendar-aware clamping to the last valid day of the target month.

What happens to February 29 one year later?

A non-leap target year needs a stated policy, commonly February 28 or March 1.

Can adding and then subtracting one month return a different date?

Yes. Month-end clamping can lose the original day number, so boundary operations need explicit tests.

주요 참고자료

아래 표준과 공식 페이지는 본문의 정의와 규칙을 뒷받침합니다. 시간대 정책과 공휴일 달력은 바뀔 수 있으므로 중요한 미래 날짜는 담당 기관에서 확인하세요.