The user sets a start date and end date range in the card of the first image.
The difference in months, days and hours are extracted from the range.
A second card appears replacing the first card with the amounts monthly/daily/hourly rates applied to months, days and hours difference from the date range selected.
Convert the dates to Unix time (milliseconds). Then convert to days.
Divide by days in the month and then calculate the modulus of that (so total days in milliseconds minus months*days in milliseconds) to get you the days remaining in milliseconds.
Convert to hours and do the same with days giving you hours left.