Share

TimeUtils

The TimeUtils class in Transformations is a utility class that provides a set of methods for working with time data. It is typically used for tasks such as formatting time values, converting these to different formats, and performing calculations with them. The TimeUtils class is typically used in conjunction with data Transformation tasks.

If you want Hevo to load the Event properties converted by your Transformation script to the Destination, you need to specifically add them to the transformed Event.

The following table is provided for each method, and specifies the type of parameter(s) it takes as input and the data type of the object that the method returns.

Definition: Contains the method definition. The definition consists of:
- The method name.
- The arguments that the method takes along with their data types.
- The data type of the return value.

<Method name>(<arg 1>: <data type1>, <arg2>: <data type2>,…) → <Return value data type>.

Example: getTimeDifference(timeOne: datetime.datetime, timeTwo: datetime.datetime, inputUnit: str, outputUnit: str) → int:str
Description: Describes what the method does.
Parameters: The variables that the method accepts as arguments. For example, the fromEpochToDate(int: epoch) method takes the parameter, epoch of type, integer.
Returns: The data type of the variable(s) created or acted upon by the method.

List of Methods in the TimeUtils Class

Hevo provides the following Transformation methods in the TimeUtils class. You can use them in your Transformation script to transform the properties, and test your script on sample Events before deploying it:

Definition Description
TimeUtils.fromEpochToDate(epoch) Convert an epoch to a date
TimeUtils.fromEpochToDatetime(epoch) Convert an epoch to a datetime object
TimeUtils.fromEpochToTime(epoch) Convert an epoch to a time object
TimeUtils.changeDateFormat(dateString, formatOfDate, requiredFormat) Convert a date string from one format to another
TimeUtils.fromEpochToFormattedDate(epoch, requiredFormat) Convert an epoch to a formatted date string
TimeUtils.fromDateToFormattedDate( dateObject, requiredFormat ) Convert a date object to a formatted date string
TimeUtils.fromDatetimeToFormattedDate( dateObject, requiredFormat ) Convert a datetime object to a formatted date string
TimeUtils.parseDateStringToDate( dateString, formatOfDate ) Parse a date string into a date object
TimeUtils.parseDateStringToDatetime( dateString, formatOfDate ) Parse a date string into a datetime object
TimeUtils.parseDateStringToTime( dateString, formatOfDate ) Parse a time string into a time object
TimeUtils.getTimeDifference(timeOne, timeTwo, inputUnit, outputUnit) Get time difference between two time values


Last updated on Aug 27, 2024

Tell us what went wrong

Skip to the section