mdtg 1.1.0 → 1.3.0
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/.github/workflows/test.yml +2 -2
- package/biome.json +34 -0
- package/eslint.config.js +17 -17
- package/index.js +228 -228
- package/package.json +26 -21
|
@@ -17,7 +17,7 @@ jobs:
|
|
|
17
17
|
- name: Setup Node.js
|
|
18
18
|
uses: actions/setup-node@v4
|
|
19
19
|
with:
|
|
20
|
-
node-version:
|
|
20
|
+
node-version: 24
|
|
21
21
|
- run: npm install
|
|
22
22
|
- name: Check format
|
|
23
23
|
run: npm run lint
|
|
@@ -27,7 +27,7 @@ jobs:
|
|
|
27
27
|
strategy:
|
|
28
28
|
matrix:
|
|
29
29
|
os: [ubuntu-latest, ubuntu-24.04-arm]
|
|
30
|
-
node-version: [18, 20, 22]
|
|
30
|
+
node-version: [18, 20, 22, 24]
|
|
31
31
|
runs-on: ${{ matrix.os }}
|
|
32
32
|
steps:
|
|
33
33
|
- uses: actions/checkout@v4
|
package/biome.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.3.13/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false
|
|
10
|
+
},
|
|
11
|
+
"formatter": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"indentStyle": "tab"
|
|
14
|
+
},
|
|
15
|
+
"linter": {
|
|
16
|
+
"enabled": true,
|
|
17
|
+
"rules": {
|
|
18
|
+
"recommended": true
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"javascript": {
|
|
22
|
+
"formatter": {
|
|
23
|
+
"quoteStyle": "double"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"assist": {
|
|
27
|
+
"enabled": true,
|
|
28
|
+
"actions": {
|
|
29
|
+
"source": {
|
|
30
|
+
"organizeImports": "on"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/eslint.config.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import pluginJs from "@eslint/js";
|
|
2
2
|
|
|
3
3
|
export default [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
pluginJs.configs.recommended,
|
|
5
|
+
{
|
|
6
|
+
rules: {
|
|
7
|
+
"no-unused-vars": [
|
|
8
|
+
"error",
|
|
9
|
+
{
|
|
10
|
+
varsIgnorePattern: "^_",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
files: ["**/*.test.js"],
|
|
17
|
+
rules: {
|
|
18
|
+
"no-undef": "off",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
21
|
];
|
package/index.js
CHANGED
|
@@ -1,244 +1,244 @@
|
|
|
1
1
|
const normalizeNumber = (number) => String(number).padStart(2, "0");
|
|
2
2
|
|
|
3
3
|
export class MDTG {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
#currentDate = null;
|
|
5
|
+
static months = [
|
|
6
|
+
"jan",
|
|
7
|
+
"feb",
|
|
8
|
+
"mar",
|
|
9
|
+
"apr",
|
|
10
|
+
"may",
|
|
11
|
+
"jun",
|
|
12
|
+
"jul",
|
|
13
|
+
"aug",
|
|
14
|
+
"sep",
|
|
15
|
+
"oct",
|
|
16
|
+
"nov",
|
|
17
|
+
"dec",
|
|
18
|
+
];
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
static offset = {
|
|
21
|
+
Y: 12,
|
|
22
|
+
X: 11,
|
|
23
|
+
W: 10,
|
|
24
|
+
V: 9,
|
|
25
|
+
U: 8,
|
|
26
|
+
T: 7,
|
|
27
|
+
S: 6,
|
|
28
|
+
R: 5,
|
|
29
|
+
Q: 4,
|
|
30
|
+
P: 3,
|
|
31
|
+
O: 2,
|
|
32
|
+
N: 1,
|
|
33
|
+
Z: 0,
|
|
34
|
+
A: -1,
|
|
35
|
+
B: -2,
|
|
36
|
+
C: -3,
|
|
37
|
+
D: -4,
|
|
38
|
+
E: -5,
|
|
39
|
+
F: -6,
|
|
40
|
+
G: -7,
|
|
41
|
+
H: -8,
|
|
42
|
+
I: -9,
|
|
43
|
+
J: -10,
|
|
44
|
+
K: -11,
|
|
45
|
+
L: -12,
|
|
46
|
+
M: -13,
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
constructor(date) {
|
|
50
|
+
const now = new Date();
|
|
51
|
+
this.#currentDate =
|
|
52
|
+
date ??
|
|
53
|
+
new Date(
|
|
54
|
+
Date.UTC(
|
|
55
|
+
now.getUTCFullYear(),
|
|
56
|
+
now.getUTCMonth(),
|
|
57
|
+
now.getUTCDate(),
|
|
58
|
+
now.getUTCHours(),
|
|
59
|
+
now.getUTCMinutes(),
|
|
60
|
+
now.getUTCSeconds(),
|
|
61
|
+
now.getUTCMilliseconds(),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
static isShortFormat(str) {
|
|
67
|
+
return /^[0-9]{6}[A-Z]$/.test(str);
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
static isShortenedFormat(str) {
|
|
71
|
+
return /^[0-9]{6}[A-Z](jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i.test(
|
|
72
|
+
str,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
static isLongFormat(str) {
|
|
77
|
+
return /^[0-9]{8}[A-Z](jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[0-9]{2}$/i.test(
|
|
78
|
+
str,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
82
|
+
#toShortMDT(timezone = "Z") {
|
|
83
|
+
if (!/^[A-Z]$/.test(timezone.toUpperCase())) {
|
|
84
|
+
timezone = "Z";
|
|
85
|
+
}
|
|
86
|
+
const newDate = new Date(
|
|
87
|
+
Date.UTC(
|
|
88
|
+
this.#currentDate.getUTCFullYear(),
|
|
89
|
+
this.#currentDate.getUTCMonth(),
|
|
90
|
+
this.#currentDate.getUTCDate(),
|
|
91
|
+
this.#currentDate.getUTCHours() - MDTG.offset[timezone.toUpperCase()],
|
|
92
|
+
this.#currentDate.getUTCMinutes(),
|
|
93
|
+
),
|
|
94
|
+
);
|
|
95
|
+
const shortMDT = [
|
|
96
|
+
newDate.getUTCDate(),
|
|
97
|
+
newDate.getUTCHours(),
|
|
98
|
+
newDate.getUTCMinutes(),
|
|
99
|
+
]
|
|
100
|
+
.map(normalizeNumber)
|
|
101
|
+
.concat(timezone.toUpperCase())
|
|
102
|
+
.join("");
|
|
103
|
+
if (!MDTG.isShortFormat(shortMDT)) {
|
|
104
|
+
throw new Error("There was an error while building short MDT");
|
|
105
|
+
}
|
|
106
|
+
return shortMDT;
|
|
107
|
+
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
109
|
+
#toLongMDT(timezone = "Z") {
|
|
110
|
+
if (!/^[A-Z]$/.test(timezone.toUpperCase())) {
|
|
111
|
+
timezone = "Z";
|
|
112
|
+
}
|
|
113
|
+
const newDate = new Date(
|
|
114
|
+
Date.UTC(
|
|
115
|
+
this.#currentDate.getUTCFullYear(),
|
|
116
|
+
this.#currentDate.getUTCMonth(),
|
|
117
|
+
this.#currentDate.getUTCDate(),
|
|
118
|
+
this.#currentDate.getUTCHours() - MDTG.offset[timezone.toUpperCase()],
|
|
119
|
+
this.#currentDate.getUTCMinutes(),
|
|
120
|
+
this.#currentDate.getUTCSeconds(),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
const longMDT = [
|
|
124
|
+
newDate.getUTCDate(),
|
|
125
|
+
newDate.getUTCHours(),
|
|
126
|
+
newDate.getUTCMinutes(),
|
|
127
|
+
newDate.getUTCSeconds(),
|
|
128
|
+
]
|
|
129
|
+
.map(normalizeNumber)
|
|
130
|
+
.concat(
|
|
131
|
+
timezone.toUpperCase(),
|
|
132
|
+
MDTG.months[newDate.getUTCMonth()],
|
|
133
|
+
normalizeNumber(newDate.getUTCFullYear() % 2000),
|
|
134
|
+
)
|
|
135
|
+
.join("");
|
|
136
|
+
if (!MDTG.isLongFormat(longMDT)) {
|
|
137
|
+
throw new Error("There was an error while building long MDT");
|
|
138
|
+
}
|
|
139
|
+
return longMDT;
|
|
140
|
+
}
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
142
|
+
#toShortenedMDT(timezone = "Z") {
|
|
143
|
+
if (!/^[A-Z]$/.test(timezone.toUpperCase())) {
|
|
144
|
+
timezone = "Z";
|
|
145
|
+
}
|
|
146
|
+
const newDate = new Date(
|
|
147
|
+
Date.UTC(
|
|
148
|
+
this.#currentDate.getUTCFullYear(),
|
|
149
|
+
this.#currentDate.getUTCMonth(),
|
|
150
|
+
this.#currentDate.getUTCDate(),
|
|
151
|
+
this.#currentDate.getUTCHours() - MDTG.offset[timezone.toUpperCase()],
|
|
152
|
+
this.#currentDate.getUTCMinutes(),
|
|
153
|
+
this.#currentDate.getUTCSeconds(),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
const shortenedMDT = [
|
|
157
|
+
this.#toShortMDT(timezone.toUpperCase()),
|
|
158
|
+
MDTG.months[newDate.getUTCMonth()],
|
|
159
|
+
normalizeNumber(newDate.getUTCFullYear() % 2000),
|
|
160
|
+
].join("");
|
|
161
|
+
if (!MDTG.isShortenedFormat(shortenedMDT)) {
|
|
162
|
+
throw new Error("There was an error while building shortened MDT");
|
|
163
|
+
}
|
|
164
|
+
return shortenedMDT;
|
|
165
|
+
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
167
|
+
toMDT(options) {
|
|
168
|
+
if (options?.form === "short") {
|
|
169
|
+
return this.#toShortMDT(options?.timezone);
|
|
170
|
+
} else if (options?.form === "shortened") {
|
|
171
|
+
return this.#toShortenedMDT(options?.timezone);
|
|
172
|
+
} else {
|
|
173
|
+
return this.#toLongMDT(options?.timezone);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
static parse(str) {
|
|
178
|
+
if (MDTG.isShortFormat(str)) {
|
|
179
|
+
const day = Number.parseInt(str.slice(0, 2), 10);
|
|
180
|
+
const hours = Number.parseInt(str.slice(2, 4), 10);
|
|
181
|
+
const minutes = Number.parseInt(str.slice(4, 6), 10);
|
|
182
|
+
const timezoneOffset = str.slice(-1).toUpperCase();
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
184
|
+
const today = new Date();
|
|
185
|
+
const date = new Date(
|
|
186
|
+
Date.UTC(
|
|
187
|
+
today.getUTCFullYear(),
|
|
188
|
+
today.getUTCMonth(),
|
|
189
|
+
day,
|
|
190
|
+
hours + MDTG.offset[timezoneOffset],
|
|
191
|
+
minutes,
|
|
192
|
+
0,
|
|
193
|
+
0,
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
return date;
|
|
197
|
+
} else if (MDTG.isShortenedFormat(str)) {
|
|
198
|
+
const day = Number.parseInt(str.slice(0, 2), 10);
|
|
199
|
+
const hours = Number.parseInt(str.slice(2, 4), 10);
|
|
200
|
+
const minutes = Number.parseInt(str.slice(4, 6), 10);
|
|
201
|
+
const timezoneOffset = str.slice(6, 7).toUpperCase();
|
|
202
|
+
const month = MDTG.months.indexOf(str.slice(7, 10).toLowerCase());
|
|
203
|
+
const year = 2000 + Number.parseInt(str.slice(10, 12), 10);
|
|
204
|
+
const date = new Date(
|
|
205
|
+
Date.UTC(
|
|
206
|
+
year,
|
|
207
|
+
month,
|
|
208
|
+
day,
|
|
209
|
+
hours + MDTG.offset[timezoneOffset],
|
|
210
|
+
minutes,
|
|
211
|
+
0,
|
|
212
|
+
0,
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
return date;
|
|
216
|
+
} else if (MDTG.isLongFormat(str)) {
|
|
217
|
+
const day = Number.parseInt(str.slice(0, 2), 10);
|
|
218
|
+
const hours = Number.parseInt(str.slice(2, 4), 10);
|
|
219
|
+
const minutes = Number.parseInt(str.slice(4, 6), 10);
|
|
220
|
+
const seconds = Number.parseInt(str.slice(6, 8), 10);
|
|
221
|
+
const timezoneOffset = str.slice(8, 9).toUpperCase();
|
|
222
|
+
const month = MDTG.months.indexOf(str.slice(9, 12).toLowerCase());
|
|
223
|
+
const year = 2000 + Number.parseInt(str.slice(12, 14), 10);
|
|
224
|
+
const date = new Date(
|
|
225
|
+
Date.UTC(
|
|
226
|
+
year,
|
|
227
|
+
month,
|
|
228
|
+
day,
|
|
229
|
+
hours + MDTG.offset[timezoneOffset],
|
|
230
|
+
minutes,
|
|
231
|
+
seconds,
|
|
232
|
+
0,
|
|
233
|
+
),
|
|
234
|
+
);
|
|
235
|
+
return date;
|
|
236
|
+
} else {
|
|
237
|
+
throw Error(`There was an error while parsing the string "${str}"`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
toDate() {
|
|
242
|
+
return this.#currentDate;
|
|
243
|
+
}
|
|
244
244
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
"name": "mdtg",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=18.0.0",
|
|
8
|
+
"npm": ">=8.6.0"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"format": "biome format .",
|
|
12
|
+
"prelint": "npm run format",
|
|
13
|
+
"lint": "biome lint .",
|
|
14
|
+
"test": "vitest run"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"military",
|
|
18
|
+
"date",
|
|
19
|
+
"time"
|
|
20
|
+
],
|
|
21
|
+
"author": "0xflotus",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"description": "This package offers you methods to convert Date Objects to military date time and vice versa",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@biomejs/biome": "2.3.13",
|
|
26
|
+
"vitest": "4.0.18"
|
|
27
|
+
}
|
|
23
28
|
}
|