Global settings

Kontrl takes a few global settings so you don’t have to set these settings for every field.

Global settings can be set using the kontrl.settings command.

This command has to be run before all other commands

kontrl.settings({
  // Your settings
})

This command can be called multiple times and the settings will be merged automatically.

timestampFields settings

Many people use “created_at”, “inserted_at”, “changed_at”, “updated_at” or any other variation of timestamp fields in their database. You can define the name of those columns globally.

The defaults are created_at and changed_at

kontrl.settings({
  timestampFields: {
    // Tell Kontrl to look for inserted_at when inserted
    created_at: "inserted_at",
    // Tell kontrl to look for changed_at when updating
    updated_at: "changed_at"
  }
})

datetime settings

clockSize

The clockSize setting decides whether to use a 24h clock also known in some places as military time or to use a 12h clock notation using AM and PM.

kontrl.settings({
  datetime: {
    clockSize: "24h" // can also be "12h"
  }
});

dateNotation

The date notation defines what dates will look like. Generally there are 2 well known date formats “months_first” and “days_first”. Other date formats are exist and are only supported through the “detect” options.

Options:

  • detect Kontrl will use the browser settings to decide which one to use.
  • months_first example: 01/24/2020
  • days_first example: 24/01/2020
kontrl.settings({
  datetime: {
    dateNotation: "detect"
  }
});

useUserTimezone

This settings is a boolean which is false by default. If it is false, it does nothing. If it is true, Kontrl will transform datetime & time from the database into the timezone that the user has selected in their browser.

kontrl.settings({
  datetime: {
    useUserTimezone: false
  }
});

dataTimezone

This settings is a string which is undefined by default. It defines the timezone at which the datetime & times are stored. If this settings is not set, Kontrl will assume your data is being stored as UTC time (which is in our opinion the best practice).

Supports:

kontrl.settings({
  datetime: {
    dataTimezone: "UTC"
  }
});

originFormat

Used for datetime fields.

This settings is a string which is “iso” by default. It tells the system in which format your data is stored.

We recommend using the iso format without a timezone attached.

Supports:

  • iso
  • sql
  • timestamp_ms a timestamp in millisecond
  • timestamp_s a timestamp in seconds
kontrl.settings({
  datetime: {
    originFormat: "iso"
  }
});