mdtg 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +28 -17
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const normalizeNumber = (number) => String(number).padStart(2, "0");
|
|
2
|
+
|
|
1
3
|
export class MDTG {
|
|
2
4
|
#currentDate = null;
|
|
3
5
|
static months = [
|
|
@@ -36,11 +38,14 @@ export class MDTG {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
#toShortMDT() {
|
|
39
|
-
const shortMDT =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const shortMDT = [
|
|
42
|
+
this.#currentDate.getDate(),
|
|
43
|
+
this.#currentDate.getHours(),
|
|
44
|
+
this.#currentDate.getMinutes(),
|
|
45
|
+
]
|
|
46
|
+
.map(normalizeNumber)
|
|
47
|
+
.concat("Z")
|
|
48
|
+
.join("");
|
|
44
49
|
if (!MDTG.isShortFormat(shortMDT)) {
|
|
45
50
|
throw new Error("There was an error while building short MDT");
|
|
46
51
|
}
|
|
@@ -48,14 +53,19 @@ export class MDTG {
|
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
#toLongMDT() {
|
|
51
|
-
const longMDT =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const longMDT = [
|
|
57
|
+
this.#currentDate.getDate(),
|
|
58
|
+
this.#currentDate.getHours(),
|
|
59
|
+
this.#currentDate.getMinutes(),
|
|
60
|
+
this.#currentDate.getSeconds(),
|
|
61
|
+
]
|
|
62
|
+
.map(normalizeNumber)
|
|
63
|
+
.concat(
|
|
64
|
+
"Z",
|
|
65
|
+
MDTG.months[this.#currentDate.getMonth()],
|
|
66
|
+
normalizeNumber(this.#currentDate.getFullYear() % 2000),
|
|
67
|
+
)
|
|
68
|
+
.join("");
|
|
59
69
|
if (!MDTG.isLongFormat(longMDT)) {
|
|
60
70
|
throw new Error("There was an error while building long MDT");
|
|
61
71
|
}
|
|
@@ -63,10 +73,11 @@ export class MDTG {
|
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
#toShortenedMDT() {
|
|
66
|
-
const shortenedMDT =
|
|
67
|
-
this.#toShortMDT()
|
|
68
|
-
MDTG.months[this.#currentDate.getMonth()]
|
|
69
|
-
|
|
76
|
+
const shortenedMDT = [
|
|
77
|
+
this.#toShortMDT(),
|
|
78
|
+
MDTG.months[this.#currentDate.getMonth()],
|
|
79
|
+
normalizeNumber(this.#currentDate.getFullYear() % 2000),
|
|
80
|
+
].join("");
|
|
70
81
|
if (!MDTG.isShortenedFormat(shortenedMDT)) {
|
|
71
82
|
throw new Error("There was an error while building shortened MDT");
|
|
72
83
|
}
|