Skip to main content
Version: 1.2.x

Hooks

Here are all the hooks that Simple Calendar emits and when they are emitted.

How to Listen for a Hook

The global Simple Calendar object comes with a variable called hooks which will list all the available hooks that can be listened for.

Example:

SimpleCalendar.Hooks.DateTimeChange

The current hooks that are emitted are:

Hook NameValueDescription
DateTimeChange"simple-calendar-date-time-change"This hook is emitted any time the current date is updated.
ClockStartStop"simple-calendar-clock-start-stop"This hook is emitted any time the clock is started/stopped or paused.

Date/Time Change

When it is emitted

This hook is emitted any time the current date is updated. The current date can be updated by several means:

What is passed

When this hook is emitted it will pass a data object that contains information about the new current day. The object will have these top level properties:

Property NameDefault ValueDescription
year{} - Empty ObjectThis property will contain all information about the current year.
For a breakdown of that information see below.
month{} - Empty ObjectThis property will contain all information about the current month.
For a breakdown of that information see below.
day{} - Empty ObjectThis property will contain all information about the current day.
For a breakdown of that information see below.
time{} - Empty ObjectThis property will contain all information about the current time.
For a breakdown of that information see below.
season{} - Empty ObjectThis property will contain all information about the current season.
For a breakdown of that information see below.
moons[] - Empty ArrayThis property will contain all information about the current moons.
For a breakdown of that information see below.

Year Properties

Property NameValue TypeDescription
numbernumberThis is the current years numerical representation.
prefixstringThis is the text that appears before the years numerical representation.
postfixstringThis is the test that appears after the years numerical representation.
isLeapYearbooleanIf this year is a leap year.

Month Properties

Property NameValue TypeDescription
numbernumberThe months numerical representation.
namestringThe name of the month.
numberOfDaysnumberHow many days are in this month.
numberOfLeapYearDaysnumberHow many days are in this month during a leap year.
intercalarybooleanIf this month is considered an intercalary month or not.

Day Properties

Property NameValue TypeDescription
numbernumberThe days numerical representation.

Time Properties

Property NameValue TypeDescription
hourstringThe number of hours into the day it currently is. This result is 0 padded.
minutestringThe number of minutes into the day it currently is. This result is 0 padded.
secondstringThe number of seconds into the day it currently is. This result is 0 padded.

Season Properties

Property NameValue TypeDescription
namestringThe name of the season.
colorstringThe hex color representation of the season.

Moon Properties

The moon properties is an array of moon objects, one for every moon in the calendar. The moon object is detailed below:

Property NameValue TypeDescription
namestringThe name of the moon.
colorstringThe hex color representation of the moon.
cycleLengthnumberThe number of calendar days for 1 cycle of the moon.
cycleDayAdjustnumberA entered adjustment used when calculating the current day of a cycle.
currentPhaseobjectAn object containing details about the phase the moon is in on this day.

Moon Phase Properties

Property NameValue TypeDescription
namestringThe name of this moon phase.
iconstringThe css class associated with this moons phase to give the proper icon.
lengthnumberHow many days of the cycle this phase lasts.
singleDaybooleanIf this phase should only happen on one day.

Examples

Hooking to

This is an example of how to listen for the hook:

Hooks.on(SimpleCalendar.Hooks.DateTimeChange, (data) => {
console.log(data);
});

Response Data

This is an example of the data that is passed with this hook:

{
"year": {
"number": 2021,
"prefix": "",
"postfix": "",
"isLeapYear": false
},
"month": {
"name": "April",
"number": 4,
"intercalary": false,
"numberOfDays": 30,
"numberOfLeapYearDays": 30
},
"day": {
"number": 13
},
"time": {
"hour": "00",
"minute": "00",
"second": "56"
},
"season": {
"name": "Spring",
"color": "#fffce8"
},
"moons": [
{
"name": "Moon",
"color": "#ffffff",
"cycleLength": 29.53059,
"cycleDayAdjust": 0.5,
"currentPhase": {
"name": "Waxing Crescent",
"length": 6.3826,
"icon": "waxing-crescent",
"singleDay": false
}
}
]
}

Clock Start/Stop

When it is emitted

This event is emitted in the followin cases:

  • When the clock is started.
  • When the clock is stopped.
  • When the game is paused or unpaused.
  • When a combat is started or ended in the active scene
  • When a combat round is advanced.

What is passed

When this hook is emitted it will pass a data object that contains the following properties:

Property NameValue TypeDescription
startedbooleanIf the clock is started and running.
stoppedbooleanIf the clock is stopped and not running.
pausedbooleanIf the clock is paused. The clock is paused when the game is paused or there is an active combat running in the active scene.

Examples

Hooking to

This is an example of how to listen for the hook:

Hooks.on(SimpleCalendar.Hooks.ClockStartStop, (data) => {
console.log(data);
});

Response Data

This is an example of the data that is passed with this hook:

{
"started": false,
"stopped": true,
"paused": false
}

Is Primary GM

When it is emitted

This eventn is emitted when the current users is promoted to the primary GM role.

This will happen 5 seconds after loading the game if no other GM is currently in the primary role.

What is passed

Property NameValue TypeDescription
isPrimaryGMbooleanIf the user is the primary gm (true).

Examples

Hooking to

This is an example of how to listen for the hook:

Hooks.on(SimpleCalendar.Hooks.PrimaryGM, (data) => {
console.log(data);
});

Response Data

This is an example of the data that is passed with this hook:

{
"isPrimaryGM": true
}