leftTime.min.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (function(y, g) {
  2. Date.prototype.format = function(a) {
  3. var d = {
  4. "M+": this.getMonth() + 1,
  5. "d+": this.getDate(),
  6. "h+": this.getHours(),
  7. "m+": this.getMinutes(),
  8. "s+": this.getSeconds(),
  9. "q+": Math.floor((this.getMonth() + 3) / 3),
  10. S: this.getMilliseconds()
  11. };
  12. /(y+)/.test(a) && (a = a.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)));
  13. for (var c in d)(new RegExp("(" + c + ")")).test(a) && (a = a.replace(RegExp.$1, 1 == RegExp.$1.length ? d[c] : ("00" + d[c]).substr(("" + d[c]).length)));
  14. return a
  15. };
  16. g.leftTime = function(a, d, c) {
  17. function w(a) {
  18. return - 1 != a.indexOf("-") || -1 != a.indexOf("/") ? !0 : !1
  19. }
  20. function g(a) {
  21. return /^(20|21|22|23|[0-1]\d):[0-5]\d$/.test(y.trim(a)) ? !0 : !1
  22. }
  23. function r(a) {
  24. 10 > a && c && (a = "0" + a);
  25. return a
  26. }
  27. function z() {
  28. if ("string" === typeof a || "number" === typeof a) {
  29. var b = (new Date).getTime(),
  30. c;
  31. "string" === typeof a || 12 <= a.toString().length ? (a = "string" === typeof a && 1 == w(a) ? a.replace(/-/g, "/") : a, c = (new Date(a)).getTime(), b = c - b) : (c = a - A.count, b = 1E3 * c, A.count++);
  32. 0 < b ? (h = Math.floor(b / 1E3 / 60 / 60 / 24), k = Math.floor(b / 1E3 / 60 / 60 % 24), l = Math.floor(b / 1E3 / 60 % 60), m = Math.floor(b / 1E3 % 60), n = !0) : (window.clearInterval(e), m = l = k = h = 0, n = !1)
  33. } else "object" === typeof a && (b = (new Date).getTime() + (0 < t ? -1 * t: Math.abs(t)), c = 0, u < f ? (c = f, v = 1) : u >= f && u < p ? (c = p, v = 2) : u >= p && (v = 3), b = c - b, 0 < b ? (h = Math.floor(b / 1E3 / 60 / 60 / 24), k = Math.floor(b / 1E3 / 60 / 60 % 24), l = Math.floor(b / 1E3 / 60 % 60), m = Math.floor(b / 1E3 % 60), n = !0) : (window.clearInterval(e), m = l = k = h = 0, n = !1));
  34. b = {
  35. d: r(h),
  36. h: r(k),
  37. m: r(l),
  38. s: r(m)
  39. };
  40. b.status = n;
  41. b.step = v;
  42. if (d && "function" === typeof d) return d(b)
  43. }
  44. var e = this.timer;
  45. c || 0 == c || (c = !0);
  46. var A = {
  47. count: 0
  48. },
  49. h = 0,
  50. k = 0,
  51. l = 0,
  52. m = 0,
  53. v = 0,
  54. n = !1;
  55. if ("object" === typeof a) {
  56. a.init || 1 == a.init || (a.init = !1);
  57. var t = 0,
  58. x, q = 0;
  59. if (0 != a.setday || "0" != a.setday) q = 864E5 * parseInt(a.setday);
  60. a.nowdate && null != a.nowdate && void 0 != a.nowdate && "undefined" != a.nowdate ? (t = (new Date).getTime() - parseInt(a.nowdate), x = new Date(a.nowdate)) : (a.nowdate = (new Date).getTime(), x = new Date);
  61. var q = new Date(parseInt(a.nowdate) + q),
  62. f = 0,
  63. p = 0;
  64. 0 == a.startdate || "0" == a.startdate || a.init || ("string" === typeof a.startdate ? w(a.startdate) ? f = (new Date(a.startdate.replace(/-/g, "/"))).getTime() : g(a.startdate) && (f = (new Date(q.format("yyyy/MM/dd") + " " + a.startdate)).getTime()) : "number" === typeof a.startdate && (f = a.startdate));
  65. if (0 != a.enddate || "0" != a.enddate)"string" === typeof a.enddate ? w(a.enddate) ? p = (new Date(a.enddate.replace(/-/g, "/"))).getTime() : g(a.enddate) && (p = (new Date(q.format("yyyy/MM/dd") + " " + a.enddate)).getTime()) : "number" === typeof a.enddate && (f = a.enddate);
  66. var u = x.getTime()
  67. }
  68. z();
  69. e = setInterval(z, 1E3);
  70. if ("undefined" != e || null != e || void 0 != e) return e
  71. };
  72. y.extend(g)
  73. })(jQuery || zepto, {});