OpenTTD: src/date_func.h File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions | Variables
date_func.h File Reference

Functions related to dates. More...

`#include "date_type.h"`

Go to the source code of this file.

## Functions
void | SetDate (Date date, DateFract fract)
| Set the date.
void | ConvertDateToYMD (Date date, YearMonthDay *ymd)
| Converts a Date to a Year, Month & Day.
Date | ConvertYMDToDate (Year year, Month month, Day day)
| Converts a tuple of Year, Month and Day to a Date.
static bool | IsLeapYear (Year yr)
| Checks whether the given year is a leap year or not.

## Variables
Year | _cur_year
| Current year, starting at 0.
Month | _cur_month
| Current month (0..11)
Date | _date
| Current date in days (day counter)
DateFract | _date_fract
| Fractional part of the day.
uint16 | _tick_counter
| Ever incrementing (and sometimes wrapping) tick counter for setting off various events.

## Detailed Description

Functions related to dates.

Definition in file date_func.h.

## Function Documentation

void ConvertDateToYMD | ( | Date | date,
|  | YearMonthDay * | ymd
| ) |  |

Converts a Date to a Year, Month & Day.

Parameters

  date | the date to convert from
  ymd | the year, month and day to write to

Definition at line 94 of file date.cpp.

References YearMonthDay::day, DAYS_IN_LEAP_YEAR, DAYS_IN_YEAR, IsLeapYear(), YearMonthDay::month, and YearMonthDay::year.

Referenced by ClickChangeDateCheat(), NetworkGameWindow::DrawServerLine(), DrawVehiclePurchaseInfo(), SubsidyListWindow::DrawWidget(), CrashLog::FillCrashLog(), GetGlobalVariable(), GetSnowLine(), IncreaseDate(), SetDate(), SetDateWindow::SetDateWindow(), and SetYearEngineAgingStops().

Date ConvertYMDToDate | ( | Year | year,
|  | Month | month,
|  | Day | day
| ) |  |

Converts a tuple of Year, Month and Day to a Date.

Parameters

  year | is a number between 0..MAX_YEAR
  month | is a number between 0..11
  day | is a number between 1..31

Definition at line 149 of file date.cpp.

References _accum_days_for_month, DAYS_TILL, and IsLeapYear().

Referenced by ClickChangeDateCheat(), SaveLoadWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), FixTTOEngines(), GetGlobalVariable(), LoadNewGRF(), SetDateWindow::OnClick(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), NetworkUDPSocketHandler::ReceiveNetworkGameInfo(), ServerNetworkAdminSocketHandler::SendWelcome(), SetStartingYear(), GenerateLandscapeWindow::SetStringParameters(), CreateScenarioWindow::SetStringParameters(), StartupEngines(), StartupOneEngine(), CheatWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), and ScenarioEditorToolbarWindow::UpdateWidgetSize().

static bool IsLeapYear | ( | Year | yr | ) |
| inlinestatic

Checks whether the given year is a leap year or not.

Parameters

  yr | The year to check.

Returns
  True if `yr` is a leap year, otherwise false.

Definition at line 32 of file date_func.h.

Referenced by ConvertDateToYMD(), ConvertYMDToDate(), GetGlobalVariable(), and OnNewYear().

void SetDate | ( | Date | date,
|  | DateFract | fract
| ) |  |

Set the date.

Parameters

  date | New date
  fract | The number of ticks that have passed on this date.

Definition at line 37 of file date.cpp.

References _cur_month, _cur_year, _date, _date_fract, ConvertDateToYMD(), DAY_TICKS, YearMonthDay::month, and YearMonthDay::year.

Referenced by AfterLoadGame(), ClickChangeDateCheat(), and SetStartingYear().