UNPKG

2.02 kBJavaScriptView Raw
1var __defProp = Object.defineProperty;
2var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3var __getOwnPropNames = Object.getOwnPropertyNames;
4var __hasOwnProp = Object.prototype.hasOwnProperty;
5var __export = (target, all) => {
6 for (var name in all)
7 __defProp(target, name, { get: all[name], enumerable: true });
8};
9var __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};
17var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18var stdin_exports = {};
19__export(stdin_exports, {
20 parseFormat: () => parseFormat
21});
22module.exports = __toCommonJS(stdin_exports);
23var import_utils = require("../utils");
24function 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}