Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
190 lines (145 sloc) 4.12 KB

Utils

The ThreatConnect |trade| TcEx App Framework provides common utils methods to assist in writing Apps.

Format Date Time

The :py:mod:`~tcex.tcex_utils.TcExUtils.format_datetime` method accepts multiple input types and returns an ISO formated datetime string by default. Optionally the timezone of the timestamp can be provided as well as the strftime format.

Accepted Formats:

  1. Human Input (e.g 30 days ago, last friday)
  2. ISO 8601 (e.g. 2017-11-08T16:52:42Z)
  3. "Loose" Date format (e.g. 2017 12 25)
  4. Unix Time/Posix Time/Epoch Time (e.g. 1510686617 or 1510686617.298753)

Note

This module supports using %s to retrieve the datetime in Unix format.

Unix Timestamp Integer

Unix Timestamp String

ISO 8601 Date (Zulu)

ISO 8601 Date (Zulu) in US/Eastern Time

ISO 8601 Date w/ TZ Offset

ISO 8601 Date w/ TZ Offset in US/Eastern Time

Now UTC Unix timestamp

Now Central

Tomorrow at 6 AM

Next Monday at noon

3 Weeks Ago US/Eastern Formatted for ThreatConnect

Date to Datetime

The :py:mod:`~tcex.tcex_utils.TcExUtils.date_to_datetime` method uses the dateutil module to parse the provided data and return a datetime.datetime object.

Human Time to Datetime

The :py:mod:`~tcex.tcex_utils.TcExUtils.human_date_to_datetime` method uses the parsedatetime module to parse the provided data and return a datetime.datetime object.

Examples:

  • August 25th, 2008
  • 25 Aug 2008
  • Aug 25 5pm
  • 5pm August 25
  • next saturday
  • tomorrow
  • next thursday at 4pm
  • at 4pm
  • eod
  • tomorrow eod
  • eod tuesday
  • eoy
  • eom
  • in 5 minutes
  • 5 minutes from now
  • 5 hours before now
  • 2 hours before noon
  • 2 days from tomorrow

Unix Time to Datetime

The :py:mod:`~tcex.tcex_utils.TcExUtils.unix_time_to_datetime` method converts a unix timestamp to a datetime.datetime object.

Examples:

  • 1510686617
  • 1510686617.298753