L2 Hub
Pontus
formatter
Get Last Month Time

L2 Construct: get_last_month_time

formatters last_month_time

Description

GetLastMonthTime returns the start and end times of the last N months.

This function calculates the start and end times for a specified number of months in the past, based on the current date. It supports custom timezones and various time formats.

Input:

  • Timezone: Optional. The timezone to use for calculations. Defaults to UTC if not provided.
  • LastNMonths: Optional. The number of months to go back. Defaults to 1 if not specified.
  • Format: Required. The desired output format for the time strings.

Output:

  • StartTime: The formatted start time of the period.
  • EndTime: The formatted end time of the period.
  • StartUnixTime: The Unix timestamp for the start time.
  • EndUnixTime: The Unix timestamp for the end time.

The function handles timezone conversions and supports various predefined time formats.

L2 Data

  1. Provider: pontus
  2. Module: formatter
  3. Action: get_last_month_time

Example Step

{
  "name": "insert-your-step-name",
  "type": "l2",
  "l2_data": {
    "provider": "pontus",
    "module": "formatter",
    "action": "get_last_month_time",
    "metadata": {}
  }
}
 

Input

Example

{
  "format": "YYYY-MM-DD HH:mm:ss"
}
 

Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pontus.bpa/pkgs/l2/pontus/formatters/last-month-time-input",
  "$ref": "#/$defs/LastMonthTimeInput",
  "$defs": {
    "LastMonthTimeInput": {
      "properties": {
        "timezone": {
          "type": "string"
        },
        "last_n_months": {
          "type": "integer"
        },
        "format": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["format"]
    }
  }
}
 

Output

Example

{
  "start_time": "20240201",
  "end_time": "20240229",
  "start_unix_time": 1714406400,
  "end_unix_time": 1714492800,
  "error": {
    "is_error": false
  }
}
 

Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pontus.bpa/pkgs/l2/pontus/formatters/last-month-time-output",
  "$ref": "#/$defs/LastMonthTimeOutput",
  "$defs": {
    "HandlerError": {
      "properties": {
        "is_error": {
          "type": "boolean"
        },
        "errors": {
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["is_error"]
    },
    "LastMonthTimeOutput": {
      "properties": {
        "start_time": {
          "type": "string"
        },
        "end_time": {
          "type": "string"
        },
        "start_unix_time": {
          "type": "integer"
        },
        "end_unix_time": {
          "type": "integer"
        },
        "error": {
          "$ref": "#/$defs/HandlerError"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "start_time",
        "end_time",
        "start_unix_time",
        "end_unix_time",
        "error"
      ]
    }
  }
}