@leancodepl/api-date-dayjs 8.3.6 → 8.5.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/package.json +41 -5
- package/index.cjs.d.ts +0 -1
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -108
- package/index.cjs.mjs +0 -2
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -92
- package/src/index.d.ts +0 -10
- package/src/lib/date/fromApiDate.d.ts +0 -4
- package/src/lib/date/toApiDate.d.ts +0 -4
- package/src/lib/dateTimeOffset/fromApiDateTimeOffset.d.ts +0 -7
- package/src/lib/dateTimeOffset/toApiDateTimeOffset.d.ts +0 -7
- package/src/lib/time/fromApiTime.d.ts +0 -7
- package/src/lib/time/toApiTime.d.ts +0 -7
- package/src/lib/timeSpan/fromApiTimeSpan.d.ts +0 -7
- package/src/lib/timeSpan/toApiTimeSpan.d.ts +0 -7
- package/src/lib/utils/dropLocalOffset.d.ts +0 -5
package/package.json
CHANGED
|
@@ -1,25 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/api-date-dayjs",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@leancodepl/api-date": "8.
|
|
7
|
-
"@leancodepl/api-date-utils": "8.
|
|
6
|
+
"@leancodepl/api-date": "8.5.0",
|
|
7
|
+
"@leancodepl/api-date-utils": "8.5.0",
|
|
8
8
|
"dayjs": ">=1.9.0"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"timezone-mock": "1.3.6"
|
|
12
12
|
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org/"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.0.0"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/leancodepl/js_corelibrary.git",
|
|
23
|
+
"directory": "packages/cqrs-clients/custom-types/date/api-date-dayjs"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/leancodepl/js_corelibrary",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/leancodepl/js_corelibrary/issues"
|
|
28
|
+
},
|
|
29
|
+
"description": "Day.js integration for API date type conversion",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"date",
|
|
32
|
+
"dayjs",
|
|
33
|
+
"api",
|
|
34
|
+
"conversion",
|
|
35
|
+
"typescript",
|
|
36
|
+
"javascript",
|
|
37
|
+
"leancode"
|
|
38
|
+
],
|
|
39
|
+
"author": {
|
|
40
|
+
"name": "LeanCode",
|
|
41
|
+
"url": "https://leancode.co"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"README.md",
|
|
46
|
+
"CHANGELOG.md"
|
|
47
|
+
],
|
|
48
|
+
"sideEffects": false,
|
|
13
49
|
"exports": {
|
|
14
50
|
"./package.json": "./package.json",
|
|
15
51
|
".": {
|
|
16
52
|
"module": "./index.esm.js",
|
|
17
|
-
"types": "./index.
|
|
53
|
+
"types": "./index.d.ts",
|
|
18
54
|
"import": "./index.cjs.mjs",
|
|
19
55
|
"default": "./index.cjs.js"
|
|
20
56
|
}
|
|
21
57
|
},
|
|
22
58
|
"module": "./index.esm.js",
|
|
23
59
|
"main": "./index.cjs.js",
|
|
24
|
-
"types": "./index.
|
|
60
|
+
"types": "./index.d.ts"
|
|
25
61
|
}
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.cjs.default.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
exports._default = require('./index.cjs.js').default;
|
package/index.cjs.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var apiDate = require('@leancodepl/api-date');
|
|
4
|
-
var dayjs = require('dayjs');
|
|
5
|
-
var customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
6
|
-
var utc = require('dayjs/plugin/utc');
|
|
7
|
-
var duration = require('dayjs/plugin/duration');
|
|
8
|
-
var apiDateUtils = require('@leancodepl/api-date-utils');
|
|
9
|
-
|
|
10
|
-
dayjs.extend(customParseFormat);
|
|
11
|
-
function fromApiTime(time) {
|
|
12
|
-
if (!time) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
return dayjs(time, "HH:mm:ss.SSS");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function toApiTime(time) {
|
|
19
|
-
if (!time) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
return time.format("HH:mm:ss.SSS");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function fromApiDate(date) {
|
|
26
|
-
if (!date) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
return dayjs(date);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
dayjs.extend(utc);
|
|
33
|
-
/**
|
|
34
|
-
* This function keeps local time (excluding timezone/offset) but sets its offset to UTC
|
|
35
|
-
*/ function dropLocalOffset(time) {
|
|
36
|
-
return time.clone().utc(true);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function toApiDate(date) {
|
|
40
|
-
if (!date) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
return dropLocalOffset(date).startOf("day").format("YYYY-MM-DD");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
dayjs.extend(customParseFormat);
|
|
47
|
-
function fromApiDateTimeOffset(datetime) {
|
|
48
|
-
if (!datetime) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
return dayjs(datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function toApiDateTimeOffset(time) {
|
|
55
|
-
if (!time) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
return time.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
dayjs.extend(duration);
|
|
62
|
-
function fromApiTimeSpan(timeSpan) {
|
|
63
|
-
if (!timeSpan) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
const parsedDuration = apiDateUtils.parseApiTimeSpan(timeSpan);
|
|
67
|
-
const isNegative = parsedDuration.sign === "-";
|
|
68
|
-
const dayjsDuration = dayjs.duration(parsedDuration.values);
|
|
69
|
-
if (isNegative) {
|
|
70
|
-
return dayjs.duration(-dayjsDuration.asMilliseconds());
|
|
71
|
-
}
|
|
72
|
-
return dayjsDuration;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
dayjs.extend(duration);
|
|
76
|
-
function toApiTimeSpan(duration) {
|
|
77
|
-
if (!duration) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
const isNegative = duration.asMilliseconds() < 0;
|
|
81
|
-
const absDuration = dayjs.duration(Math.abs(duration.asMilliseconds()));
|
|
82
|
-
const days = Math.floor(absDuration.asDays());
|
|
83
|
-
let stringTimeSpan = "";
|
|
84
|
-
if (isNegative) {
|
|
85
|
-
stringTimeSpan += "-";
|
|
86
|
-
}
|
|
87
|
-
if (days > 0) {
|
|
88
|
-
stringTimeSpan += `${days}.`;
|
|
89
|
-
}
|
|
90
|
-
stringTimeSpan += absDuration.format("HH:mm:ss.SSS");
|
|
91
|
-
return stringTimeSpan;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
exports.dropLocalOffset = dropLocalOffset;
|
|
95
|
-
exports.fromApiDate = fromApiDate;
|
|
96
|
-
exports.fromApiDateTimeOffset = fromApiDateTimeOffset;
|
|
97
|
-
exports.fromApiTime = fromApiTime;
|
|
98
|
-
exports.fromApiTimeSpan = fromApiTimeSpan;
|
|
99
|
-
exports.toApiDate = toApiDate;
|
|
100
|
-
exports.toApiDateTimeOffset = toApiDateTimeOffset;
|
|
101
|
-
exports.toApiTime = toApiTime;
|
|
102
|
-
exports.toApiTimeSpan = toApiTimeSpan;
|
|
103
|
-
Object.keys(apiDate).forEach(function (k) {
|
|
104
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
105
|
-
enumerable: true,
|
|
106
|
-
get: function () { return apiDate[k]; }
|
|
107
|
-
});
|
|
108
|
-
});
|
package/index.cjs.mjs
DELETED
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.esm.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
export * from '@leancodepl/api-date';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
|
-
import utc from 'dayjs/plugin/utc';
|
|
5
|
-
import duration from 'dayjs/plugin/duration';
|
|
6
|
-
import { parseApiTimeSpan } from '@leancodepl/api-date-utils';
|
|
7
|
-
|
|
8
|
-
dayjs.extend(customParseFormat);
|
|
9
|
-
function fromApiTime(time) {
|
|
10
|
-
if (!time) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
return dayjs(time, "HH:mm:ss.SSS");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function toApiTime(time) {
|
|
17
|
-
if (!time) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
return time.format("HH:mm:ss.SSS");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function fromApiDate(date) {
|
|
24
|
-
if (!date) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
return dayjs(date);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
dayjs.extend(utc);
|
|
31
|
-
/**
|
|
32
|
-
* This function keeps local time (excluding timezone/offset) but sets its offset to UTC
|
|
33
|
-
*/ function dropLocalOffset(time) {
|
|
34
|
-
return time.clone().utc(true);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function toApiDate(date) {
|
|
38
|
-
if (!date) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
return dropLocalOffset(date).startOf("day").format("YYYY-MM-DD");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
dayjs.extend(customParseFormat);
|
|
45
|
-
function fromApiDateTimeOffset(datetime) {
|
|
46
|
-
if (!datetime) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
return dayjs(datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function toApiDateTimeOffset(time) {
|
|
53
|
-
if (!time) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return time.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
dayjs.extend(duration);
|
|
60
|
-
function fromApiTimeSpan(timeSpan) {
|
|
61
|
-
if (!timeSpan) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
const parsedDuration = parseApiTimeSpan(timeSpan);
|
|
65
|
-
const isNegative = parsedDuration.sign === "-";
|
|
66
|
-
const dayjsDuration = dayjs.duration(parsedDuration.values);
|
|
67
|
-
if (isNegative) {
|
|
68
|
-
return dayjs.duration(-dayjsDuration.asMilliseconds());
|
|
69
|
-
}
|
|
70
|
-
return dayjsDuration;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
dayjs.extend(duration);
|
|
74
|
-
function toApiTimeSpan(duration) {
|
|
75
|
-
if (!duration) {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
const isNegative = duration.asMilliseconds() < 0;
|
|
79
|
-
const absDuration = dayjs.duration(Math.abs(duration.asMilliseconds()));
|
|
80
|
-
const days = Math.floor(absDuration.asDays());
|
|
81
|
-
let stringTimeSpan = "";
|
|
82
|
-
if (isNegative) {
|
|
83
|
-
stringTimeSpan += "-";
|
|
84
|
-
}
|
|
85
|
-
if (days > 0) {
|
|
86
|
-
stringTimeSpan += `${days}.`;
|
|
87
|
-
}
|
|
88
|
-
stringTimeSpan += absDuration.format("HH:mm:ss.SSS");
|
|
89
|
-
return stringTimeSpan;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { dropLocalOffset, fromApiDate, fromApiDateTimeOffset, fromApiTime, fromApiTimeSpan, toApiDate, toApiDateTimeOffset, toApiTime, toApiTimeSpan };
|
package/src/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "@leancodepl/api-date";
|
|
2
|
-
export * from "./lib/time/fromApiTime";
|
|
3
|
-
export * from "./lib/time/toApiTime";
|
|
4
|
-
export * from "./lib/date/fromApiDate";
|
|
5
|
-
export * from "./lib/date/toApiDate";
|
|
6
|
-
export * from "./lib/dateTimeOffset/fromApiDateTimeOffset";
|
|
7
|
-
export * from "./lib/dateTimeOffset/toApiDateTimeOffset";
|
|
8
|
-
export * from "./lib/timeSpan/fromApiTimeSpan";
|
|
9
|
-
export * from "./lib/timeSpan/toApiTimeSpan";
|
|
10
|
-
export * from "./lib/utils/dropLocalOffset";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import type { ApiDateTimeOffset } from "@leancodepl/api-date";
|
|
3
|
-
/**
|
|
4
|
-
*This function handles at most milliseconds precision, smaller units are lost in conversion process
|
|
5
|
-
*/
|
|
6
|
-
export declare function fromApiDateTimeOffset(datetime: ApiDateTimeOffset): dayjs.Dayjs;
|
|
7
|
-
export declare function fromApiDateTimeOffset(datetime: ApiDateTimeOffset | undefined): dayjs.Dayjs | undefined;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import type { ApiDateTimeOffset } from "@leancodepl/api-date";
|
|
3
|
-
/**
|
|
4
|
-
*This function handles at most milliseconds precision, smaller units are lost in conversion process
|
|
5
|
-
*/
|
|
6
|
-
export declare function toApiDateTimeOffset(time: dayjs.Dayjs): ApiDateTimeOffset;
|
|
7
|
-
export declare function toApiDateTimeOffset(time: dayjs.Dayjs | undefined): ApiDateTimeOffset | undefined;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import type { ApiTimeOnly } from "@leancodepl/api-date";
|
|
3
|
-
/**
|
|
4
|
-
*This function handles at most milliseconds precision, smaller units are lost in conversion process
|
|
5
|
-
*/
|
|
6
|
-
export declare function fromApiTime(time: ApiTimeOnly): dayjs.Dayjs;
|
|
7
|
-
export declare function fromApiTime(time: ApiTimeOnly | undefined): dayjs.Dayjs | undefined;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import type { ApiTimeOnly } from "@leancodepl/api-date";
|
|
3
|
-
/**
|
|
4
|
-
*This function handles at most milliseconds precision, smaller units are lost in conversion process
|
|
5
|
-
*/
|
|
6
|
-
export declare function toApiTime(time: dayjs.Dayjs): ApiTimeOnly;
|
|
7
|
-
export declare function toApiTime(time: dayjs.Dayjs | undefined): ApiTimeOnly | undefined;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import duration from "dayjs/plugin/duration";
|
|
2
|
-
import type { ApiTimeSpan } from "@leancodepl/api-date";
|
|
3
|
-
/**
|
|
4
|
-
*This function handles at most milliseconds precision, smaller units are lost in conversion process
|
|
5
|
-
*/
|
|
6
|
-
export declare function fromApiTimeSpan(timeSpan: ApiTimeSpan): duration.Duration;
|
|
7
|
-
export declare function fromApiTimeSpan(timeSpan: ApiTimeSpan | undefined): duration.Duration | undefined;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import duration from "dayjs/plugin/duration";
|
|
2
|
-
import type { ApiTimeSpan } from "@leancodepl/api-date";
|
|
3
|
-
/**
|
|
4
|
-
*This function handles at most milliseconds precision, smaller units are lost in conversion process
|
|
5
|
-
*/
|
|
6
|
-
export declare function toApiTimeSpan(duration: duration.Duration): ApiTimeSpan;
|
|
7
|
-
export declare function toApiTimeSpan(duration: duration.Duration | undefined): ApiTimeSpan | undefined;
|