utils.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. parseFormat: () => parseFormat
  21. });
  22. module.exports = __toCommonJS(stdin_exports);
  23. var import_utils = require("../utils");
  24. function parseFormat(format, currentTime) {
  25. const { days } = currentTime;
  26. let { hours, minutes, seconds, milliseconds } = currentTime;
  27. if (format.includes("DD")) {
  28. format = format.replace("DD", (0, import_utils.padZero)(days));
  29. } else {
  30. hours += days * 24;
  31. }
  32. if (format.includes("HH")) {
  33. format = format.replace("HH", (0, import_utils.padZero)(hours));
  34. } else {
  35. minutes += hours * 60;
  36. }
  37. if (format.includes("mm")) {
  38. format = format.replace("mm", (0, import_utils.padZero)(minutes));
  39. } else {
  40. seconds += minutes * 60;
  41. }
  42. if (format.includes("ss")) {
  43. format = format.replace("ss", (0, import_utils.padZero)(seconds));
  44. } else {
  45. milliseconds += seconds * 1e3;
  46. }
  47. if (format.includes("S")) {
  48. const ms = (0, import_utils.padZero)(milliseconds, 3);
  49. if (format.includes("SSS")) {
  50. format = format.replace("SSS", ms);
  51. } else if (format.includes("SS")) {
  52. format = format.replace("SS", ms.slice(0, 2));
  53. } else {
  54. format = format.replace("S", ms.charAt(0));
  55. }
  56. }
  57. return format;
  58. }