1 /* $Id: script_date.cpp 26307 2014-02-06 19:50:34Z zuu $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file script_date.cpp Implementation of ScriptDate. */
13 #include "../../stdafx.h"
14 #include "script_date.hpp"
15 #include "../../date_func.h"
17 #include "../../safeguards.h"
19 /* static */ bool ScriptDate::IsValidDate(Date date
)
24 /* static */ ScriptDate::Date
ScriptDate::GetCurrentDate()
26 return (ScriptDate::Date
)_date
;
29 /* static */ int32
ScriptDate::GetYear(ScriptDate::Date date
)
31 if (date
< 0) return DATE_INVALID
;
34 ::ConvertDateToYMD(date
, &ymd
);
38 /* static */ int32
ScriptDate::GetMonth(ScriptDate::Date date
)
40 if (date
< 0) return DATE_INVALID
;
43 ::ConvertDateToYMD(date
, &ymd
);
47 /* static */ int32
ScriptDate::GetDayOfMonth(ScriptDate::Date date
)
49 if (date
< 0) return DATE_INVALID
;
52 ::ConvertDateToYMD(date
, &ymd
);
56 /* static */ ScriptDate::Date
ScriptDate::GetDate(int32 year
, int32 month
, int32 day_of_month
)
58 if (month
< 1 || month
> 12) return DATE_INVALID
;
59 if (day_of_month
< 1 || day_of_month
> 31) return DATE_INVALID
;
60 if (year
< 0 || year
> MAX_YEAR
) return DATE_INVALID
;
62 return (ScriptDate::Date
)::ConvertYMDToDate(year
, month
- 1, day_of_month
);
65 /* static */ int32
ScriptDate::GetSystemTime()