Class EpochDateTransformer

java.lang.Object
com.invirgance.convirgance.transform.date.EpochDateTransformer
All Implemented Interfaces:
IdentityTransformer, Transformer

@Wiring public class EpochDateTransformer extends Object implements IdentityTransformer
Transforms long numbers representing a millisecond timestamp into Date objects.

This transformer transforms Epoch millisecond timestamps into their corresponding Date following the format of Date.getTime() in both Java and JavaScript.

Example usage:

 Iterable<JSONObject> stream = ...;
 
 // Convert specified fields
 EpochDateTransformer transformer = new EpochDateTransformer("created_at", "updated_at");
 
 // Apply the transformation
 stream = transformer.transform(stream);
 
Author:
jbanes
See Also:
  • Constructor Details

    • EpochDateTransformer

      public EpochDateTransformer()
      Prepares a new EpochDateTransformer for transforming epoch values to Dates. Note that setColumns(java.lang.String...) must be called or the transformation will throw an exception when invoked.
    • EpochDateTransformer

      public EpochDateTransformer(String... columns)
      Creates a new EpochDateTransformer for transforming the epoch values of a JSONObject to Dates.
      Parameters:
      columns - field names to include in the conversion
  • Method Details

    • getColumns

      public String[] getColumns()
      Get the list of columns that will be transformed. Null is returned if no column list has been set. In this case, all columns will be checked.
      Returns:
      list of columns to be converted or null if all columns will be checked
    • setColumns

      public void setColumns(String... columns)
      Set the list of columns to transform. Null may be passed if all columns should be checked and transformed if they are of type Date.
      Parameters:
      columns - list of columns to be converted
    • transform

      public JSONObject transform(JSONObject record) throws ConvirganceException
      Description copied from interface: IdentityTransformer
      Transforms the provided record in some way.
      Specified by:
      transform in interface IdentityTransformer
      Parameters:
      record - The JSONObject to transform/modify.
      Returns:
      The modified JSONObject.
      Throws:
      ConvirganceException - If an error occurs while making transformations.