aggregation_modules/custom_functions.py
def convert_time(epoch_time, time_format="%s", delta=1):
    """
    Converts GMT epoch time to the specified time format.
    Also rounds off to the nearest minute, hour, day when valid delta value is passed
    :param epoch_time: epoch time to be converted
    :param time_format: expected output time format
                         example: "%Y-%m-%d %H:%M:%S", "%s", ...
    :param delta: in seconds to be rounded off.
                  example: 300, 1800, 3600...
    :rtype: time
    example:
        >>> epoch_time = "1541399309.143"
        >>> convert_time(epoch_time)
        '1541399309'
        >>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z")
        '2018-11-05 06:28:29 UTC'
        >>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z", delta=300)
        '2018-11-05 06:25:00 UTC'
        >>> convert_time(epoch_time, delta=300)
        '1541399100'
    """
    os.environ["TZ"] = "UTC"
    time.tzset()
    # reset delta if unexpected value
    if delta <= 0:
        delta = 1
    # round off the epoch to specified delta
    epoch_rounded = float(epoch_time) - (float(epoch_time) % delta)
    # return in GMT format
    return time.strftime(time_format, time.gmtime(float(epoch_rounded)))

    Converts GMT epoch time to the specified time format.
    Also rounds off to the nearest minute, hour, day when valid delta value is passed
    :param epoch_time: epoch time to be converted
    :param time_format: expected output time format
                         example: "%Y-%m-%d %H:%M:%S", "%s", ...
    :param delta: in seconds to be rounded off.
                  example: 300, 1800, 3600...
    :rtype: time
    example:
        >>> epoch_time = "1541399309.143"
        >>> convert_time(epoch_time)
        '1541399309'
        >>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z")
        '2018-11-05 06:28:29 UTC'
        >>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z", delta=300)
        '2018-11-05 06:25:00 UTC'
        >>> convert_time(epoch_time, delta=300)
        '1541399100'
    
Converts GMT epoch time to the specified time format.
Also rounds off to the nearest minute, hour, day when valid delta value is passed
Converts GMT epoch time to the specified time format . Also rounds off to the nearest minute hour day when valid delta value is passed
def convert_time(epoch_time, time_format="%s", delta=1):
    os.environ["TZ"] = "UTC"
    time.tzset()
    if delta <= 0:
        delta = 1
    epoch_rounded = float(epoch_time) - (float(epoch_time) % delta)
    return time.strftime(time_format, time.gmtime(float(epoch_rounded)))
def convert_time ( epoch_time , time_format = "%s" , delta = 1 ) : os . environ [ "TZ" ] = "UTC" time . tzset ( ) if delta <= 0 : delta = 1 epoch_rounded = float ( epoch_time ) - ( float ( epoch_time ) % delta ) return time . strftime ( time_format , time . gmtime ( float ( epoch_rounded ) ) )
Converts GMT epoch time to the specified time format.
Converts GMT epoch time to the specified time format .
"""
    Converts GMT epoch time to the specified time format.
    Also rounds off to the nearest minute, hour, day when valid delta value is passed
    :param epoch_time: epoch time to be converted
    :param time_format: expected output time format
                         example: "%Y-%m-%d %H:%M:%S", "%s", ...
    :param delta: in seconds to be rounded off.
                  example: 300, 1800, 3600...
    :rtype: time
    example:
        >>> epoch_time = "1541399309.143"
        >>> convert_time(epoch_time)
        '1541399309'
        >>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z")
        '2018-11-05 06:28:29 UTC'
        >>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z", delta=300)
        '2018-11-05 06:25:00 UTC'
        >>> convert_time(epoch_time, delta=300)
        '1541399100'
    """ # reset delta if unexpected value # round off the epoch to specified delta # return in GMT format
None
time
example:
>>> epoch_time = "1541399309.143"
>>> convert_time(epoch_time)
'1541399309'
>>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z")
'2018-11-05 06:28:29 UTC'
>>> convert_time(epoch_time, time_format="%Y-%m-%d %H:%M:%S %Z", delta=300)
'2018-11-05 06:25:00 UTC'
>>> convert_time(epoch_time, delta=300)
'1541399100'
epoch_time
epoch time to be converted
epoch time to be converted
time_format
expected output time format
example: "%Y-%m-%d %H:%M:%S", "%s".
expected output time format example : " %Y - %m - %d %H : %M : %S " " %s " .
delta
in seconds to be rounded off.
in seconds to be rounded off .