OpenTTD GameScript API 20241221-master-g2176d49a39
Public Types | Static Public Member Functions
GSDate Class Reference

Class that handles all date related (calculation) functions. More...

#include <script_date.hpp>

Inheritance diagram for GSDate:

Public Types

enum  Date { DATE_INVALID }
 Date data type is an integer value. More...
 

Static Public Member Functions

static bool IsValidDate (Date date)
 Validates if a date value represent a valid date.
 
static Date GetCurrentDate ()
 Get the current date.
 
static int GetYear (Date date)
 Get the year of the given date.
 
static int GetMonth (Date date)
 Get the month of the given date.
 
static int GetDayOfMonth (Date date)
 Get the day (of the month) of the given date.
 
static Date GetDate (int year, int month, int day_of_month)
 Get the date given a year, month and day of month.
 
static int GetSystemTime ()
 Get the time of the host system.
 

Detailed Description

Class that handles all date related (calculation) functions.

Note
Months and days of month are 1-based; the first month of the year is 1 and the first day of the month is also 1.
Years are zero based; they start with the year 0.
Dates can be used to determine the number of days between two different moments in time because they count the number of days since the year 0.

Calendar-Time

Calendar time measures the technological progression in the game.

Calendar time uses the Gregorian calendar with 365 or 366 days per year.

Economy-Time

Economy time measures the in-game time progression, while the game is not paused.

Depending on game settings economy time is represented differently:

Member Enumeration Documentation

◆ Date

Date data type is an integer value.

Use GSDate::GetDate to compose valid date values for a known year, month and day.

Enumerator
DATE_INVALID 

A value representing an invalid date.

Member Function Documentation

◆ GetCurrentDate()

static Date GSDate::GetCurrentDate ( )
static

Get the current date.

This is the number of days since epoch under the assumption that there is a leap year every 4 years, except when dividable by 100 but not by 400.

Returns
The current date.

◆ GetDate()

static Date GSDate::GetDate ( int  year,
int  month,
int  day_of_month 
)
static

Get the date given a year, month and day of month.

Parameters
yearThe year of the to-be determined date.
monthThe month of the to-be determined date.
day_of_monthThe day of month of the to-be determined date.
Returns
The date.

◆ GetDayOfMonth()

static int GSDate::GetDayOfMonth ( Date  date)
static

Get the day (of the month) of the given date.

Parameters
dateThe date to get the day of.
Returns
The day.

◆ GetMonth()

static int GSDate::GetMonth ( Date  date)
static

Get the month of the given date.

Parameters
dateThe date to get the month of.
Returns
The month.

◆ GetSystemTime()

static int GSDate::GetSystemTime ( )
static

Get the time of the host system.

Returns
The amount of seconds passed since 1 Jan 1970.
Note
This uses the clock of the host system, which can skew or be set back. Use with caution.

◆ GetYear()

static int GSDate::GetYear ( Date  date)
static

Get the year of the given date.

Parameters
dateThe date to get the year of.
Returns
The year.

◆ IsValidDate()

static bool GSDate::IsValidDate ( Date  date)
static

Validates if a date value represent a valid date.

Parameters
dateThe date to validate.
Returns
True if the date is valid, otherwise false