@alexstukovnikov/oz-time 1.0.2 → 1.0.3
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/package.json +2 -2
- package/src/modules/interval.js +7 -14
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexstukovnikov/oz-time",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Lightweight JavaScript date-time library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/AlexStukovnikov/oz-time.git"
|
|
7
|
+
"url": "git+https://github.com/AlexStukovnikov/oz-time.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "./src/index.js",
|
package/src/modules/interval.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OzTime } from '../core/core.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Duration } from './duration.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Модуль интервалов времени.
|
|
@@ -144,11 +144,9 @@ export class Interval {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* Возвращает длительность
|
|
147
|
+
* Возвращает длительность интервала.
|
|
148
148
|
*
|
|
149
|
-
* @
|
|
150
|
-
* @throws {Error} Выбрасывается, если unit не является фиксированной единицей времени.
|
|
151
|
-
* @returns {number} Длительность интервала в указанной единице.
|
|
149
|
+
* @returns {Duration} Длительность интервала в виде экземпляра {@link Duration}.
|
|
152
150
|
* @example
|
|
153
151
|
* import { Interval, fromISO } from '@alexstukovnikov/oz-time';
|
|
154
152
|
*
|
|
@@ -156,17 +154,12 @@ export class Interval {
|
|
|
156
154
|
* fromISO('2024-05-25T10:00:00Z'),
|
|
157
155
|
* fromISO('2024-05-25T12:00:00Z')
|
|
158
156
|
* );
|
|
159
|
-
*
|
|
157
|
+
*
|
|
158
|
+
* console.log(range.duration().asHours()); // ожидаемый результат: 2
|
|
160
159
|
*/
|
|
161
|
-
duration(
|
|
162
|
-
const normalizedUnit = normalizeUnit(unit);
|
|
163
|
-
|
|
164
|
-
if (!isFixedUnit(normalizedUnit)) {
|
|
165
|
-
throw new Error(`Interval.duration supports only fixed units: ${unit}`);
|
|
166
|
-
}
|
|
167
|
-
|
|
160
|
+
duration() {
|
|
168
161
|
const diffMs = this._end.getTimestamp() - this._start.getTimestamp();
|
|
169
|
-
return
|
|
162
|
+
return new Duration(diffMs);
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
165
|
|