from datetime import datetime


def update_first_notification_object(first_notification_object, assignment_id, notifcation_type, time):
    """
    Gets the FirstAssignmentOfCourse object from the database.
    If it does not exist for the requested course, it will be created.

    :param first_notification_object: FirstAssignmentOfCourse object that needs to be updated.
    :type first_notification_object: FirstAssignmentOfCourse
    :param assignmen_id: ID of the assignment the notification is for.
    :type assignmen_id: int
    :param notifcation_type: Type of planned notification ('early' or 'late').
    :type notifcation_type: str
    :param time: Timestamp of when the notification will need to be send.
    :type time: int
    :return: FirstAssignmentOfCourse object that is updated.
    :rtype: FirstAssignmentOfCourse
    """

    first_notification_object.assignment_id = assignment_id
    first_notification_object.notification_type = notifcation_type
    first_notification_object.time = None if time is None else datetime.fromtimestamp(time)
    first_notification_object.save()

    return first_notification_object