mdtg 1.0.0 → 1.2.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 +39 -0
- package/index.js +58 -20
- package/package.json +10 -4
|
@@ -0,0 +1,39 @@
|
|
|
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/index.js
CHANGED
|
@@ -79,14 +79,26 @@ export class MDTG {
|
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
#toShortMDT() {
|
|
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
|
+
);
|
|
83
95
|
const shortMDT = [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
newDate.getUTCDate(),
|
|
97
|
+
newDate.getUTCHours(),
|
|
98
|
+
newDate.getUTCMinutes(),
|
|
87
99
|
]
|
|
88
100
|
.map(normalizeNumber)
|
|
89
|
-
.concat(
|
|
101
|
+
.concat(timezone.toUpperCase())
|
|
90
102
|
.join("");
|
|
91
103
|
if (!MDTG.isShortFormat(shortMDT)) {
|
|
92
104
|
throw new Error("There was an error while building short MDT");
|
|
@@ -94,18 +106,31 @@ export class MDTG {
|
|
|
94
106
|
return shortMDT;
|
|
95
107
|
}
|
|
96
108
|
|
|
97
|
-
#toLongMDT() {
|
|
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
|
+
);
|
|
98
123
|
const longMDT = [
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
newDate.getUTCDate(),
|
|
125
|
+
newDate.getUTCHours(),
|
|
126
|
+
newDate.getUTCMinutes(),
|
|
127
|
+
newDate.getUTCSeconds(),
|
|
103
128
|
]
|
|
104
129
|
.map(normalizeNumber)
|
|
105
130
|
.concat(
|
|
106
|
-
|
|
107
|
-
MDTG.months[
|
|
108
|
-
normalizeNumber(
|
|
131
|
+
timezone.toUpperCase(),
|
|
132
|
+
MDTG.months[newDate.getUTCMonth()],
|
|
133
|
+
normalizeNumber(newDate.getUTCFullYear() % 2000),
|
|
109
134
|
)
|
|
110
135
|
.join("");
|
|
111
136
|
if (!MDTG.isLongFormat(longMDT)) {
|
|
@@ -114,11 +139,24 @@ export class MDTG {
|
|
|
114
139
|
return longMDT;
|
|
115
140
|
}
|
|
116
141
|
|
|
117
|
-
#toShortenedMDT() {
|
|
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
|
+
);
|
|
118
156
|
const shortenedMDT = [
|
|
119
|
-
this.#toShortMDT(),
|
|
120
|
-
MDTG.months[
|
|
121
|
-
normalizeNumber(
|
|
157
|
+
this.#toShortMDT(timezone.toUpperCase()),
|
|
158
|
+
MDTG.months[newDate.getUTCMonth()],
|
|
159
|
+
normalizeNumber(newDate.getUTCFullYear() % 2000),
|
|
122
160
|
].join("");
|
|
123
161
|
if (!MDTG.isShortenedFormat(shortenedMDT)) {
|
|
124
162
|
throw new Error("There was an error while building shortened MDT");
|
|
@@ -128,11 +166,11 @@ export class MDTG {
|
|
|
128
166
|
|
|
129
167
|
toMDT(options) {
|
|
130
168
|
if (options?.form === "short") {
|
|
131
|
-
return this.#toShortMDT();
|
|
169
|
+
return this.#toShortMDT(options?.timezone);
|
|
132
170
|
} else if (options?.form === "shortened") {
|
|
133
|
-
return this.#toShortenedMDT();
|
|
171
|
+
return this.#toShortenedMDT(options?.timezone);
|
|
134
172
|
} else {
|
|
135
|
-
return this.#toLongMDT();
|
|
173
|
+
return this.#toLongMDT(options?.timezone);
|
|
136
174
|
}
|
|
137
175
|
}
|
|
138
176
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdtg",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=18.0.0",
|
|
8
|
+
"npm": ">=8.6.0"
|
|
9
|
+
},
|
|
6
10
|
"scripts": {
|
|
7
11
|
"format": "prettier --check .",
|
|
12
|
+
"prelint": "npm run format",
|
|
8
13
|
"lint": "eslint .",
|
|
9
|
-
"test": "
|
|
14
|
+
"test": "vitest run"
|
|
10
15
|
},
|
|
11
16
|
"keywords": [
|
|
12
17
|
"military",
|
|
@@ -17,7 +22,8 @@
|
|
|
17
22
|
"license": "MIT",
|
|
18
23
|
"description": "This package offers you methods to convert Date Objects to military date time and vice versa",
|
|
19
24
|
"devDependencies": {
|
|
20
|
-
"eslint": "
|
|
21
|
-
"prettier": "3.
|
|
25
|
+
"eslint": "9.39.2",
|
|
26
|
+
"prettier": "3.8.1",
|
|
27
|
+
"vitest": "4.0.18"
|
|
22
28
|
}
|
|
23
29
|
}
|