Semaphor

Calendar Preferences

Configure timezone, week start, and date anchoring for accurate reporting

Overview

Calendar preferences control how timezone-sensitive operations work across Semaphor dashboards. They affect:

  • Relative date filters such as "this week", "last month", and "year to date"
  • Date aggregations like "group by week" or "group by month"
  • Date formatting in visualizations and exports

By default, Semaphor uses UTC with Monday as the first day of the week. You can override these defaults at multiple levels to match your users' locale and reporting conventions.

Store Timestamps in UTC

Semaphor assumes that timestamps in your database are stored in UTC. When a tz preference is set, Semaphor converts from UTC to the target timezone for display, filtering, and aggregation. If your data is stored in a local timezone instead of UTC, date calculations may produce incorrect results.


Preference Hierarchy

Semaphor resolves calendar preferences using a multi-level hierarchy. The first level that defines a property wins, checked from top to bottom:

  1. Org User / Tenant User Preferences -- Individual org users and tenant users can set their own timezone and week start via the preferences dialog in the dashboard toolbar. These take the highest priority.
  2. Token Context -- Passed programmatically via params.calendarContext in the token request. Use this when you, as the developer, want to set the default timezone and week start for your customers in embedded dashboards.
  3. Tenant Defaults -- Defaults for all tenant users within a specific tenant, set by admins via the Management API.
  4. Organization Defaults -- Defaults for all org users and tenant users across the organization, set by admins via the Management API.
  5. System Default -- { tz: 'UTC', weekStart: 1, anchor: 'now' }

Independent Resolution

Each property (tz, weekStart, anchor) is resolved independently. For example, if a tenant user has set their timezone but not their week start, the timezone comes from the tenant user's preferences while week start falls through to the next level that has it configured.

Resolution for Tenant Users

For a tenant user, Semaphor checks in this order:

  1. Tenant user's own preferences
  2. Token calendarContext
  3. Tenant defaults
  4. Organization defaults
  5. System default

Resolution for Org Users

For an org user, Semaphor checks in this order:

  1. Org user's own preferences
  2. Token calendarContext
  3. Organization defaults
  4. System default

Tenant defaults do not apply to org users since they are not associated with a specific tenant.


Setting Calendar Preferences

Via Token Request (Developer)

Pass calendarContext inside params when requesting an authentication token. This is the most common approach for embedded dashboards where your application already knows the user's timezone.

const requestBody = {
  dashboardId: DASHBOARD_ID,
  dashboardSecret: DASHBOARD_SECRET,
  params: {
    calendarContext: { 
      tz: 'America/Chicago', 
      weekStart: 0, 
    }, 
  },
};
 
const response = await fetch(TOKEN_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(requestBody),
});

Security Note

The token generation function must be run on the server side. Do not expose DASHBOARD_SECRET in client-side code in production.

Organization Defaults (Admin)

Set default calendar preferences for all org users and tenant users across the organization using the Management API:

curl -X PUT https://semaphor.cloud/api/management/v1/organizations/{orgId} \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {token}" \
  -d '{
    "defaultCalendarContext": {
      "tz": "America/New_York",
      "weekStart": 0
    }
  }'

Tenant Defaults (Admin)

Override organization defaults for all tenant users within a specific tenant:

curl -X PUT https://semaphor.cloud/api/management/v1/tenants/{tenantId} \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {token}" \
  -d '{
    "defaultCalendarContext": {
      "tz": "Europe/London",
      "weekStart": 1
    }
  }'

Org User and Tenant User Preferences

Individual org users and tenant users can set their own preferences through the calendar preferences dialog in the dashboard toolbar. These preferences take the highest priority and override token, tenant, and organization defaults.


How It Affects Your Dashboard

Week Start and Relative Date Filters

The weekStart value determines how "this week" and other week-relative filters are calculated.

For the week containing January 8, 2025:

weekStart"This Week" Range
1 (Monday)Mon Jan 6 -- Sun Jan 12
0 (Sunday)Sun Jan 5 -- Sat Jan 11

This also affects "group by week" aggregations -- each bucket starts on the configured weekStart day.

Timezone and Date Boundaries

Timezone determines which calendar date a timestamp falls on. Consider a sale recorded at 11:00 PM EST on January 15:

tzDisplayed Date
'UTC'January 16 (4:00 AM UTC)
'America/New_York'January 15 (11:00 PM EST)

Setting the correct timezone ensures records appear on the date your org users and tenant users expect.

Date Anchoring

By default, anchor is set to 'now', meaning relative date filters use the current time. For reproducible or historical views, pass a fixed ISO timestamp:

{
  "calendarContext": {
    "tz": "America/New_York",
    "anchor": { "iso": "2025-01-15T00:00:00" }
  }
}

With this configuration, "last 7 days" always resolves relative to January 15, 2025 -- regardless of when the dashboard is viewed.


Calendar Context Properties

Calendar preferences are expressed as a calendarContext object with three properties:

PropertyTypeDefaultDescription
tzstring'UTC'IANA timezone identifier (e.g., 'America/Chicago', 'Europe/London')
weekStart0-61First day of the week (0=Sunday, 1=Monday, ..., 6=Saturday)
anchor'now' or { iso: string }'now'Reference time for relative dates. Use a fixed ISO date for reproducible views.

Common weekStart Values

ValueDayRegions
0SundayUS, Canada, Japan
1MondayISO standard, Europe (default)
6SaturdayMiddle East

  • Tokens API -- Full API reference for calendar context in token requests
  • Filters -- How date filters work with calendar preferences
  • Token Options -- All available options when generating embed tokens