1 /*
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/>.
6  */
7 
8 /** @file script_date.hpp Everything to query and manipulate date related information. */
9 
10 #ifndef SCRIPT_DATE_HPP
11 #define SCRIPT_DATE_HPP
12 
13 #include "script_object.hpp"
14 #include "../../date_type.h"
15 
16 /**
17  * Class that handles all date related (calculation) functions.
18  * @api ai game
19  *
20  * @note Months and days of month are 1-based; the first month of the
21  *       year is 1 and the first day of the month is also 1.
22  * @note Years are zero based; they start with the year 0.
23  * @note Dates can be used to determine the number of days between
24  *       two different moments in time because they count the number
25  *       of days since the year 0.
26  */
27 class ScriptDate : public ScriptObject {
28 public:
29 	/**
30 	 * Date data type is an integer value. Use ScriptDate::GetDate to
31 	 * compose valid date values for a known year, month and day.
32 	 */
33 	enum Date {
34 		DATE_INVALID = ::INVALID_DATE, ///< A value representing an invalid date.
35 	};
36 
37 	/**
38 	 * Validates if a date value represent a valid date.
39 	 * @param date The date to validate.
40 	 * @return True if the date is valid, otherwise false
41 	 */
42 	static bool IsValidDate(Date date);
43 
44 	/**
45 	 * Get the current date.
46 	 * This is the number of days since epoch under the assumption that
47 	 *  there is a leap year every 4 years, except when dividable by
48 	 *  100 but not by 400.
49 	 * @return The current date.
50 	 */
51 	static Date GetCurrentDate();
52 
53 	/**
54 	 * Get the year of the given date.
55 	 * @param date The date to get the year of.
56 	 * @return The year.
57 	 */
58 	static int32 GetYear(Date date);
59 
60 	/**
61 	 * Get the month of the given date.
62 	 * @param date The date to get the month of.
63 	 * @return The month.
64 	 */
65 	static int32 GetMonth(Date date);
66 
67 	/**
68 	 * Get the day (of the month) of the given date.
69 	 * @param date The date to get the day of.
70 	 * @return The day.
71 	 */
72 	static int32 GetDayOfMonth(Date date);
73 
74 	/**
75 	 * Get the date given a year, month and day of month.
76 	 * @param year The year of the to-be determined date.
77 	 * @param month The month of the to-be determined date.
78 	 * @param day_of_month The day of month of the to-be determined date.
79 	 * @return The date.
80 	 */
81 	static Date GetDate(int32 year, int32 month, int32 day_of_month);
82 
83 	/**
84 	 * Get the time of the host system.
85 	 * @return The amount of seconds passed since 1 Jan 1970.
86 	 * @api -ai
87 	 * @note This uses the clock of the host system, which can skew or be set back. Use with caution.
88 	 */
89 	static int32 GetSystemTime();
90 };
91 
92 #endif /* SCRIPT_DATE_HPP */
93