OpenTTD AI API  20240426-master-ga60a81f34e
Public Types | Static Public Member Functions
AIDate Class Reference

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

Inheritance diagram for AIDate:

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. More...
 
static Date GetCurrentDate ()
 Get the current date. More...
 
static SQInteger GetYear (Date date)
 Get the year of the given date. More...
 
static SQInteger GetMonth (Date date)
 Get the month of the given date. More...
 
static SQInteger GetDayOfMonth (Date date)
 Get the day (of the month) of the given date. More...
 
static Date GetDate (SQInteger year, SQInteger month, SQInteger day_of_month)
 Get the date given a year, month and day of month. More...
 

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.

Member Enumeration Documentation

◆ Date

Date data type is an integer value.

Use AIDate::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 AIDate::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 AIDate::GetDate ( SQInteger  year,
SQInteger  month,
SQInteger  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 SQInteger AIDate::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 SQInteger AIDate::GetMonth ( Date  date)
static

Get the month of the given date.

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

◆ GetYear()

static SQInteger AIDate::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 AIDate::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