Skip to content

Instantly share code, notes, and snippets.

@Krinkle
Last active September 28, 2018 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krinkle/0dc54535513b2d5de32409db36f07d14 to your computer and use it in GitHub Desktop.
Save Krinkle/0dc54535513b2d5de32409db36f07d14 to your computer and use it in GitHub Desktop.
/**
* 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