mdtg 1.2.0 → 1.3.1

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 CHANGED
@@ -1,244 +1,244 @@
1
1
  const normalizeNumber = (number) => String(number).padStart(2, "0");
2
2
 
3
3
  export class MDTG {
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
- ];
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
- 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
- };
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
- 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
- }
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
- static isShortFormat(str) {
67
- return /^[0-9]{6}[A-Z]$/.test(str);
68
- }
66
+ static isShortFormat(str) {
67
+ return /^[0-9]{6}[A-Z]$/.test(str);
68
+ }
69
69
 
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
- }
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
- 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
- }
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
- #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
- }
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
- #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
- }
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
- #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
- }
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
- 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
- }
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
- static parse(str) {
178
- if (MDTG.isShortFormat(str)) {
179
- const day = Number.parseInt(str.slice(0, 2));
180
- const hours = Number.parseInt(str.slice(2, 4));
181
- const minutes = Number.parseInt(str.slice(4, 6));
182
- const timezoneOffset = str.slice(-1).toUpperCase();
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
- const today = new Date();
185
- const date = new Date(
186
- Date.UTC(
187
- today.getUTCFullYear(),
188
- today.getUTCMonth(),
189
- day,
190
- hours + this.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));
199
- const hours = Number.parseInt(str.slice(2, 4));
200
- const minutes = Number.parseInt(str.slice(4, 6));
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));
204
- const date = new Date(
205
- Date.UTC(
206
- year,
207
- month,
208
- day,
209
- hours + this.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));
218
- const hours = Number.parseInt(str.slice(2, 4));
219
- const minutes = Number.parseInt(str.slice(4, 6));
220
- const seconds = Number.parseInt(str.slice(6, 8));
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));
224
- const date = new Date(
225
- Date.UTC(
226
- year,
227
- month,
228
- day,
229
- hours + this.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
- }
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
- toDate() {
242
- return this.#currentDate;
243
- }
241
+ toDate() {
242
+ return this.#currentDate;
243
+ }
244
244
  }
package/package.json CHANGED
@@ -1,29 +1,28 @@
1
1
  {
2
- "name": "mdtg",
3
- "version": "1.2.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": "prettier --check .",
12
- "prelint": "npm run format",
13
- "lint": "eslint .",
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
- "eslint": "9.39.2",
26
- "prettier": "3.8.1",
27
- "vitest": "4.0.18"
28
- }
2
+ "name": "mdtg",
3
+ "version": "1.3.1",
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
+ }
29
28
  }
@@ -1,39 +0,0 @@
1
- name: Test
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- pull_request:
8
- branches:
9
- - main
10
-
11
- jobs:
12
- lint:
13
- name: Linting
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/checkout@v4
17
- - name: Setup Node.js
18
- uses: actions/setup-node@v4
19
- with:
20
- node-version: 24
21
- - run: npm install
22
- - name: Check format
23
- run: npm run lint
24
- build:
25
- name: Testing
26
- needs: lint
27
- strategy:
28
- matrix:
29
- os: [ubuntu-latest, ubuntu-24.04-arm]
30
- node-version: [18, 20, 22, 24]
31
- runs-on: ${{ matrix.os }}
32
- steps:
33
- - uses: actions/checkout@v4
34
- - name: Setup Node.js ${{ matrix.node-version }}
35
- uses: actions/setup-node@v4
36
- with:
37
- node-version: ${{ matrix.node-version }}
38
- - run: npm install
39
- - run: npm test
package/eslint.config.js DELETED
@@ -1,21 +0,0 @@
1
- import pluginJs from "@eslint/js";
2
-
3
- export default [
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
- ];