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