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