Class GameDate
java.lang.Object
net.risingworld.api.utils.GameDate
- All Implemented Interfaces:
Comparable<GameDate>
Represents an ingame date and time of day. This object is immutable, i.e it's a
snapshot of the current ingame time and does not change when the ingame time passes.
Use
The game has no months: A year consists of 4 seasons (spring, summer, autumn and winter) with
A "time of day" is always represented by the minutes since midnight (0-1439), e.g. 450 for 7:30 am.
Server.getGameDate() to get the current ingame date.The game has no months: A year consists of 4 seasons (spring, summer, autumn and winter) with
Seasons.DAYS_PER_SEASON days per season. A day has 24 hours.A "time of day" is always represented by the minutes since midnight (0-1439), e.g. 450 for 7:30 am.
- Example: Check if it's night and print the current date
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNumber of days per yearstatic final intNumber of minutes per daystatic final intTime of day when the sunrise ends (8:00 am, minutes since midnight)static final intTime of day when the sunrise starts (7:00 am, minutes since midnight).static final intTime of day when the sunset ends (10:00 pm, minutes since midnight)static final intTime of day when the sunset starts (9:00 pm, minutes since midnight). -
Method Summary
Modifier and TypeMethodDescriptionintbooleanintgetDay()Gets the day of year (1-124).intGets the day within the season (1-31).intgetHour()Gets the hour (0-23).intGets the minute (0-59).Gets the season according to the calendar, i.e. based on the day of year.intGets the time of day, i.e. the minutes since midnight (0-1439).intGets the total amount of minutes since the beginning of year 0.intgetYear()Gets the year.inthashCode()booleanisNight()Gets whether or not it's night, i.e. afterSUNSET_START(9:00 pm) and beforeSUNRISE_START(7:00 am).static booleanisNight(int timeOfDay) Gets whether or not the provided time of day is at night, i.e. afterSUNSET_START(9:00 pm) and beforeSUNRISE_START(7:00 am).static GameDateof(int year, int day, int hour, int minute) Creates a new game date.static GameDateofTotalMinutes(int totalMinutes) Creates a game date from the total amount of minutes, i.e the value returned bygetTotalMinutes().plusMinutes(int minutes) Returns a new date with the provided amount of minutes added (or subtracted, if negative).toString()
-
Field Details
-
DAYS_PER_YEAR
public static final int DAYS_PER_YEARNumber of days per year- See Also:
-
MINUTES_PER_DAY
public static final int MINUTES_PER_DAYNumber of minutes per day- See Also:
-
SUNRISE_START
public static final int SUNRISE_STARTTime of day when the sunrise starts (7:00 am, minutes since midnight). The night ends at this time- See Also:
-
SUNRISE_END
public static final int SUNRISE_ENDTime of day when the sunrise ends (8:00 am, minutes since midnight)- See Also:
-
SUNSET_START
public static final int SUNSET_STARTTime of day when the sunset starts (9:00 pm, minutes since midnight). The night begins after this time- See Also:
-
SUNSET_END
public static final int SUNSET_ENDTime of day when the sunset ends (10:00 pm, minutes since midnight)- See Also:
-
-
Method Details
-
of
Creates a new game date.- Parameters:
year- the year (new worlds start in year 1).day- the day of the year (1-124).hour- the hour of the day (0-23).minute- the minute (0-59).- Returns:
- the new date object.
- Throws:
IllegalArgumentException- if a value is out of range.
-
ofTotalMinutes
Creates a game date from the total amount of minutes, i.e the value returned bygetTotalMinutes(). Useful to restore a date you've stored previously (e.g. in a database).- Parameters:
totalMinutes- the total amount of minutes.- Returns:
- the new date object.
- Throws:
IllegalArgumentException- if the value is negative.
-
getYear
public int getYear()Gets the year. New worlds start with year 1.- Returns:
- the year.
-
getDay
public int getDay()Gets the day of year (1-124).- Returns:
- the day of year.
-
getDayOfSeason
public int getDayOfSeason()Gets the day within the season (1-31).- Returns:
- the day within the season.
-
getSeason
Gets the season according to the calendar, i.e. based on the day of year. Note that the actual season of the server may differ, e.g. if seasons are disabled (seeServer.getCurrentSeason()).- Returns:
- the calendar season.
-
getTimeOfDay
public int getTimeOfDay()Gets the time of day, i.e. the minutes since midnight (0-1439).- Returns:
- the time of day.
-
getHour
public int getHour()Gets the hour (0-23).- Returns:
- the hour.
-
getMinute
public int getMinute()Gets the minute (0-59).- Returns:
- the minute.
-
getTotalMinutes
public int getTotalMinutes()Gets the total amount of minutes since the beginning of year 0. Useful to store a date (seeofTotalMinutes(int)) or to calculate the minutes between two dates.- Returns:
- the total amount of minutes.
-
plusMinutes
Returns a new date with the provided amount of minutes added (or subtracted, if negative). This object stays unchanged.- Parameters:
minutes- the amount of minutes to add.- Returns:
- the new date.
- Throws:
IllegalArgumentException- if the new date would be before year 0.ArithmeticException- if the new date would be out of range.
-
isNight
public boolean isNight()Gets whether or not it's night, i.e. afterSUNSET_START(9:00 pm) and beforeSUNRISE_START(7:00 am). This is the same time window in which the game skips the night if all players are sleeping.- Returns:
- true if it's night, false if not.
-
isNight
public static boolean isNight(int timeOfDay) Gets whether or not the provided time of day is at night, i.e. afterSUNSET_START(9:00 pm) and beforeSUNRISE_START(7:00 am).- Parameters:
timeOfDay- the time of day, i.e. the minutes since midnight (0-1439).- Returns:
- true if the time is at night, false if not.
-
compareTo
- Specified by:
compareToin interfaceComparable<GameDate>
-
equals
-
hashCode
-
toString
-