# date_type.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef DATE_TYPE_H
    00013 #define DATE_TYPE_H
    00014
    00015
    00016 typedef int32  Date;
    00017 typedef uint16 DateFract;
    00018 typedef int32  Ticks;
    00019
    00020 typedef int32  Year;
    00021 typedef uint8  Month;
    00022 typedef uint8  Day;
    00023
    00030 static const int DAY_TICKS         =  74;
    00031 static const int DAYS_IN_YEAR      = 365;
    00032 static const int DAYS_IN_LEAP_YEAR = 366;
    00033
    00034 /*
    00035  * ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR and DAYS_TILL_ORIGINAL_BASE_YEAR are
    00036  * primarily used for loading newgrf and savegame data and returning some
    00037  * newgrf (callback) functions that were in the original (TTD) inherited
    00038  * format, where '_date == 0' meant that it was 1920-01-01.
    00039  */
    00040
    00042 static const Year ORIGINAL_BASE_YEAR = 1920;
    00044 static const Year ORIGINAL_END_YEAR  = 2051;
    00046 static const Year ORIGINAL_MAX_YEAR  = 2090;
    00047
    00060 #define LEAP_YEARS_TILL(year) ((year) == 0 ? 0 : ((year) - 1) / 4 - ((year) - 1) / 100 + ((year) - 1) / 400 + 1)
    00061
    00067 #define DAYS_TILL(year) (DAYS_IN_YEAR * (year) + LEAP_YEARS_TILL(year))
    00068
    00073 #define DAYS_TILL_ORIGINAL_BASE_YEAR DAYS_TILL(ORIGINAL_BASE_YEAR)
    00074
    00076 static const Year MIN_YEAR = 0;
    00077
    00079 static const Year DEF_START_YEAR = 1950;
    00080
    00085 static const Year MAX_YEAR  = 5000000;
    00086
    00088 #define MAX_DAY (DAYS_TILL(MAX_YEAR + 1) - 1)
    00089
    00094 struct YearMonthDay {
    00095   Year  year;
    00096   Month month;
    00097   Day   day;
    00098 };
    00099
    00100 static const Year  INVALID_YEAR  = -1;
    00101 static const Date  INVALID_DATE  = -1;
    00102 static const Ticks INVALID_TICKS = -1;
    00103
    00104 #endif /* DATE_TYPE_H */