WorldClock
WorldClock reads the calendar and sets the time of day and the date. WorldClock.Now gives you every part of the time in one read, as a WorldTime.
WorldTime the time in the game, in one read
WorldClock.Now gives you one of these, with the year, month, day, weekday, hour and minute in one read.
public struct WorldTime
{
public readonly int Year;
public readonly int Month;
public readonly int CalendarDay;
public readonly int Day;
public readonly DayOfWeek Weekday;
public readonly int Hour;
public readonly int Minute;
}
| Property | Type | What it means |
|---|---|---|
Year | int | The year. |
Month | int | The month, 1 to 12. |
CalendarDay | int | The day of the month. |
Day | int | The game’s day counter. It is a different number from CalendarDay. |
Weekday | DayOfWeek | The day of the week. |
Hour | int | The hour, 0 to 23. |
Minute | int | The minute, 0 to 59. |
WorldClock read the calendar, set the time and date
Use Now to read the time, SetTimeOfDay to set the hour and minute, and SetDate to set the date.
public static class WorldClock
{
public static int Year { get; }
public static int Month { get; }
public static int CalendarDay { get; }
public static bool IsAvailable { get; }
public static WorldTime Now { get; }
public static bool SetTimeOfDay(int hour, int minute);
public static bool SetDate(int year, int month, int day);
}
| Property | Type | What it means |
|---|---|---|
Year | int | The year. |
Month | int | The month. |
CalendarDay | int | The day of the month. GameTime.Day is the game’s day counter, a different value. |
IsAvailable | bool | true when the game clock exists. |
Now | WorldTime | Every part of the time in one read. All zero when not available. |
| Method | Returns | What it does |
|---|---|---|
SetTimeOfDay(hour, minute) | bool | Moves the clock forward to this time today. Hour 0 to 23, minute 0 to 59. |
SetDate(year, month, day) | bool | Sets the calendar date. Year 1 to 9999, month 1 to 12, day 3 to the last day of that month. |
Things to know
WorldTimeis a read-only snapshot.Nowfills it from the same calls as the separate reads, so it equals reading them one by one. WhenIsAvailableisfalse,Nowis all zero (WeekdayisSunday). (DayisGameTime.Day,WeekdayisGameTime.DayOfWeek,HourandMinuteareGameTime.HourandGameTime.Minute.)WorldClockhas no minute event.TimeControl.MinutePassedfires once for each game minute, andEvents.HourPassedonce for each game hour.- Use
GameTimeto read the time of day and the day counter.WorldClockadds the calendar reads and the two setters thatGameTimedoes not have. SetTimeOfDayonly moves the clock forward. The minute is placed in the middle of its minute so it reads back as that minute. (It calls the game’sTimeOfDayAzure.SetTimeline, which takes hours from 0 to 24.)SetTimeOfDayreturnsfalsewhen the time is earlier than the game’s current time, seconds included, because the game does not move the day back. Use a later time, or wait for the next day. It also returnsfalsewhile a save is loading or being written, and when the game’s timeline value cannot be read.- Moving the clock backwards with the game’s own calls makes the game think midnight passed, and it then advances its timers by the difference it sees.
SetTimeOfDayrefuses an earlier time, so it never does this. (The calls areTimeOfDayAzure.SetTimelineand the developer console.) SetDatesets the calendar date only. It throws anArgumentExceptionfor a year outside 1 to 9999, a month outside 1 to 12, or a day outside 3 to the last day of the month. It works forwards and backwards. (It calls the game’sTimeOfDayAzure.SetDate, the call the game itself makes on a save load. The game’s calendar throws on year 0 and clamps a bad day.)SetDatechanges nothing but the calendar. The time of day, the game’s day counter (GameTime.Day) and every timer stay as they are, and it raises noEvents.DayPassed.- Things that depend on the weekday or the day of the month react at the next minute. The weekday follows the date. NPC schedules, rent day (Sunday), and the weekly, biweekly and monthly subscription, invoice and bank payment checks all notice the new date. A low day of the month can make a payment come due. The date is saved with the game. (
PlayerSubscription.CheckDateAndTriggercompares the day of the month with the days since its last check.) - Setting the time does not fire
Events.HourPassedorEvents.DayPassedby itself. Those follow the game’s own clock. GameTime.IsDaytimeis the game’s own rule for day. Day is the hours 6 to 20, so 6:00 to 20:59. The game’s plants use the same rule. The answer depends on the hour alone, not on the sun’s position, and it can lagGameTime.Hourslightly. (It isTimeOfDayAzure.IsItDay. It reads the cachedcurrentTimeAndDay, which is refreshed once per in-game minute and not while time updates are disabled.)
Limits
SetDatereturnsfalsein some cases: while a save is loading or being written, when the clock is not available, and while the game has time updates off, which is just after a scene starts. A date set then would be taken for a new day.- Days 1 and 2 of a month can’t be set. The game never holds those days: when a day change lands on day 1, the game moves the date to day 3. So the date checks that compare the day of the month with a stored one have never run on those days. (
TimeOfDayAzure.IncreaseDayCounterdoes the move. The checks are inPlayerSubscription.) - Timers, perishables, mail and crops do not follow the calendar date. They use the game’s day counter, the hour and the minute, which
SetDatedoes not touch. - You can’t set the game’s day counter. The game has no setter for it, only a call that adds a day and fires the day event. (
dayCounterhas onlyIncreaseDayCounter.)