Last active
September 28, 2018 20:17
-
-
Save Krinkle/0dc54535513b2d5de32409db36f07d14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* https://tfl.gov.uk/corporate/terms-and-conditions/tfl-call-charges | |
* | |
* > The rate is 0.66p per minute. | |
* > There is also a 40p connection charge. | |
* > Call charges are rounded up to the nearest 10p, with a minimum charge of 60p. | |
* | |
* @param {number} seconds | |
* @return {string} Cost in GBP | |
*/ | |
function cost(seconds) { | |
// Round up per minute | |
var minutes = Math.ceil(seconds / 60); | |
// Calling charge of 0.66p per minute | |
// Connection charge of 40p per call | |
// Minimum total charge of 60p per call | |
var charge = Math.ceil(Math.max(60, 40 + (minutes * 0.66))); | |
// Round up to nearest 10p | |
charge = Math.ceil(charge / 10) * 10; | |
// 123p -> £ 1.23 | |
return '£ ' + (charge / 100).toFixed(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment