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/>.
8 /** @file script_date.hpp Everything to query and manipulate date related information. */
10 #ifndef SCRIPT_DATE_HPP
11 #define SCRIPT_DATE_HPP
13 #include "script_object.hpp"
14 #include "../../timer/timer_game_economy.h"
17 * Class that handles all date related (calculation) functions.
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.
27 * \anchor ScriptCalendarTime
30 * Calendar time measures the technological progression in the game.
31 * \li The calendar date is shown in the status bar.
32 * \li The calendar date affects engine model introduction and expiration.
33 * \li Progression of calendar time can be slowed or even halted via game settings.
35 * Calendar time uses the Gregorian calendar with 365 or 366 days per year.
37 * \anchor ScriptEconomyTime
40 * Economy time measures the in-game time progression, while the game is not paused.
41 * \li Cargo production and consumption follows economy time.
42 * \li Recurring income and expenses follow economy time.
43 * \li Production and income statistics and balances are created per economy month/quarter/year.
45 * Depending on game settings economy time is represented differently:
46 * \li Calendar-based timekeeping: Economy- and calendar-time use the identical Gregorian calendar.
47 * \li Wallclock-based timekeeping: Economy- and calendar-time are separate.
48 * Economy-time will use a 360 day calendar (12 months with 30 days each), which runs at a constant speed of one economy-month per realtime-minute.
49 * Calendar-time will use a Gregorian calendar, which can be slowed to stopped via game settings.
51 class ScriptDate
: public ScriptObject
{
54 * Date data type is an integer value. Use ScriptDate::GetDate to
55 * compose valid date values for a known year, month and day.
58 DATE_INVALID
= ::EconomyTime::INVALID_DATE
.base(), ///< A value representing an invalid date.
62 * Validates if a date value represent a valid date.
63 * @param date The date to validate.
64 * @return True if the date is valid, otherwise false
66 static bool IsValidDate(Date date
);
69 * Get the current date.
70 * This is the number of days since epoch under the assumption that
71 * there is a leap year every 4 years, except when dividable by
73 * @return The current date.
75 static Date
GetCurrentDate();
78 * Get the year of the given date.
79 * @param date The date to get the year of.
82 static SQInteger
GetYear(Date date
);
85 * Get the month of the given date.
86 * @param date The date to get the month of.
89 static SQInteger
GetMonth(Date date
);
92 * Get the day (of the month) of the given date.
93 * @param date The date to get the day of.
96 static SQInteger
GetDayOfMonth(Date date
);
99 * Get the date given a year, month and day of month.
100 * @param year The year of the to-be determined date.
101 * @param month The month of the to-be determined date.
102 * @param day_of_month The day of month of the to-be determined date.
105 static Date
GetDate(SQInteger year
, SQInteger month
, SQInteger day_of_month
);
108 * Get the time of the host system.
109 * @return The amount of seconds passed since 1 Jan 1970.
111 * @note This uses the clock of the host system, which can skew or be set back. Use with caution.
113 static SQInteger
GetSystemTime();
116 #endif /* SCRIPT_DATE_HPP */