ai_date.cpp

Go to the documentation of this file.
00001 /* $Id: ai_date.cpp 17248 2009-08-21 20:21:05Z rubidium $ */
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 #include "ai_date.hpp"
00013 #include "../../date_func.h"
00014 
00015 /* static */ int32 AIDate::GetCurrentDate()
00016 {
00017   return ::_date;
00018 }
00019 
00020 /* static */ int32 AIDate::GetYear(int32 date)
00021 {
00022   if (date < 0) return -1;
00023 
00024 	::YearMonthDay ymd;
00025 	::ConvertDateToYMD(date, &ymd);
00026   return ymd.year;
00027 }
00028 
00029 /* static */ int32 AIDate::GetMonth(int32 date)
00030 {
00031   if (date < 0) return -1;
00032 
00033 	::YearMonthDay ymd;
00034 	::ConvertDateToYMD(date, &ymd);
00035   return ymd.month + 1;
00036 }
00037 
00038 /* static */ int32 AIDate::GetDayOfMonth(int32 date)
00039 {
00040   if (date < 0) return -1;
00041 
00042 	::YearMonthDay ymd;
00043 	::ConvertDateToYMD(date, &ymd);
00044   return ymd.day;
00045 }
00046 
00047 /* static */ int32 AIDate::GetDate(int32 year, int32 month, int32 day_of_month)
00048 {
00049   if (month < 1 || month > 12) return -1;
00050   if (day_of_month < 1 || day_of_month > 31) return -1;
00051   if (year < 0 || year > MAX_YEAR) return -1;
00052 
00053   return ::ConvertYMDToDate(year, month - 1, day_of_month);
00054 }

Generated on Wed Apr 21 20:31:45 2010 for OpenTTD by  doxygen 1.6.1