OpenTTD Source  1.11.0-beta2
date_func.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef DATE_FUNC_H
11 #define DATE_FUNC_H
12 
13 #include "date_type.h"
14 
15 extern Year _cur_year;
16 extern Month _cur_month;
17 extern Date _date;
18 extern DateFract _date_fract;
19 extern uint16 _tick_counter;
20 
21 void SetDate(Date date, DateFract fract);
22 void ConvertDateToYMD(Date date, YearMonthDay *ymd);
23 Date ConvertYMDToDate(Year year, Month month, Day day);
24 
30 static inline bool IsLeapYear(Year yr)
31 {
32  return yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0);
33 }
34 
35 #endif /* DATE_FUNC_H */
_tick_counter
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
Definition: date.cpp:30
_cur_month
Month _cur_month
Current month (0..11)
Definition: date.cpp:27
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
IsLeapYear
static bool IsLeapYear(Year yr)
Checks whether the given year is a leap year or not.
Definition: date_func.h:30
Month
uint8 Month
Type for the month, note: 0 based, i.e. 0 = January, 11 = December.
Definition: date_type.h:19
date_type.h
ConvertYMDToDate
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
SetDate
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:37
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:103
Day
uint8 Day
Type for the day of the month, note: 1 based, first day of a month is 1.
Definition: date_type.h:20
DateFract
uint16 DateFract
The fraction of a date we're in, i.e. the number of ticks since the last date changeover.
Definition: date_type.h:15
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26