How is the number of gems required to finish an upgrade calculated?

//ads -- adsterra.com -- native banner
?>
In the game we can pay gems to finish an upgrade early. The number of gems is greater the more time that is remaining on the upgrade, but does anyone know exactly how it is calculated?
For example, to skip a 1 day upgrade costs around 200 gems ( I think) But to skip a 7 day upgrade costs 1000 gems. Or to skip a 14 day upgrade costs around 1800 gems.
Pictures about "How is the number of gems required to finish an upgrade calculated?"



How many gems does it take to finish an upgrade?
It takes much more gems to heal a hero or to request Clan Castle troops than to finish upgrades or troop training: for example, it takes 7 gems to finish an upgrade or troop training with 20 minutes remaining, but it takes 42 gems to request Clan Castle troops again immediately after requesting and 23 gems to heal a ...How many gems does it take to finish a 7 day upgrade?
The lvl 4 Dark Barracks (7 day upgrade) has 4d 20h left (116 hours) and costs 736 gems to finish right now. That's a 6.3 gem-per-hour ratio (736 gems / 116 hours).How many gems does it take to complete a 14 day upgrade?
Or to skip a 14 day upgrade costs around 1800 gems.How many gems does it take to finish Clash of Clans?
According to the Clash of Clans wiki the total cost of upgrading everything is 1,688,882 gems which works out to be $12,068.77.StepN - Upgrading Gems with detailed calculations for profit
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Rosemary Ketchum, Nataliya Vaitkevich, Karolina Grabowska, Karolina Grabowska