When gameTime is not specified (i.e. defaults to -1), the Now()gameTime will be used.
Day and Month have an additional boolshiftForNumbericalDisplay, which is false by default. When true, the value returned will be 1 higher, since humans don't use "0" for the first day or month.
publicint GameTime => _gameTime; // Returns an int// Return intspublicintMinute(int gameTime =-1)public int Hour(int gameTime =-1)public int Day(int gameTime =-1,bool shiftForNumericalDisplay =false)public int Week(int gameTime =-1)public int Month(int gameTime =-1,bool shiftForNumericalDisplay =false)public int Season(int gameTime =-1)public int Year(int gameTime =-1)// Return stringspublic string DayName(int gameTime =-1)public string MonthName(int gameTime =-1)public string SeasonName(int gameTime =-1)public int DaysPerWeekpublic int NumberOfMonthspublic int NumberOfSeasonspublic int DaysPerMonthpublic int MinutesPerHourpublic int HoursPerDaypublic int DaysPerYearpublic int DaysPerSeason // There could be different number of days per season if the year is not divisible!public int WeeksPerYear // Any last partial week is counted!public float DaysPerSeasonFloatpublic float WeeksPerYearFloat// In-game timepublic float SecondsPerGameMinutepublic float SecondsPerGameHourpublic float SecondsPerGameDaypublic float SecondsPerGameWeekpublic float SecondsPerGameMonthpublic float SecondsPerGameSeasonpublic float SecondsPerGameYear// 1 in-game minute = 1 "GameMinute" -- these are the same as "MinutesPer"public int GameTimePerHour => minutesPerHour; // minutesPerHour is the same as GameTimePerHour!publicint GameTimePerDaypublicint GameTimePerWeekpublicint GameTimePerMonthpublicint GameTimePerSeasonpublicint GameTimePerYear
Methods
The Gametime Module contains many methods which perform time and date calculations, and may be quite convenient for your project.
FullDate() returns a human-readable string, and can be formatted in a variety of ways.
publicfloatNow(bool includeSubtime =true)// Returns Now() plus or minus a gameTime value based on the read-world minutespublic float LaterRealTime(float realWorldMinutes)public float EarlierRealTime(float realWorldMinutes)// Returns Now() plus or minus the values in the provided TimeSpan objectpublic float Later(TimeSpan span)public float Earlier(TimeSpan span)// Returns Now() plus or minus the values providedpublic float Later(float seconds =0f,float minutes =0f,float hours =0f,float days =0f,float weeks =0f,float months =0f,float seasons =0f,float years =0f)public float Earlier(float seconds =0f,float minutes =0f,float hours =0f,float days =0f,float weeks =0f,float months =0f,float seasons =0f,float years =0f)// Gets the gameTime for the start of the season in the year providedpublic float SeasonGameTime(int season,int year =-1) // -1 = Current Year
We use Real Seconds for converting between real-world time and in-game gameTime, because it is the lowest common measurement, using the variable realWorldSecondsPerGameMinute
This value is the basis for all in-game time.
DatePart comparisons to gameTime
When gameTime is not provided, it defaults to Now()
// Returns the current lowest value of datePart compared to the next greatest// denominator.publicintGetDatePart(DatePart datePart,float gameTime =-1)// Returns the selected datePart since the last comparison DatePartpublic float DatePartInto(DatePart datePart,DatePart comparison,float gameTime =-1)// Returns the datePart until the next comparison DatePartpublic float DatePartUntil(DatePart datePart,DatePart comparison,float gameTime =-1)
Examples
// Hours until the next day startsvar hoursUntilMidnight =DatePartUntil(DatePart.Hour,DatePart.Day);// Days into the current season, for a specific gameTimevar daysIntoSeason =DatePartInto(DatePart.Day,DatePart.Season, savedGameTime);
These helper methods may be more convenient to use.