diff options
author | rubidium <rubidium@openttd.org> | 2009-11-25 23:28:04 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-11-25 23:28:04 +0000 |
commit | 1a8c203d6ec29cf200b37fd995e865821c8ce888 (patch) | |
tree | 6fead8ca2f9912f460132eb58edd610343685ebf /src/date.cpp | |
parent | d3a925af42e8e5ce01a63a57dfd57c0ed99a6c96 (diff) | |
download | openttd-1a8c203d6ec29cf200b37fd995e865821c8ce888.tar.xz |
(svn r18291) -Codechange: rework the calculation of the 'days till year' macro a bit so it can be properly reused and add a MAX_DAY
Diffstat (limited to 'src/date.cpp')
-rw-r--r-- | src/date.cpp | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/src/date.cpp b/src/date.cpp index 51ff6e426..e1b6d1943 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -140,22 +140,13 @@ void ConvertDateToYMD(Date date, YearMonthDay *ymd) */ Date ConvertYMDToDate(Year year, Month month, Day day) { - /* - * Each passed leap year adds one day to the 'day count'. - * - * A special case for the year 0 as no year has been passed, - * but '(year - 1) / 4' does not yield '-1' to counteract the - * '+1' at the end of the formula as divisions round to zero. - */ - int nr_of_leap_years = (year == 0) ? 0 : ((year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + 1); - /* Day-offset in a leap year */ int days = _accum_days_for_month[month] + day - 1; /* Account for the missing of the 29th of February in non-leap years */ if (!IsLeapYear(year) && days >= ACCUM_MAR) days--; - return year * DAYS_IN_YEAR + nr_of_leap_years + days; + return DAYS_TILL(year) + days; } /** Functions used by the IncreaseDate function */ |