script_date.cpp

Go to the documentation of this file.
00001 /* $Id: script_date.cpp 23619 2011-12-19 20:59:12Z truebrain $ */
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 <time.h>
00013 #include "../../stdafx.h"
00014 #include "script_date.hpp"
00015 #include "../../date_func.h"
00016 
00017 /* static */ int32 ScriptDate::GetCurrentDate()
00018 {
00019   return ::_date;
00020 }
00021 
00022 /* static */ int32 ScriptDate::GetYear(int32 date)
00023 {
00024   if (date < 0) return -1;
00025 
00026 	::YearMonthDay ymd;
00027 	::ConvertDateToYMD(date, &ymd);
00028   return ymd.year;
00029 }
00030 
00031 /* static */ int32 ScriptDate::GetMonth(int32 date)
00032 {
00033   if (date < 0) return -1;
00034 
00035 	::YearMonthDay ymd;
00036 	::ConvertDateToYMD(date, &ymd);
00037   return ymd.month + 1;
00038 }
00039 
00040 /* static */ int32 ScriptDate::GetDayOfMonth(int32 date)
00041 {
00042   if (date < 0) return -1;
00043 
00044 	::YearMonthDay ymd;
00045 	::ConvertDateToYMD(date, &ymd);
00046   return ymd.day;
00047 }
00048 
00049 /* static */ int32 ScriptDate::GetDate(int32 year, int32 month, int32 day_of_month)
00050 {
00051   if (month < 1 || month > 12) return -1;
00052   if (day_of_month < 1 || day_of_month > 31) return -1;
00053   if (year < 0 || year > MAX_YEAR) return -1;
00054 
00055   return ::ConvertYMDToDate(year, month - 1, day_of_month);
00056 }
00057 
00058 /* static */ int32 ScriptDate::GetSystemTime()
00059 {
00060   time_t t;
00061   time(&t);
00062   return t;
00063 }