Custom Calendars

You can create custom calendars to display your data. Start by creating a flat text file with a row for the starting date for each period. This table of dates must have a specific set of columns. The first column is named Date with type date, and the second column is Year with type integer. The other optional columns, also of type integer, can be: Half, Quarter, Tertile, Month, or Week. A year period type is always generated, and then a period type is generated for each other integer column. For example, a calendar table with columns Date, Year, Quarter, and Month has period types year, year-quarter, and year-month.

Each row in the calendar table must have a unique date, and the dates must be in chronological order. Each row should also specify a unique combination of periods, representing the first date in each range. For example, in a custom calendar with Year, Quarter, and Month period values, rows should be as shown in the following table:

Date Year Quarter Month
2017/02/01 2017 2 4
2017/03/01 2017 3 1
2017/04/01 2017 3 2
2017/05/01 2017 3 3

The non-date columns specify the values for the other period elements for the particular date in that record. For example, the following record:

Date Year Quarter Month
2017/02/03 2017 2 4

specifies that Feb 3, 2017 is to be considered in the custom year 2017, in the second quarter, and in the fourth month of that year.

The following group of records:

Date Year Month
2017/01/01 2017 1
2017/01/29 2017 2
2017/02/26 2017 3

specify that all days from Jan 1, 2017 to Jan 28th are in the period Month 1; Jan 29, 2017 to Feb 25th are in period Month 2; Feb 26, 2017 starts period Month 3. When Spectre creates the custom calendar from such chronological records, it fills in the gaps.

The custom calendar table can be built into a cBase, or can be left as a text file and built as part of the calendar declaration. An example Build script for a cBase:

build {
  text-input "fiscal.txt" {
    column "Date" type="date"
    column "Year" type="integer"
    column "Quarter" type="integer"
    column "Month" type="integer"
  }
  output "fiscal.cbase"
}

This cBase can be used in a calendar declaration like this:

calendar "fiscal" type="custom" {
  cbase-input "fiscal.cbase"
}

Alternatively, you could skip the cBase and put the text-input directly in the calendar declaration. While this is simpler, it might be slower. Here's an example calendar declaration that uses the text file:

calendar "fiscal" type="custom" {
  text-input "fiscal.txt" {
    column "Date" type="date"
    column "Year" type="integer"
    column "Quarter" type="integer"
    column "Month" type="integer"
  }
}

Note that the period types generated for the custom calendar have default formats, unless you override them with period tags. For example:

calendar "fiscal" type="custom" {
  cbase-input "fiscal.cbase"
  period "year-month" format="\\MMM YYYY"
  period "year-quarter" format="\\QQ YYYY"
}

Here the \\M is used to denote the literal character 'M', as opposed to M as part of a format string. In this case, \\MMM matches M01, M02, M03, such as for January, February, March). MMM, without the literal with backslashes, represents the three-character month abbreviation, such as Jan, Feb, Mar.

See also: Creating a Custom Calendar.