Skip to content

Commit

Permalink
[IMP] continue refactoring timeago.js, following the conversation on …
Browse files Browse the repository at this point in the history
…this pull request: #83

- remove bad usage of global variable stringAndNumber
- use a consistent name for the substitute() function which was actully not substituing anything anymore
  • Loading branch information
qn7o committed Jun 25, 2012
1 parent 1bb29c8 commit 6fc5d86
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions jquery.timeago.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@
var days = hours / 24; var days = hours / 24;
var years = days / 365; var years = days / 365;


function substitute(stringOrFunction, number) { function convert(stringOrFunction, number) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction; var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;


// return the proper string and the numeric value that goes in it // return the proper string and the numeric value that goes in it
return stringAndNumber = {'string': string, 'value': ($l.numbers && $l.numbers[number]) || number}; return {'string': string, 'value': ($l.numbers && $l.numbers[number]) || number};
} }


var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || var stringAndNumber = seconds < 45 && convert($l.seconds, Math.round(seconds)) ||
seconds < 90 && substitute($l.minute, 1) || seconds < 90 && convert($l.minute, 1) ||
minutes < 45 && substitute($l.minutes, Math.round(minutes)) || minutes < 45 && convert($l.minutes, Math.round(minutes)) ||
minutes < 90 && substitute($l.hour, 1) || minutes < 90 && convert($l.hour, 1) ||
hours < 24 && substitute($l.hours, Math.round(hours)) || hours < 24 && convert($l.hours, Math.round(hours)) ||
hours < 42 && substitute($l.day, 1) || hours < 42 && convert($l.day, 1) ||
days < 30 && substitute($l.days, Math.round(days)) || days < 30 && convert($l.days, Math.round(days)) ||
days < 45 && substitute($l.month, 1) || days < 45 && convert($l.month, 1) ||
days < 365 && substitute($l.months, Math.round(days / 30)) || days < 365 && convert($l.months, Math.round(days / 30)) ||
years < 1.5 && substitute($l.year, 1) || years < 1.5 && convert($l.year, 1) ||
substitute($l.years, Math.round(years)); convert($l.years, Math.round(years));


var string = stringAndNumber.string; var string = stringAndNumber.string;
var value = stringAndNumber.value; var value = stringAndNumber.value;
Expand Down

0 comments on commit 6fc5d86

Please sign in to comment.