@leancodepl/api-date-dayjs 7.1.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/index.cjs.d.ts +1 -0
- package/index.cjs.js +127 -0
- package/index.esm.js +86 -0
- package/package.json +15 -0
- package/src/index.d.ts +10 -0
- package/src/lib/date/fromApiDate.d.ts +3 -0
- package/src/lib/date/toApiDate.d.ts +3 -0
- package/src/lib/dateTimeOffset/fromApiDateTimeOffset.d.ts +7 -0
- package/src/lib/dateTimeOffset/toApiDateTimeOffset.d.ts +7 -0
- package/src/lib/time/fromApiTime.d.ts +7 -0
- package/src/lib/time/toApiTime.d.ts +7 -0
- package/src/lib/timeSpan/fromApiTimeSpan.d.ts +7 -0
- package/src/lib/timeSpan/toApiTimeSpan.d.ts +7 -0
- package/src/lib/utils/dropLocalOffset.d.ts +5 -0
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var apiDate = require('@leancodepl/api-date');
|
|
6
|
+
var dayjs = require('dayjs');
|
|
7
|
+
var customParseFormat = require('dayjs/plugin/customParseFormat');
|
|
8
|
+
var utc = require('dayjs/plugin/utc');
|
|
9
|
+
var apiDateUtils = require('@leancodepl/api-date-utils');
|
|
10
|
+
var duration = require('dayjs/plugin/duration');
|
|
11
|
+
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n["default"] = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var dayjs__namespace = /*#__PURE__*/_interopNamespace(dayjs);
|
|
31
|
+
var customParseFormat__namespace = /*#__PURE__*/_interopNamespace(customParseFormat);
|
|
32
|
+
var utc__namespace = /*#__PURE__*/_interopNamespace(utc);
|
|
33
|
+
var duration__namespace = /*#__PURE__*/_interopNamespace(duration);
|
|
34
|
+
|
|
35
|
+
dayjs__namespace.extend(customParseFormat__namespace);
|
|
36
|
+
function fromApiTime(time) {
|
|
37
|
+
if (!time) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return dayjs__namespace(time, "HH:mm:ss.SSS");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function toApiTime(time) {
|
|
44
|
+
if (!time) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return time.format("HH:mm:ss.SSS");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function fromApiDate(date) {
|
|
51
|
+
return dayjs__namespace(date);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
dayjs__namespace.extend(utc__namespace);
|
|
55
|
+
/**
|
|
56
|
+
* This function keeps local time (excluding timezone/offset) but sets its offset to UTC
|
|
57
|
+
*/ function dropLocalOffset(time) {
|
|
58
|
+
return time.clone().utc(true);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toApiDate(date) {
|
|
62
|
+
return dropLocalOffset(date).startOf("day").format("YYYY-MM-DD");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dayjs__namespace.extend(customParseFormat__namespace);
|
|
66
|
+
function fromApiDateTimeOffset(datetime) {
|
|
67
|
+
if (!datetime) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return dayjs__namespace(datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function toApiDateTimeOffset(time) {
|
|
74
|
+
if (!time) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return time.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
dayjs__namespace.extend(duration__namespace);
|
|
81
|
+
function fromApiTimeSpan(timeSpan) {
|
|
82
|
+
if (!timeSpan) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const parsedDuration = apiDateUtils.parseApiTimeSpan(timeSpan);
|
|
86
|
+
const isNegative = parsedDuration.sign === "-";
|
|
87
|
+
const dayjsDuration = dayjs__namespace.duration(parsedDuration.values);
|
|
88
|
+
if (isNegative) {
|
|
89
|
+
return dayjs__namespace.duration(-dayjsDuration.asMilliseconds());
|
|
90
|
+
}
|
|
91
|
+
return dayjsDuration;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
dayjs__namespace.extend(duration__namespace);
|
|
95
|
+
function toApiTimeSpan(duration) {
|
|
96
|
+
if (!duration) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const isNegative = duration.asMilliseconds() < 0;
|
|
100
|
+
const absDuration = dayjs__namespace.duration(Math.abs(duration.asMilliseconds()));
|
|
101
|
+
const days = Math.floor(absDuration.asDays());
|
|
102
|
+
let stringTimeSpan = "";
|
|
103
|
+
if (isNegative) {
|
|
104
|
+
stringTimeSpan += "-";
|
|
105
|
+
}
|
|
106
|
+
if (days > 0) {
|
|
107
|
+
stringTimeSpan += `${days}.`;
|
|
108
|
+
}
|
|
109
|
+
stringTimeSpan += absDuration.format("HH:mm:ss.SSS");
|
|
110
|
+
return stringTimeSpan;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.dropLocalOffset = dropLocalOffset;
|
|
114
|
+
exports.fromApiDate = fromApiDate;
|
|
115
|
+
exports.fromApiDateTimeOffset = fromApiDateTimeOffset;
|
|
116
|
+
exports.fromApiTime = fromApiTime;
|
|
117
|
+
exports.fromApiTimeSpan = fromApiTimeSpan;
|
|
118
|
+
exports.toApiDate = toApiDate;
|
|
119
|
+
exports.toApiDateTimeOffset = toApiDateTimeOffset;
|
|
120
|
+
exports.toApiTime = toApiTime;
|
|
121
|
+
exports.toApiTimeSpan = toApiTimeSpan;
|
|
122
|
+
Object.keys(apiDate).forEach(function (k) {
|
|
123
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function () { return apiDate[k]; }
|
|
126
|
+
});
|
|
127
|
+
});
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export * from '@leancodepl/api-date';
|
|
2
|
+
import * as dayjs from 'dayjs';
|
|
3
|
+
import * as customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
|
+
import * as utc from 'dayjs/plugin/utc';
|
|
5
|
+
import { parseApiTimeSpan } from '@leancodepl/api-date-utils';
|
|
6
|
+
import * as duration from 'dayjs/plugin/duration';
|
|
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
|
+
return dayjs(date);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
dayjs.extend(utc);
|
|
28
|
+
/**
|
|
29
|
+
* This function keeps local time (excluding timezone/offset) but sets its offset to UTC
|
|
30
|
+
*/ function dropLocalOffset(time) {
|
|
31
|
+
return time.clone().utc(true);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function toApiDate(date) {
|
|
35
|
+
return dropLocalOffset(date).startOf("day").format("YYYY-MM-DD");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
dayjs.extend(customParseFormat);
|
|
39
|
+
function fromApiDateTimeOffset(datetime) {
|
|
40
|
+
if (!datetime) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return dayjs(datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function toApiDateTimeOffset(time) {
|
|
47
|
+
if (!time) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return time.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
dayjs.extend(duration);
|
|
54
|
+
function fromApiTimeSpan(timeSpan) {
|
|
55
|
+
if (!timeSpan) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const parsedDuration = parseApiTimeSpan(timeSpan);
|
|
59
|
+
const isNegative = parsedDuration.sign === "-";
|
|
60
|
+
const dayjsDuration = dayjs.duration(parsedDuration.values);
|
|
61
|
+
if (isNegative) {
|
|
62
|
+
return dayjs.duration(-dayjsDuration.asMilliseconds());
|
|
63
|
+
}
|
|
64
|
+
return dayjsDuration;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
dayjs.extend(duration);
|
|
68
|
+
function toApiTimeSpan(duration) {
|
|
69
|
+
if (!duration) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const isNegative = duration.asMilliseconds() < 0;
|
|
73
|
+
const absDuration = dayjs.duration(Math.abs(duration.asMilliseconds()));
|
|
74
|
+
const days = Math.floor(absDuration.asDays());
|
|
75
|
+
let stringTimeSpan = "";
|
|
76
|
+
if (isNegative) {
|
|
77
|
+
stringTimeSpan += "-";
|
|
78
|
+
}
|
|
79
|
+
if (days > 0) {
|
|
80
|
+
stringTimeSpan += `${days}.`;
|
|
81
|
+
}
|
|
82
|
+
stringTimeSpan += absDuration.format("HH:mm:ss.SSS");
|
|
83
|
+
return stringTimeSpan;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { dropLocalOffset, fromApiDate, fromApiDateTimeOffset, fromApiTime, fromApiTimeSpan, toApiDate, toApiDateTimeOffset, toApiTime, toApiTimeSpan };
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leancodepl/api-date-dayjs",
|
|
3
|
+
"version": "7.1.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./index.cjs.js",
|
|
6
|
+
"module": "./index.esm.js",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@leancodepl/api-date": "7.1.0",
|
|
9
|
+
"@leancodepl/api-date-utils": "7.1.0",
|
|
10
|
+
"dayjs": ">=1.0.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"timezone-mock": "1.3.6"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiDateTimeOffset } from "@leancodepl/api-date";
|
|
2
|
+
import * as dayjs from "dayjs";
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiDateTimeOffset } from "@leancodepl/api-date";
|
|
2
|
+
import * as dayjs from "dayjs";
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiTimeOnly } from "@leancodepl/api-date";
|
|
2
|
+
import * as dayjs from "dayjs";
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiTimeOnly } from "@leancodepl/api-date";
|
|
2
|
+
import * as dayjs from "dayjs";
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiTimeSpan } from "@leancodepl/api-date";
|
|
2
|
+
import * as duration from "dayjs/plugin/duration";
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiTimeSpan } from "@leancodepl/api-date";
|
|
2
|
+
import * as duration from "dayjs/plugin/duration";
|
|
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;
|