Date Class
Date class is meant to encapsulate logic around months, years, days, hours. It should be able to do adjustments with regards to days in given month and so on. Date objects should be immutable and that is why date adjustments return new objects instead of modifying the current one.
Method Index
- _adjustDayOverflow()
- _adjustHoursOverflow()
- _adjustMonthOverflow()
- _adjustOverflow()
- clone()
- dayOfMonth()
- daysPerMonth(month)
- getProgressInMonths()
- hourOfDay()
- hoursPerDay()
- isLastDayOfMonth()
- isLastDayOfYear()
- isSameDay(other)
- lastDayOfMonth()
- monthOfGame()
- monthOfYear()
- plusDays(increment)
- plusHours(increment)
- plusMonths(increment)
- plusYears(increment)
- resetDayToFirst()
- tostring()
- year()
Member Index
- _day
- _hour
- _month
- _year
function Date:Date(year, month, day, hour)
Date constructor
Date is initialized by setting year, month day and hour in this order
the default day is 1-01-01T00 - if any of the components isn't set the
default value is used.
Parameters:
| Name | Type | Description |
|---|---|---|
| year | number | year of the new date |
| month | number | month of the new date |
| day | number | day of the new date |
| hour | number | hour of the new date |
Declared on: line 74 of Lua/date.lua.
function Date:_adjustDayOverflow()
PRIVATE Adjusts the days overflows
Method to deal with day being more or less than valid value
Declared on: line 333 of Lua/date.lua.
function Date:_adjustHoursOverflow()
PRIVATE Adjusts the hours overflows
Method to deal with hour being more or less than valid value
Declared on: line 315 of Lua/date.lua.
function Date:_adjustMonthOverflow()
PRIVATE Adjusts the months overflows
Method to deal with month being more or less than valid value
Declared on: line 350 of Lua/date.lua.
function Date:_adjustOverflow()
PRIVATE Adjusts all the overflows
Normalize date to fix all the overflows of hours, days and months. This
method is a key to date adjustments.
Declared on: line 360 of Lua/date.lua.
function Date:clone()
Clone the date
Creates another instance of date with a same value
Declared on: line 255 of Lua/date.lua.
function Date:dayOfMonth()
Returns the day of month
Finds out what is a current day in a date (1-31)
Declared on: line 181 of Lua/date.lua.
function Date.daysPerMonth(month)
Method that returns the number of days of a month.
--
--
Parameters:
| Name | Type | Description |
|---|---|---|
| month | 1 or 12 | Month being queried. -- |
Declared on: line 63 of Lua/date.lua.
Note: Is a function rather than a method.
function Date:getProgressInMonths()
Calculates the number of months played until a time an hour in the future. This is used in EndConditions
Declared on: line 277 of Lua/date.lua.
function Date:hourOfDay()
Returns the hour of the day
Finds out what is an hour of this date starting on 0 up to 49
Declared on: line 201 of Lua/date.lua.
function Date.hoursPerDay()
Method returns the number of game hours in one day
This should be use everywhere we query this information
Declared on: line 51 of Lua/date.lua.
Note: Is a function rather than a method.
function Date:isLastDayOfMonth()
Checks if date is a last day of a month
Finds out if the current day is a last day in current month with respect to
different month lengths.
Declared on: line 221 of Lua/date.lua.
function Date:isLastDayOfYear()
Checks if date is a last day of a year
Finds out if the current day is a last day in current month and current month
is a last month in a year.
Declared on: line 232 of Lua/date.lua.
function Date:isSameDay(other)
Checks the date
Checks the date with another passed as a parameter, but ignores time
Parameters:
| Name | Type | Description |
|---|---|---|
| other | Date | The other day to be compared |
Declared on: line 265 of Lua/date.lua.
function Date:lastDayOfMonth()
Returns the last day of the current month
This method finds the correct last day for current month of self. This number
is also the number of days within a month. Ignores leap years.
Declared on: line 97 of Lua/date.lua.
function Date:monthOfGame()
Returns the month of the game
Returns the number of months started since the start of the game. This
converts all the years to months and add them together with the started
months.
Declared on: line 243 of Lua/date.lua.
function Date:monthOfYear()
Returns the month of year
Finds out what is a month of this year (1-12)
Declared on: line 171 of Lua/date.lua.
function Date:plusDays(increment)
Adds days
Creates a copy of self with adjusted days.
Parameters:
| Name | Type | Description |
|---|---|---|
| increment | number | number to adjust, can be negative |
Declared on: line 132 of Lua/date.lua.
function Date:plusHours(increment)
Adds hours
Creates a copy of self with adjusted hours.
Parameters:
| Name | Type | Description |
|---|---|---|
| increment | number | number to adjust, can be negative |
Declared on: line 158 of Lua/date.lua.
function Date:plusMonths(increment)
Adds months
Creates a copy of self with adjusted months.
Parameters:
| Name | Type | Description |
|---|---|---|
| increment | number | number to adjust, can be negative |
Declared on: line 119 of Lua/date.lua.
function Date:plusYears(increment)
Adds years
Creates a copy of self with adjusted years.
Parameters:
| Name | Type | Description |
|---|---|---|
| increment | number | number to adjust, can be negative |
Declared on: line 145 of Lua/date.lua.
function Date:resetDayToFirst()
Returns the first day of the current month
This method finds the first day for current month of self.
Declared on: line 108 of Lua/date.lua.
function Date:tostring()
Return string representation
Returns string representation of the date in format y-mm-ddThh
Declared on: line 211 of Lua/date.lua.
function Date:year()
Returns the year
Finds out what is a current year of this date (1-X)
Declared on: line 191 of Lua/date.lua.