Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

References

Renames and re-exports Icons

Functions

  • activateFullCalendarListeners(calendarId: string, onMonthChange?: null | Function, onDayClick?: null | Function): void
  • This function is used to activate event listeners for calendars displayed with the HandlebarHelpers.sc-full-calendar.

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

    example
    SimpleCalendar.api.activateFullCalendarListeners('example_1');
    

    Parameters

    • calendarId: string

      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.

    • onMonthChange: null | Function = null

      Optional function to be called when the month being viewed has changed. Returned parameters to the function are:
      - The direction moved, previous or next.
      - 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:
      - The options used to render the calendar, which includes the selected date.

    Returns void

  • addNote(title: string, content: string, starDate: DateTime, endDate: DateTime, allDay: boolean, repeats: NoteRepeat, categories: string[], calendarId?: string, macro?: null | string): Promise<StoredDocument<JournalEntry> | null>
  • This function adds a new note to the calendar

    example
    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

    • title: string

      The title of the new note

    • content: string

      The contents of the new note

    • starDate: DateTime

      The date and time the note starts

    • endDate: DateTime

      The date and time the note ends (can be the same as the start date)

    • allDay: boolean

      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

      If the note repeats and how often it does

    • categories: string[]

      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.

  • 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
    //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

    • preset: PresetTimeOfDay

      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(interval: DateTimeParts, calendarId?: string): 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
    //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

    • interval: DateTimeParts

      The interval objects properties are all optional so only those that are needed have to be set.
      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.

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

    example
    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

    • startingDate: DateTimeParts = {}

      The start date objects properties are all optional so only those needed have to be set.
      Where each property is the earliest date to be chosen when randomly selecting a date.
      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 = {}

      The end date objects properties are all optional so only those needed have to be set.
      Where each property is the latest date to be chosen when randomly selecting a date.
      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

    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.

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

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

    Parameters

    • 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

    The clock status for the specified calendar.

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

    example

    //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

    • calendarData: Calendars | CalendarData

      The configuration to set the calendar to. It can be one of the predefined calendars or a SimpleCalendar.CalendarData 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(date: DateTimeParts, calendarId?: string): number
  • Converts the passed in date to a timestamp.

    example
    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

    • date: DateTimeParts

      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.
      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(date: DateTimeParts, format?: string, calendarId?: string): 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
    // 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

    • date: DateTimeParts

      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.
      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.

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

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

    Returns CalendarData[]

    Array of all calendars and their data.

  • getAllMonths(calendarId?: string): MonthData[]
  • Gets the details for all the months of the specified calendar.

    example
    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

    • 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[]

    Array of all months in the calendar.

  • getAllMoons(calendarId?: string): MoonData[]
  • Gets the details for all the moons of the specified calendar.

    example
    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

    • 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[]

    Array of all moons in the calendar.

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

    example
    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

    • 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[]

    Array of all seasons in the calendar.

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

    example
    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

    • 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[]

    Array of all weekdays in the calendar.

  • Gets the details about the current active calendar.

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

    Returns CalendarData

    The current active calendars configuration.

  • getCurrentDay(calendarId?: string): DayData | null
  • Gets the details about the current day for the specified calendar.

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

    Parameters

    • 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 | null

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

  • getCurrentMonth(calendarId?: string): MonthData | null
  • Gets the details about the current month for the specified calendar.

    example
    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

    • 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 | null

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

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

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

    Parameters

    • 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

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

  • getCurrentWeekday(calendarId?: string): WeekdayData | null
  • Gets the details about the current weekday.

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

    Parameters

    • 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 | null

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

  • getCurrentYear(calendarId?: string): YearData | null
  • Gets the details about the current year for the specified calendar.

    example
    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

    • 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 | null

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

  • getLeapYearConfiguration(calendarId?: string): LeapYearData | null
  • Gets the details about how leap years are configured for the specified calendar.

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

    Parameters

    • 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 | null

    The leap year configuration.

  • getNotes(calendarId?: string): (StoredDocument<JournalEntry> | undefined)[]
  • Gets all notes that the current user is able to see for the specified calendar.

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

    Parameters

    • 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 that contain the note data.

  • getNotesForDay(year: number, month: number, day: number, calendarId?: string): (StoredDocument<JournalEntry> | undefined)[]
  • Gets all notes that the current user is able to see for the specified date from the specified calendar.

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

    Parameters

    • year: number

      The year of the date to get the notes for.

    • month: number

      The index of the month to get the notes for.

    • day: number

      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 that contain the note data.

  • getTimeConfiguration(calendarId?: string): TimeData | null
  • Get the details about how time is configured for the specified calendar.

    example
    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

    • 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 | null

    The time configuration.

  • isPrimaryGM(): boolean
  • Get if the current user is considered the primary GM or not.

    example

    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(calendarId?: string): boolean
  • Pauses the real time clock for the specified calendar. Only the primary GM can pause a clock.

    example
    SimpleCalendar.api.pauseClock();
    

    Parameters

    • 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(journalEntryId: string): Promise<boolean>
  • This function removes the specified note from Simple Calendar.

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

    Parameters

    • 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(): 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
    SimpleCalendar.api.runMigration();
    

    Returns void

  • searchNotes(term: string, options?: { author: boolean; categories: boolean; date: boolean; details: boolean; title: boolean }, calendarId?: string): (StoredDocument<JournalEntry> | undefined)[]
  • Search the notes in Simple Calendar for a specific term. Only notes that the user can see are returned.

    example
    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

    • term: string

      The text that is being searched for

    • options: { author: boolean; categories: boolean; date: boolean; details: boolean; title: boolean } = ...

      Options parameter to specify which fields of the note to use when searching, If not provided all fields are searched against.

      • author: boolean
      • categories: boolean
      • date: boolean
      • details: boolean
      • title: boolean
    • 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 that matched the term being searched.

  • secondsToInterval(seconds: number, calendarId?: string): DateTimeParts
  • Will attempt to parse the passed in seconds into larger time intervals.

    example
    //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

    • seconds: number

      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

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

  • 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
    //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

    • date: DateTimeParts

      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.
      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(date?: null | DateTimeParts, compact?: boolean, calendarId?: string): void
  • Will open up Simple Calendar to the current date, or the passed in date.

    example
    //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

    • date: null | 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.
      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(calendarId?: string): boolean
  • Starts the real time clock for the specified calendar. Only the primary GM can start a clock.

    example
    SimpleCalendar.api.startClock();
    

    Parameters

    • 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(calendarId?: string): boolean
  • Stops the real time clock for the specified calendar. Only the primary GM can stop a clock.

    example
    SimpleCalendar.api.stopClock();
    

    Parameters

    • 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(calendarId?: string): number
  • Get the timestamp (in seconds) of the specified calendars currently set date.

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

    Parameters

    • 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(currentSeconds: number, interval: DateTimeParts, calendarId?: string): number
  • Calculates a new timestamp from the passed in timestamp plus the passed in interval amount.

    example
    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

    • currentSeconds: number

      The timestamp (in seconds) to have the interval added too.

    • interval: DateTimeParts

      The interval objects properties are all optional so only those needed have to be set.
      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(seconds: number, calendarId?: string): DateData | null
  • Converts a timestamp (in seconds) into a SimpleCalendar.DateData objet from the specified calendar

    example
    // 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

    • seconds: number

      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 objet. If not provided the current active calendar will be used.

    Returns DateData | null

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