from datetime import datetime

from ._OrderCondition import OrderCondition
from production.model import ProductionOrder


class DisplayTimeCondition(OrderCondition):
    def __init__(self, max_display_time):
        self.max_display_time = int(max_display_time)

    def evaluate(self, order):
        # type: (ProductionOrder) -> bool
        if order.display_time in [None, "", " "]:
            return True

        display_time = datetime.strptime(order.display_time[0:19], "%Y-%m-%dT%H:%M:%S")
        current_time = datetime.now()
        return (current_time - display_time).total_seconds() < self.max_display_time
