---
id: "SimpleCalendar.api"
title: "Namespace: api"
sidebar_label: "api"
custom_edit_url: null
pagination_next: null
pagination_prev: null
---

[SimpleCalendar](SimpleCalendar.md).api

The `SimpleCalendar.api` namespace contains functions and properties used to update the Simple Calendar module or get information from it.

## Enumerations

- [Calendars](../enums/SimpleCalendar.api.Calendars.md)
- [GameWorldTimeIntegrations](../enums/SimpleCalendar.api.GameWorldTimeIntegrations.md)
- [Icons](../enums/SimpleCalendar.api.Icons.md)
- [LeapYearRules](../enums/SimpleCalendar.api.LeapYearRules.md)
- [MoonYearResetOptions](../enums/SimpleCalendar.api.MoonYearResetOptions.md)
- [NoteRepeat](../enums/SimpleCalendar.api.NoteRepeat.md)
- [PresetTimeOfDay](../enums/SimpleCalendar.api.PresetTimeOfDay.md)
- [YearNamingRules](../enums/SimpleCalendar.api.YearNamingRules.md)

## References

### MoonIcons

Renames and re-exports [Icons](../enums/SimpleCalendar.api.Icons.md)

## Functions

### activateFullCalendarListeners

▸ **activateFullCalendarListeners**(`calendarId`, `onMonthChange?`, `onDayClick?`): `void`

This function is used to activate event listeners for calendars displayed with the [HandlebarHelpers.sc-full-calendar](../enums/HandlebarHelpers.md#sc-full-calendar).

If being used in a FoundryVTT application or FormApplication it is best called in the activateListeners function.

**`example`**
```javascript
SimpleCalendar.api.activateFullCalendarListeners('example_1');
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `undefined` | The ID of the HTML element of the calendar to activate listeners for. This is the same ID used in the [HandlebarHelpers.sc-full-calendar](../enums/HandlebarHelpers.md#sc-full-calendar). |
| `onMonthChange` | ``null`` \| `Function` | `null` | Optional function to be called when the month being viewed has changed. Returned parameters to the function are:<br/> - The direction moved, previous or next.<br/> - The options used to render the calendar, which includes the date being shown. |
| `onDayClick` | ``null`` \| `Function` | `null` | Optional function to be called when a day is clicked. Returned parameters to the function are:<br/>- The options used to render the calendar, which includes the selected date. |

#### Returns

`void`

___

### addNote

▸ **addNote**(`title`, `content`, `starDate`, `endDate`, `allDay`, `repeats`, `categories`, `calendarId?`, `macro?`): `Promise`\<`StoredDocument`\<`JournalEntry`\> \| ``null``\>

This function adds a new note to the calendar

**`example`**
```javascript
const newJournal = await SimpleCalendar.api.addNote('Christmas Day','Presents!', {year: 2022, month: 11, day: 24, hour: 0, minute: 0, seconds: 0}, {year: 2022, month: 11, day: 24, hour: 0, minute: 0, seconds: 0}, true, SimpleCalendar.api.NoteRepeat.Yearly, ['Holiday']);
// Will create a new note on Christmas day of 2022 that lasts all day and repeats yearly.
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `title` | `string` | `undefined` | The title of the new note |
| `content` | `string` | `undefined` | The contents of the new note |
| `starDate` | [`DateTime`](SimpleCalendar.md#datetime) | `undefined` | The date and time the note starts |
| `endDate` | [`DateTime`](SimpleCalendar.md#datetime) | `undefined` | The date and time the note ends (can be the same as the start date) |
| `allDay` | `boolean` | `undefined` | If the note lasts all day or if it has a specific time duration. Whether to ignore the time portion of the start and end dates. |
| `repeats` | [`NoteRepeat`](../enums/SimpleCalendar.api.NoteRepeat.md) | `undefined` | If the note repeats and how often it does |
| `categories` | `string`[] | `undefined` | A list of note categories to assign to this note |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to add the note too. If not provided the current active calendar will be used. |
| `macro` | ``null`` \| `string` | `null` | The ID of the macro that this note should execute when the in game time meets or exceeds the note time. Or null if no macro should be executed. |

#### Returns

`Promise`\<`StoredDocument`\<`JournalEntry`\> \| ``null``\>

The newly created JournalEntry that contains the note data, or null if there was an error encountered.

___

### advanceTimeToPreset

▸ **advanceTimeToPreset**(`preset`, `calendarId?`): `boolean`

Advance the date and time to match the next preset time.

**Important**: This function can only be run by users who have permission to change the date in Simple Calendar.

**`example`**
```javascript
//Assuming the current time is 11am, set the time to the next sunset
//Will result in the date staying the same but the time changing to 6pm
SimpleCalendar.api.advanceTimeToPreset(SimpleCalendar.api.PresetTimeOfDay.Sunset);

//Assuming the current time is 11am, set the time to the next sunrise
//Will result in the date advancing by 1 day and the time changing to 6am
SimpleCalendar.api.advanceTimeToPreset(SimpleCalendar.api.PresetTimeOfDay.Sunrise);
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `preset` | [`PresetTimeOfDay`](../enums/SimpleCalendar.api.PresetTimeOfDay.md) | `undefined` | The preset time that is used to set the time of day. |
| `calendarId` | `string` | `'active'` | Optional parameter specify the ID of the calendar to advance the time and date for. If not provided the current active calendar will be used. |

#### Returns

`boolean`

True if the date was set successfully, false if it was not.

___

### changeDate

▸ **changeDate**(`interval`, `calendarId?`): `boolean`

Changes the current date of Simple Calendar.
**Important**: This function can only be run by users who have permission to change the date in Simple Calendar.

**`example`**
```javascript
//Assuming a date of June 1, 2021 and user has permission to change the date
SimpleCalendar.api.changeDate({day: 1}); // Will set the new date to June 2, 2021

//Assuming a date of June 1, 2021 and user has permission to change the date
SimpleCalendar.api.changeDate({day: -1}); // Will set the new date to May 31, 2021

//Assuming a date of June 1, 2021 10:00:00 and user has permission to change the date
SimpleCalendar.api.changeDate({year: 1, month: 1, day: 1, hour: 1, minute: 1, second: 1}); // Will set the new date to July 2, 2022 11:01:01

//Assuming a date of June 1, 2021 10:00:00 and user has permission to change the date
SimpleCalendar.api.changeDate({second: 3600}); // Will set the new date to June 1, 2021 11:00:00
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `interval` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `undefined` | The interval objects properties are all optional so only those that are needed have to be set.<br/>Where each property is how many of that interval to change the current date by. |
| `calendarId` | `string` | `'active'` | Optional parameter specify the ID of the calendar to change the date on. If not provided the current active calendar will be used. |

#### Returns

`boolean`

True if the date change was successful and false if it was not.

___

### chooseRandomDate

▸ **chooseRandomDate**(`startingDate?`, `endingDate?`, `calendarId?`): [`DateTime`](SimpleCalendar.md#datetime)

Will choose a random date between the 2 passed in dates, or if no dates are passed in will choose a random date.

**`example`**
```javascript
SimpleCalendar.api.chooseRandomDate({year: 2021, month: 3, day: 0}, {year: 2021, month: 5, day: 1})

// {
//     day: 1
//     hour: 12
//     minute: 5
//     month: 4
//     second: 41
//     year: 2021
// }

SimpleCalendar.api.chooseRandomDate({year: 1900, month: 3}, {year: 2021, month: 5})
// {
//     day: 19
//     hour: 8
//     minute: 16
//     month: 3
//     second: 25
//     year: 1982
// }

SimpleCalendar.api.chooseRandomDate();
// {
//     day: 11
//     hour: 0
//     minute: 49
//     month: 8
//     second: 37
//     year: 3276
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `startingDate` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `{}` | The start date objects properties are all optional so only those needed have to be set.<br/>Where each property is the earliest date to be chosen when randomly selecting a date.<br/>The month and day properties are both index's so January would be 0 and the first day of the month is also 0. |
| `endingDate` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `{}` | The end date objects properties are all optional so only those needed have to be set.<br/>Where each property is the latest date to be chosen when randomly selecting a date.<br/>The month and day properties are both index's so January would be 0 and the first day of the month is also 0. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to choose the random date from. If not provided the current active calendar will be used. |

#### Returns

[`DateTime`](SimpleCalendar.md#datetime)

A full date and time, where all properties will be randomly set. The month and day properties will be the index of the month/day chosen.

___

### clockStatus

▸ **clockStatus**(`calendarId?`): [`ClockStatus`](../interfaces/SimpleCalendar.ClockStatus.md)

Get the current status of the built-in clock for the specified calendar in Simple Calendar

**`example`**
```javascript
const status = SimpleCalendar.api.clockStatus();
console.log(status); // {started: false, stopped: true, paused: false}
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to check its clock status. If not provided the current active calendar will be used. |

#### Returns

[`ClockStatus`](../interfaces/SimpleCalendar.ClockStatus.md)

The clock status for the specified calendar.

___

### configureCalendar

▸ **configureCalendar**(`calendarData`, `calendarId?`): `Promise`\<`boolean`\>

Sets up the current calendar to match the passed in configuration. This function can only be run by GMs.

**`example`**
```javascript

//Set the calendar configuration to the Gregorian calendar
const result = await SimpleCalendar.api.configureCalendar(SimpleCalendar.api.Calendars.Gregorian);

//Set the calendar configuration to a custom calendar
const custom = {};

const result = await SimpleCalendar.api.configureCalendar(custom);
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarData` | [`Calendars`](../enums/SimpleCalendar.api.Calendars.md) \| [`CalendarData`](../interfaces/SimpleCalendar.CalendarData.md) | `undefined` | The configuration to set the calendar to. It can be one of the predefined calendars or a [SimpleCalendar.CalendarData](../interfaces/SimpleCalendar.CalendarData.md) object representing a custom calendar. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to configure. If not provided the current active calendar will be used. |

#### Returns

`Promise`\<`boolean`\>

A promise that resolves to a boolean value, true if the change was successful and false if it was not.

___

### dateToTimestamp

▸ **dateToTimestamp**(`date`, `calendarId?`): `number`

Converts the passed in date to a timestamp.

**`example`**
```javascript
SimpleCalendar.api.dateToTimestamp({}); //Returns the timestamp for the current date

SimpleCalendar.api.dateToTimestamp({year: 2021, month: 0, day: 0, hour: 1, minute: 1, second: 0}); //Returns 1609462860
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `date` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `undefined` | A date object (eg `{year:2021, month: 4, day: 12, hour: 0, minute: 0, second: 0}`) with the parameters set to the date that should be converted to a timestamp. Any missing parameters will default to the current date value for that parameter.<br/>**Important**: The month and day are index based so January would be 0 and the first day of the month will also be 0. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to use when converting a date to a timestamp. If not provided the current active calendar will be used. |

#### Returns

`number`

The timestamp for that date.

___

### formatDateTime

▸ **formatDateTime**(`date`, `format?`, `calendarId?`): `string` \| \{ `date`: `string` ; `time`: `string`  }

Converts the passed in date/time into formatted date and time strings that match the configured date and time formats or the passed in format string.

- Any missing date/time parameters will default to a value of 0.
- If the date/time parameters are negative, their value will be set to 0. The exception to this is the year parameter, it can be negative.
- If the date/time parameters are set to a value greater than possible (eg. the 20th month in a calendar that only has 12 months, or the 34th hour when a day can only have 24 hours) the max value will be used.

**`examples`**
```javascript
// Assuming that the default date and time formats are in place
// Date: Full Month Name Day, Year
// Time: 24Hour:Minute:Second

SimpleCalendar.api.formatDateTime({year: 2021, month: 11, day: 24, hour: 12, minute: 13, second: 14});
// Returns {date: 'December 25, 2021', time: '12:13:14'}

SimpleCalendar.api.formatDateTime({year: -2021, month: -11, day: 24, hour: 12, minute: 13, second: 14})
// Returns {date: 'January 25, -2021', time: '12:13:14'}

SimpleCalendar.api.formatDateTime({year: 2021, month: 111, day: 224, hour: 44, minute: 313, second: 314})
// Returns {date: 'December 31, 2021', time: '23:59:59'}

SimpleCalendar.api.formatDateTime({year: 2021, month: 111, day: 224, hour: 44, minute: 313, second: 314},"DD/MM/YYYY HH:mm:ss A")
// Returns "31/12/2021 23:59:00 PM"
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `date` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `undefined` | A date object (eg `{year:2021, month: 4, day: 12, hour: 0, minute: 0, second: 0}`) with the parameters set to the date and time that should be formatted.<br/>**Important**: The month and day are index based so January would be 0 and the first day of the month will also be 0. |
| `format` | `string` | `''` | Optional format string to return custom formats for the passed in date and time. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to use when converting a date to a formatted string. If not provided the current active calendar will be used. |

#### Returns

`string` \| \{ `date`: `string` ; `time`: `string`  }

If no format string is provided an object with the date and time formatted strings, as set in the configuration, will be returned. If a format is provided then a formatted string will be returned.

___

### getAllCalendars

▸ **getAllCalendars**(): [`CalendarData`](../interfaces/SimpleCalendar.CalendarData.md)[]

Gets the details of all calendars that have been configured in Simple Calendar

**`example`**
```javascript
const c = SimpleCalendar.api.getAllCalendars();
console.log(c); // Will contain a list of all calendars and their data
```

#### Returns

[`CalendarData`](../interfaces/SimpleCalendar.CalendarData.md)[]

Array of all calendars and their data.

___

### getAllMonths

▸ **getAllMonths**(`calendarId?`): [`MonthData`](../interfaces/SimpleCalendar.MonthData.md)[]

Gets the details for all the months of the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getAllMonths();
// Returns an array like this, assuming the Gregorian Calendar
// [
//     {
//         "id": "13390ed",
//         "name": "January",
//         "abbreviation": "Jan",
//         "numericRepresentation": 1,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "effafeee",
//         "name": "February",
//         "abbreviation": "Feb",
//         "numericRepresentation": 2,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 28,
//         "numberOfLeapYearDays": 29,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "25b48251",
//         "name": "March",
//         "abbreviation": "Mar",
//         "numericRepresentation": 3,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "e5e9782f",
//         "name": "April",
//         "abbreviation": "Apr",
//         "numericRepresentation": 4,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 30,
//         "numberOfLeapYearDays": 30,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "93f626f6",
//         "name": "May",
//         "abbreviation": "May",
//         "numericRepresentation": 5,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "22b4b204",
//         "name": "June",
//         "abbreviation": "Jun",
//         "numericRepresentation": 6,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 30,
//         "numberOfLeapYearDays": 30,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "adc0a7ca",
//         "name": "July",
//         "abbreviation": "Jul",
//         "numericRepresentation": 7,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "58197d71",
//         "name": "August",
//         "abbreviation": "Aug",
//         "numericRepresentation": 8,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "eca76bbd",
//         "name": "September",
//         "abbreviation": "Sep",
//         "numericRepresentation": 9,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 30,
//         "numberOfLeapYearDays": 30,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "6b0da33e",
//         "name": "October",
//         "abbreviation": "Oct",
//         "numericRepresentation": 10,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "150f5519",
//         "name": "November",
//         "abbreviation": "Nov",
//         "numericRepresentation": 11,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 30,
//         "numberOfLeapYearDays": 30,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     },
//     {
//         "id": "b67bc3ee",
//         "name": "December",
//         "abbreviation": "Dec",
//         "numericRepresentation": 12,
//         "numericRepresentationOffset": 0,
//         "numberOfDays": 31,
//         "numberOfLeapYearDays": 31,
//         "intercalary": false,
//         "intercalaryInclude": false,
//         "startingWeekday": null
//     }
// ]
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the list of months from. If not provided the current active calendar will be used. |

#### Returns

[`MonthData`](../interfaces/SimpleCalendar.MonthData.md)[]

Array of all months in the calendar.

___

### getAllMoons

▸ **getAllMoons**(`calendarId?`): [`MoonData`](../interfaces/SimpleCalendar.MoonData.md)[]

Gets the details for all the moons of the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getAllMoons();
// Returns an array like this, assuming the Gregorian Calendar
// [
//     {
//         "id": "2c26abfa",
//         "name": "Moon",
//         "color": "#ffffff",
//         "cycleLength": 29.53059,
//         "cycleDayAdjust": 0.5,
//         "firstNewMoon": {
//             "year": 2000,
//             "month": 1,
//             "day": 6,
//             "yearX": 0,
//             "yearReset": "none"
//         },
//         "phases": [
//             {
//                 "name": "New Moon",
//                 "length": 1,
//                 "icon": "new",
//                 "singleDay": true
//             },
//             {
//                 "name": "Waxing Crescent",
//                 "length": 6.3826,
//                 "icon": "waxing-crescent",
//                 "singleDay": false
//             },
//             {
//                 "name": "First Quarter",
//                 "length": 1,
//                 "icon": "first-quarter",
//                 "singleDay": true
//             },
//             {
//                 "name": "Waxing Gibbous",
//                 "length": 6.3826,
//                 "icon": "waxing-gibbous",
//                 "singleDay": false
//             },
//             {
//                 "name": "Full Moon",
//                 "length": 1,
//                 "icon": "full",
//                 "singleDay": true
//             },
//             {
//                 "name": "Waning Gibbous",
//                 "length": 6.3826,
//                 "icon": "waning-gibbous",
//                 "singleDay": false
//             },
//             {
//                 "name": "Last Quarter",
//                 "length": 1,
//                 "icon": "last-quarter",
//                 "singleDay": true
//             },
//             {
//                 "name": "Waning Crescent",
//                 "length": 6.3826,
//                 "icon": "waning-crescent",
//                 "singleDay": false
//             }
//         ],
//         "currentPhase": {
//             "name": "Waning Crescent",
//             "length": 6.3826,
//             "icon": "waning-crescent",
//             "singleDay": false
//         }
//     }
// ]
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the list of moons from. If not provided the current active calendar will be used. |

#### Returns

[`MoonData`](../interfaces/SimpleCalendar.MoonData.md)[]

Array of all moons in the calendar.

___

### getAllSeasons

▸ **getAllSeasons**(`calendarId?`): [`SeasonData`](../interfaces/SimpleCalendar.SeasonData.md)[]

Gets the details for all the seasons for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getAllSeasons();
// Returns an array like this, assuming the Gregorian Calendar
// [
//     {
//         color: "#fffce8",
//         id: "4916a231",
//         name: "Spring",
//         startingDay: 20,
//         startingMonth: 3,
//         sunriseTime: 21600,
//         sunsetTime: 64800
//     },
//     {
//         color: "#f3fff3",
//         id: "e596489",
//         name: "Summer",
//         startingDay: 20,
//         startingMonth: 6,
//         sunriseTime: 21600,
//         sunsetTime: 64800
//     },
//     {
//         color: "#fff7f2",
//         id: "3f137ee5",
//         name: "Fall",
//         startingDay: 22,
//         startingMonth: 9,
//         sunriseTime: 21600,
//         sunsetTime: 64800
//     },
//     {
//         color: "#f2f8ff",
//         id: "92f919a2",
//         name: "Winter",
//         startingDay: 21,
//         startingMonth: 12,
//         sunriseTime: 21600,
//         sunsetTime: 64800
//     }
// ]
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the list of seasons from. If not provided the current active calendar will be used. |

#### Returns

[`SeasonData`](../interfaces/SimpleCalendar.SeasonData.md)[]

Array of all seasons in the calendar.

___

### getAllWeekdays

▸ **getAllWeekdays**(`calendarId?`): [`WeekdayData`](../interfaces/SimpleCalendar.WeekdayData.md)[]

Gets the details about all the weekdays for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getAllWeekdays();
// Returns an array like this, assuming the Gregorian Calendar
// [
//     {
//         id: "dafbfd4",
//         name: "Sunday",
//         numericRepresentation: 1
//     },
//     {
//         id: "8648c7e9",
//         name: "Monday",
//         numericRepresentation: 2
//     }
//     {
//         id: "b40f3a20",
//         name: "Tuesday",
//         numericRepresentation: 3
//     },
//     {
//         id: "6c20a99e",
//         name: "Wednesday",
//         numericRepresentation: 4
//     },
//     {
//         id: "56c14ec7",
//         name: "Thursday",
//         numericRepresentation: 5
//     },
//     {
//         id: "2c732d04",
//         name: "Friday",
//         numericRepresentation: 6
//     },
//     {
//         id: "c8f72e3d",
//         name: "Saturday",
//         numericRepresentation: 7
//     }
// ]
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the list of weekdays from. If not provided the current active calendar will be used. |

#### Returns

[`WeekdayData`](../interfaces/SimpleCalendar.WeekdayData.md)[]

Array of all weekdays in the calendar.

___

### getCurrentCalendar

▸ **getCurrentCalendar**(): [`CalendarData`](../interfaces/SimpleCalendar.CalendarData.md)

Gets the details about the current active calendar.

**`example`**
```javascript
cosnt c = SimpleCalendar.api.getCurrentCalendar();
console.log(c); // Will contain all the configuration data for the current calendar.
```

#### Returns

[`CalendarData`](../interfaces/SimpleCalendar.CalendarData.md)

The current active calendars configuration.

___

### getCurrentDay

▸ **getCurrentDay**(`calendarId?`): [`DayData`](../interfaces/SimpleCalendar.DayData.md) \| ``null``

Gets the details about the current day for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getCurrentDay();
// Returns an object like this:
// {
//     id: "cbdb31cb",
//     name: "8",
//     numericRepresentation: 8
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the current day from. If not provided the current active calendar will be used. |

#### Returns

[`DayData`](../interfaces/SimpleCalendar.DayData.md) \| ``null``

The current day data or null if no current day can be found.

___

### getCurrentMonth

▸ **getCurrentMonth**(`calendarId?`): [`MonthData`](../interfaces/SimpleCalendar.MonthData.md) \| ``null``

Gets the details about the current month for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getCurrentMonth();
// Returns an object like this:
// {
//     abbreviation: "Jun",
//     id: "22b4b204",
//     intercalary: false,
//     intercalaryInclude: false,
//     name: "June",
//     numberOfDays: 30,
//     numberOfLeapYearDays: 30,
//     numericRepresentation: 6,
//     numericRepresentationOffset: 0,
//     startingWeekday: null
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the current month from. If not provided the current active calendar will be used. |

#### Returns

[`MonthData`](../interfaces/SimpleCalendar.MonthData.md) \| ``null``

The current month data or null if no current month can be found.

___

### getCurrentSeason

▸ **getCurrentSeason**(`calendarId?`): [`SeasonData`](../interfaces/SimpleCalendar.SeasonData.md)

Gets the details about the season for the current date of the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getCurrentSeason();
// Returns an object like this
// {
//     color: "#fffce8",
//     id: "4916a231",
//     name: "Spring",
//     startingDay: 19,
//     startingMonth: 2,
//     sunriseTime: 21600,
//     sunsetTime: 64800
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the current season from. If not provided the current active calendar will be used. |

#### Returns

[`SeasonData`](../interfaces/SimpleCalendar.SeasonData.md)

The current seasons data or an empty season data object if no current season can be found.

___

### getCurrentWeekday

▸ **getCurrentWeekday**(`calendarId?`): [`WeekdayData`](../interfaces/SimpleCalendar.WeekdayData.md) \| ``null``

Gets the details about the current weekday.

**`example`**
```javascript
SimpleCalendar.api.getCurrentWeekday();
// Returns an object like this
// {
//     id: "b40f3a20",
//     name: "Tuesday",
//     numericRepresentation: 3
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the current weekday from. If not provided the current active calendar will be used. |

#### Returns

[`WeekdayData`](../interfaces/SimpleCalendar.WeekdayData.md) \| ``null``

The current weekday data or null if no current weekday can be found.

___

### getCurrentYear

▸ **getCurrentYear**(`calendarId?`): [`YearData`](../interfaces/SimpleCalendar.YearData.md) \| ``null``

Gets the details about the current year for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getCurrentYear();
// Returns an object like this
// {
//     firstWeekday: 4,
//     id: "bbe5385c",
//     numericRepresentation: 2021,
//     postfix: "",
//     prefix: "",
//     showWeekdayHeadings: true,
//     yearNames: [],
//     yearNamesStart: 0,
//     yearNamingRule: "default",
//     yearZero: 1970
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the current year from. If not provided the current active calendar will be used. |

#### Returns

[`YearData`](../interfaces/SimpleCalendar.YearData.md) \| ``null``

The current year data or null if no current year can be found.

___

### getLeapYearConfiguration

▸ **getLeapYearConfiguration**(`calendarId?`): [`LeapYearData`](../interfaces/SimpleCalendar.LeapYearData.md) \| ``null``

Gets the details about how leap years are configured for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getLeapYearConfiguration();
// Returns an object like this
// {
//     customMod: 0,
//     id: "1468d034",
//     rule: "gregorian"
}
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the leap year configuration from. If not provided the current active calendar will be used. |

#### Returns

[`LeapYearData`](../interfaces/SimpleCalendar.LeapYearData.md) \| ``null``

The leap year configuration.

___

### getNotes

▸ **getNotes**(`calendarId?`): (`StoredDocument`\<`JournalEntry`\> \| `undefined`)[]

Gets all notes that the current user is able to see for the specified calendar.

**`example`**
```javascript
// Returns an array of JournalEntry objects
SimpleCalendar.api.getNotes();
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the notes from. If not provided the current active calendar will be used. |

#### Returns

(`StoredDocument`\<`JournalEntry`\> \| `undefined`)[]

A list of [JournalEntries](https://foundryvtt.com/api/JournalEntry.html) that contain the note data.

___

### getNotesForDay

▸ **getNotesForDay**(`year`, `month`, `day`, `calendarId?`): (`StoredDocument`\<`JournalEntry`\> \| `undefined`)[]

Gets all notes that the current user is able to see for the specified date from the specified calendar.

**`example`**
```javascript
// Returns an array of JournalEntry objects
SimpleCalendar.api.getNotesForDay(2022, 11, 24);
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `year` | `number` | `undefined` | The year of the date to get the notes for. |
| `month` | `number` | `undefined` | The index of the month to get the notes for. |
| `day` | `number` | `undefined` | The index of the day to get the notes for. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the notes from. If not provided the current active calendar will be used. |

#### Returns

(`StoredDocument`\<`JournalEntry`\> \| `undefined`)[]

A list of [JournalEntries](https://foundryvtt.com/api/JournalEntry.html)  that contain the note data.

___

### getTimeConfiguration

▸ **getTimeConfiguration**(`calendarId?`): [`TimeData`](../interfaces/SimpleCalendar.TimeData.md) \| ``null``

Get the details about how time is configured for the specified calendar.

**`example`**
```javascript
SimpleCalendar.api.getTimeConfiguration();
// Returns an object like this
// {
//     gameTimeRatio: 1,
//     hoursInDay: 24,
//     id: "d4791796",
//     minutesInHour: 60,
//     secondsInCombatRound: 6,
//     secondsInMinute: 60,
//     unifyGameAndClockPause: true,
//     updateFrequency: 1
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the time configuration from. If not provided the current active calendar will be used. |

#### Returns

[`TimeData`](../interfaces/SimpleCalendar.TimeData.md) \| ``null``

The time configuration.

___

### isPrimaryGM

▸ **isPrimaryGM**(): `boolean`

Get if the current user is considered the primary GM or not.

**`example`**
```javascript

SimpleCalendar.api.isPrimaryGM(); //True or Flase depending on if the current user is primary gm

```

#### Returns

`boolean`

If the current user is the primary GM.

___

### pauseClock

▸ **pauseClock**(`calendarId?`): `boolean`

Pauses the real time clock for the specified calendar. Only the primary GM can pause a clock.

**`example`**
```javascript
SimpleCalendar.api.pauseClock();
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to pause the real time clock for. If not provided the current active calendar will be used. |

#### Returns

`boolean`

True if the clock was paused, false otherwise

___

### removeNote

▸ **removeNote**(`journalEntryId`): `Promise`\<`boolean`\>

This function removes the specified note from Simple Calendar.

**`example`**
```javascript
SimpleCalendar.api.removeNote("asd123").then(...).catch(console.error);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `journalEntryId` | `string` | The ID of the journal entry associated with the note that is to be removed. |

#### Returns

`Promise`\<`boolean`\>

True if the note was removed or false if it was not.

___

### runMigration

▸ **runMigration**(): `void`

Run the migration from Simple Calendar version 1 to version 2.
This will only work if the current player is the primary GM.

A dialog will be shown to confirm if the GM wants to run the migration. This will prevent accidental running of the migration.

**`example`**
```javascript
SimpleCalendar.api.runMigration();
```

#### Returns

`void`

___

### searchNotes

▸ **searchNotes**(`term`, `options?`, `calendarId?`): (`StoredDocument`\<`JournalEntry`\> \| `undefined`)[]

Search the notes in Simple Calendar for a specific term. Only notes that the user can see are returned.

**`example`**
```javascript
SimpleCalendar.api.searchNotes("Note"); //Will return a list of notes that contained the word note somewhere in its content.

SimpleCalendar.api.searchNotes("Note", {title: true}); // Will return a list of notes that contain the world note in the title.

SimpleCalendar.api.searchNotes("Gamemaster", {author: true}); // Will return a list of notes that were written by the gamemaster.
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `term` | `string` | `undefined` | The text that is being searched for |
| `options` | `Object` | `undefined` | Options parameter to specify which fields of the note to use when searching, If not provided all fields are searched against. |
| `options.author` | `boolean` | `true` | - |
| `options.categories` | `boolean` | `true` | - |
| `options.date` | `boolean` | `true` | - |
| `options.details` | `boolean` | `true` | - |
| `options.title` | `boolean` | `true` | - |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar whose notes to search against. If not provided the current active calendar will be used. |

#### Returns

(`StoredDocument`\<`JournalEntry`\> \| `undefined`)[]

A list of [JournalEntry](https://foundryvtt.com/api/JournalEntry.html) that matched the term being searched.

___

### secondsToInterval

▸ **secondsToInterval**(`seconds`, `calendarId?`): [`DateTimeParts`](SimpleCalendar.md#datetimeparts)

Will attempt to parse the passed in seconds into larger time intervals.

**`example`**
```javascript
//Assuming a Gregorian Calendar
SimpleCalendar.api.secondsToInterval(3600); //Returns {year: 0, month: 0, day: 0, hour: 1, minute: 0, second 0}
SimpleCalendar.api.secondsToInterval(3660); //Returns {year: 0, month: 0, day: 0, hour: 1, minute: 1, second: 0}
SimpleCalendar.api.secondsToInterval(86400); //Returns {year: 0, month: 0, day: 1, hour: 0, minute: 0, second: 0}
SimpleCalendar.api.secondsToInterval(604800); //Returns {year: 0, month: 0, day: 7, hour: 0, minute: 0, second: 0}
SimpleCalendar.api.secondsToInterval(2629743); //Returns {year: 0, month: 1, day: 0, hour: 10, minute: 29, second: 3}
SimpleCalendar.api.secondsToInterval(31556926); //Returns {year: 1, month: 0, day: 0, hour: 5, minute: 48, second: 46}
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `seconds` | `number` | `undefined` | The number of seconds to convert to different intervals. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to use when calculating the intervals. If not provided the current active calendar will be used. |

#### Returns

[`DateTimeParts`](SimpleCalendar.md#datetimeparts)

An object containing the larger time intervals that make up the number of seconds passed in.

___

### setDate

▸ **setDate**(`date`, `calendarId?`): `boolean`

Will set the current date of the specified calendar to match the passed in date.
**Important**: This function can only be run by users who have permission to change the date in Simple Calendar.

**`example`**
```javascript
//To set the date to December 25th 1999 with the time 00:00:00
SimpleCalendar.setDate({year: 1999, month: 11, day: 24, hour: 0, minute: 0, second: 0});

//To set the date to December 31st 1999 and the time to 11:59:59pm
SimpleCalendar.setDate({year: 1999, month: 11, day: 30, hour: 23, minute: 59, second: 59});
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `date` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `undefined` | A date object (eg `{year:2021, month: 4, day: 12, hour: 0, minute: 0, second: 0}`) with the parameters set to the date that the calendar should be set to. Any missing parameters will default to the current date value for that parameter.<br/>**Important**: The month and day are index based so January would be 0 and the first day of the month will also be 0. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to set the date of. If not provided the current active calendar will be used. |

#### Returns

`boolean`

True if the date was set successfully, false otherwise.

___

### showCalendar

▸ **showCalendar**(`date?`, `compact?`, `calendarId?`): `void`

Will open up Simple Calendar to the current date, or the passed in date.

**`example`**
```javascript
//Assuming a Gregorian Calendar
SimpleCalendar.api.showCalendar(); // Will open the calendar to the current date.
SimpleCalendar.api.showCalendar({year: 1999, month: 11, day: 25}); // Will open the calendar to the date December 25th, 1999
SimpleCalendar.api.showCalendar(null, true); // Will open the calendar to the current date in compact mode.
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `date` | ``null`` \| [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `null` | A date object (eg `{year:2021, month: 4, day: 12}`) with the year, month and day set to the date to be visible when the calendar is opened.<br/>**Important**: The month is index based so January would be 0. |
| `compact` | `boolean` | `false` | If to open the calendar in compact mode or not. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to focus when the calendar view is opened. If not provided the current active calendar will be used. |

#### Returns

`void`

___

### startClock

▸ **startClock**(`calendarId?`): `boolean`

Starts the real time clock for the specified calendar. Only the primary GM can start a clock.

**`example`**
```javascript
SimpleCalendar.api.startClock();
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to start the real time clock for. If not provided the current active calendar will be used. |

#### Returns

`boolean`

True if the clock was started, false otherwise

___

### stopClock

▸ **stopClock**(`calendarId?`): `boolean`

Stops the real time clock for the specified calendar. Only the primary GM can stop a clock.

**`example`**
```javascript
SimpleCalendar.api.stopClock();
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to stop the real time clock for. If not provided the current active calendar will be used. |

#### Returns

`boolean`

True if the clock was stopped, false otherwise

___

### timestamp

▸ **timestamp**(`calendarId?`): `number`

Get the timestamp (in seconds) of the specified calendars currently set date.

**`example`**
```javascript
const timestamp = SimpleCalendar.api.timestamp();
console.log(timestamp); // This will be a number representing the current number of seconds passed in the calendar.
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to get the timestamp for. If not provided the current active calendar will be used. |

#### Returns

`number`

The time stamp of the calendar in seconds

___

### timestampPlusInterval

▸ **timestampPlusInterval**(`currentSeconds`, `interval`, `calendarId?`): `number`

Calculates a new timestamp from the passed in timestamp plus the passed in interval amount.

**`example`**
```javascript
let newTime = SimpleCalendar.api.timestampPlusInterval(0, {day: 1});
console.log(newTime); // this will be 0 + the number of seconds in 1 day. For most calendars this will be 86400

// Assuming Gregorian Calendar with the current date of June 1, 2021
newTime = SimpleCalendar.api.timestampPlusInterval(1622505600, {month: 1, day: 1});
console.log(newTime); // This will be the number of seconds that equal July 2nd 2021
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `currentSeconds` | `number` | `undefined` | The timestamp (in seconds) to have the interval added too. |
| `interval` | [`DateTimeParts`](SimpleCalendar.md#datetimeparts) | `undefined` | The interval objects properties are all optional so only those needed have to be set.<br/>Where each property is how many of that interval to increase the passed in timestamp by. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to use to calculate the new timestamp. If not provided the current active calendar will be used. |

#### Returns

`number`

The timestamp plus the passed in interval amount

___

### timestampToDate

▸ **timestampToDate**(`seconds`, `calendarId?`): [`DateData`](../interfaces/SimpleCalendar.DateData.md) \| ``null``

Converts a timestamp (in seconds) into a [SimpleCalendar.DateData](../interfaces/SimpleCalendar.DateData.md) objet from the specified calendar

**`example`**
```javascript
// Assuming Gregorian Calendar with the current date of June 1, 2021
let scDate = SimpleCalendar.api.timestampToDate(1622505600);
console.log(scDate);
// This is what the returned object will look like
// {
//     currentSeason: {color: "#fffce8", startingMonth: 3, startingDay: 20, name: "Spring"},
//     day: 0,
//     dayDisplay: "1",
//     dayOfTheWeek: 2,
//     dayOffset: 0,
//     display: {
//         date: "June 01, 2021",
//         day: "1",
//         daySuffix: "st",
//         month: "6",
//         monthName: "June",
//         time: "00:00:00",
//         weekday: "Tuesday",
//         year: "2021",
//         yearName: "",
//         yearPostfix: "",
//         yearPrefix: "",
//     },
//     hour: 0,
//     minute: 0,
//     month: 5,
//     monthName: "June",
//     second: 0,
//     showWeekdayHeadings: true,
//     weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
//     year: 2021,
//     yearName: "",
//     yearPostfix: "",
//     yearPrefix: "",
//     yearZero: 1970
// }
```

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `seconds` | `number` | `undefined` | The timestamp (in seconds) to convert into a date object. |
| `calendarId` | `string` | `'active'` | Optional parameter to specify the ID of the calendar to use to calculate the [SimpleCalendar.DateData](../interfaces/SimpleCalendar.DateData.md) objet. If not provided the current active calendar will be used. |

#### Returns

[`DateData`](../interfaces/SimpleCalendar.DateData.md) \| ``null``

A date object with information about the date the timestamp represents or null if the specified calendar can not be found
