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/>.
8 /** @file script_date.cpp Implementation of ScriptDate. */
10 #include "../../stdafx.h"
11 #include "script_date.hpp"
12 #include "../../timer/timer_game_economy.h"
16 #include "../../safeguards.h"
18 /* static */ bool ScriptDate::IsValidDate(Date date
)
23 /* static */ ScriptDate::Date
ScriptDate::GetCurrentDate()
25 return (ScriptDate::Date
)TimerGameEconomy::date
.base();
28 /* static */ SQInteger
ScriptDate::GetYear(ScriptDate::Date date
)
30 if (date
< 0) return DATE_INVALID
;
32 ::TimerGameEconomy::YearMonthDay ymd
= ::TimerGameEconomy::ConvertDateToYMD(date
);
33 return ymd
.year
.base();
36 /* static */ SQInteger
ScriptDate::GetMonth(ScriptDate::Date date
)
38 if (date
< 0) return DATE_INVALID
;
40 ::TimerGameEconomy::YearMonthDay ymd
= ::TimerGameEconomy::ConvertDateToYMD(date
);
44 /* static */ SQInteger
ScriptDate::GetDayOfMonth(ScriptDate::Date date
)
46 if (date
< 0) return DATE_INVALID
;
48 ::TimerGameEconomy::YearMonthDay ymd
= ::TimerGameEconomy::ConvertDateToYMD(date
);
52 /* static */ ScriptDate::Date
ScriptDate::GetDate(SQInteger year
, SQInteger month
, SQInteger day_of_month
)
54 if (month
< 1 || month
> 12) return DATE_INVALID
;
55 if (day_of_month
< 1 || day_of_month
> 31) return DATE_INVALID
;
56 if (year
< 0 || year
> EconomyTime::MAX_YEAR
) return DATE_INVALID
;
58 return (ScriptDate::Date
)::TimerGameEconomy::ConvertYMDToDate(year
, month
- 1, day_of_month
).base();
61 /* static */ SQInteger
ScriptDate::GetSystemTime()