schedule_selector.js 869 Bytes
//@ts-check
/* eslint-disable no-unused-vars */
/*
[
    {
        'course_name': 'name'
        'due_date': '2022-05-15T14:59:59Z'
        'assignment_name': '과제이름'
        'points': 10.0
    }
]
*/

const ADayForMS = 1000 * 60 * 60 * 24

async function is_possible_schedule(date, assignments) {
    const assignments_dates = assignments.map(it => new Date(it.due_date))
    const is_disqualified = assignments_dates.filter(it => {
        const current_timestamp = date.getTime()
        const target_timestamp = it.getTime()

        return current_timestamp > (target_timestamp - ADayForMS)  
    })
    
    if(is_disqualified) {
        const disq = is_disqualified.at(0)
        return `${disq.course_name}: ${disq.assignment_name} [${disq.points} 점]`
    } else {
        return null
    }
}

module.exports.is_possible_schedule = is_possible_schedule