from datetime import datetime


def get_longest_bear(price_history):
    """Get longest bear trend length and dates
    
    Return is format: [longest bear length, start date, end date].
    """
    previous_price = 0
    longest_bear_start = 0
    longest_bear_end = 0
    longest_bear_length = 0
    current_bear_start = 0
    current_bear_length = 0
    for timestamp in price_history:
        if(price_history[timestamp] < previous_price):
            current_bear_length += 1
        else:
            current_bear_start = timestamp
            current_bear_length = 0
        if(current_bear_length > longest_bear_length):
            longest_bear_length = current_bear_length
            longest_bear_start = current_bear_start
            longest_bear_end = timestamp
        previous_price = price_history[timestamp]
    return([
        longest_bear_length, datetime.fromtimestamp(longest_bear_start / 1000),
        datetime.fromtimestamp(longest_bear_end / 1000)
        ])