Articles in this section

Time API Guide

We have created new APIs that you can use to create dashboard API Actions. These APIs simplify working across different time zones and help you prepare for upcoming or past events. All Forethought customers can access these APIs. 

Authentication

To access our APIs, reach out to your Customer Success Manager to get the API key. This key must be included in the request header as X-API-KEY. Make sure the key matches the one linked to your Solve widget; otherwise, you’ll receive a 401 Unauthorized error.

API Endpoints

1. Get Current Time

Endpoint

GET https://api.forethought.ai/time/current

Description

This endpoint provides the current time object for any time zone you specify, no need to guess or manually calculate time differences. This endpoint keeps you updated with real-time data across regions.

Request Parameters

Name Type Required Description
timezone string true A valid timezone string, such as "America/Los_Angeles".

Example request

GET /time/current?timezone=America/New_York
X-API-KEY: your_api_key_here

Example response

{
  "timezone": "Europe/Amsterdam",
  "year": 2021,
  "month": 11,
  "day": 26,
  "hour": 2,
  "minutes": 45,
  "seconds": 0,
  "milli_seconds": 0,
  "date_time": "2021-11-26T02:45:00+01:00",
  "date": "11/26/2021",
  "time": "02:45:00",
  "day_of_week": "Friday",
  "formatted_date_time": "2021-11-26 02:45:00"
}

2. Time Calculation (Increment or Decrement)

Endpoint

POST https://api.forethought.ai/time/calculation

Description

This endpoint allows you to adjust the time forward or backward by a specified amount, whether that’s in hours, minutes, or days. Simply indicate how much you want to change the time and in which direction, and it will return a new time object based on your input.

Request Parameters

Name Type Required Description
timezone string true A valid IANA timezone string, such as "America/Los_Angeles".
time_span string true The time span in the format "dd:hh:mm:ss" representing days, hours, minutes, and seconds to adjust the custom date-time.
custom_date_time string true The custom date-time in the format "YYYY-MM-DD HH:MM:SS" on which the calculation will be performed.
operation string true Operation type (increment or decrement) indicating whether to add or subtract the specified time span.

Example request

POST /time/calculation
X-API-KEY: your_api_key_here

{
  "timezone": "Europe/Amsterdam",
  "custom_date_time": "2021-11-27 05:45:00",
  "time_span": "01:03:00:00",
  "operation":"decrement"
}

Example response

{
    "original_date_time": "2021-11-27T05:45:00+01:00",
    "time_span": "01:03:00:00",
    "result": {
        "timezone": "Europe/Amsterdam",
        "year": 2021,
        "month": 11,
        "day": 26,
        "hour": 2,
        "minutes": 45,
        "seconds": 0,
        "milli_seconds": 0,
        "date_time": "2021-11-26T02:45:00+01:00",
        "date": "11/26/2021",
        "time": "02:45:00",
        "day_of_week": "Friday",
        "formatted_date_time": "2021-11-26 02:45:00"
    }
}
Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Article is closed for comments.

Support

  • Need help?

    Click here to submit a support request. We are here to assist you.

  • Business hours

    Monday to Friday 8am - 5pm PST excluding US holidays

  • Contact us

    support@forethought.ai