index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/k8w-super-date/index.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
  12. ///<reference path="index.d.ts"/>
  13. function prependZero(matched, num) {
  14. return matched.length > 1 && num < 10 ? "0" + num : "" + num;
  15. }
  16. Date.prototype.format = function (pattern) {
  17. var _this = this;
  18. if (pattern === void 0) { pattern = 'YYYY-MM-DD hh:mm:ss'; }
  19. return pattern.replace(/y{2,}|Y{2,}/, function (v) { return (_this.getFullYear() + "").substr(4 - v.length); })
  20. .replace(/M{1,2}/, function (v) { return prependZero(v, _this.getMonth() + 1); })
  21. .replace(/D{1,2}|d{1,2}/, function (v) { return prependZero(v, _this.getDate()); })
  22. .replace(/Q|q/, function (v) { return prependZero(v, Math.ceil((_this.getMonth() + 1) / 3)); })
  23. .replace(/h{1,2}|H{1,2}/, function (v) { return prependZero(v, _this.getHours()); })
  24. .replace(/m{1,2}/, function (v) { return prependZero(v, _this.getMinutes()); })
  25. .replace(/s{1,2}/, function (v) { return prependZero(v, _this.getSeconds()); })
  26. .replace(/SSS|S/, function (v) {
  27. var ms = '' + _this.getMilliseconds();
  28. return v.length === 1 ? ms : "" + (ms.length === 1 ? '00' : ms.length === 2 ? '0' : '') + ms;
  29. });
  30. };
  31. Date.today = function () {
  32. var now = new Date();
  33. return new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
  34. };
  35. }
  36. if (nodeEnv) {
  37. __define(__module.exports, __require, __module);
  38. }
  39. else {
  40. __quick_compile_project__.registerModuleFunc(__filename, function () {
  41. __define(__module.exports, __require, __module);
  42. });
  43. }
  44. })();