Advertisement
Snuggledash

Minute count/timestamp conversation

May 6th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var helpers = {
  2.     mc: function(ts) {
  3.         var s = 1;
  4.         if (["+","-"].indexOf(ts.charAt(0)) != -1) {
  5.             if (ts.charAt(0) == "-") s = -1;
  6.             ts = ts.substring(1);
  7.         }
  8.         var h = parseInt(ts.substring(0, 2));
  9.         var m = parseInt(ts.substring(3, 5));
  10.         return (h >= 0 && m >= 0 && m < 60) ? s * (60 * h + m) : NaN;
  11.     },
  12.     ts: function(M) {
  13.         var d = function(i) { return (i < 10 ? "0" : "") + i };
  14.         M = parseInt(M);
  15.         if (!isNaN(M)) {
  16.             var mi = M < 0;
  17.             M = Math.abs(M);
  18.             var m = parseInt(M / 60);
  19.             var s = M % 60;
  20.             return (mi ? "-" : "") + d(m) + ":" + d(s);
  21.         } else return undefined;
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement