Dual datepicker jQuery selection

I am building a date picker from scratch as a learning exercise. My date picker has two months side by side, and my question is, what does the jQuery look like for picking a start date and end date, allowing for the user to change their mind and have both dates on the same month, or on opposite months?

My HTML

<div class="calendar left">
    <div class="calendar-days">
        <div class="calendar-day" day="1">1</div>
        <div class="calendar-day" day="2">2</div>   
        <div class="calendar-day" day="3">3</div>
        <div class="calendar-day" day="4">4</div>
        <div class="calendar-day" day="5">5</div>
        ...
        ...
    </div>
</div>
<div class="calendar right">
    <div class="calendar-days">
        <div class="calendar-day" day="1">1</div>
        <div class="calendar-day" day="2">2</div>   
        <div class="calendar-day" day="3">3</div>
        <div class="calendar-day" day="4">4</div>
        <div class="calendar-day" day="5">5</div>
        ...
        ...
    </div>
</div>

Say the left month is August and the right month is September… they can choose start date August 5th and end date August 17th, or start date August 5th and end date September 22nd, or start date September 8th and end date September 12th, etc… there’s three scenarios.

Selecting the start date is obvious with a click event, and adding a selected class to that day. But how do I only allow two days to be selected at any given time across both calendars?