@leancodepl/api-date-dayjs 7.8.2 → 8.0.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.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var apiDate = require('@leancodepl/api-date');
6
4
  var dayjs = require('dayjs');
7
5
  var customParseFormat = require('dayjs/plugin/customParseFormat');
@@ -9,36 +7,26 @@ var utc = require('dayjs/plugin/utc');
9
7
  var duration = require('dayjs/plugin/duration');
10
8
  var apiDateUtils = require('@leancodepl/api-date-utils');
11
9
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
15
- var customParseFormat__default = /*#__PURE__*/_interopDefaultLegacy(customParseFormat);
16
- var utc__default = /*#__PURE__*/_interopDefaultLegacy(utc);
17
- var duration__default = /*#__PURE__*/_interopDefaultLegacy(duration);
18
-
19
- dayjs__default["default"].extend(customParseFormat__default["default"]);
10
+ dayjs.extend(customParseFormat);
20
11
  function fromApiTime(time) {
21
12
  if (!time) {
22
13
  return undefined;
23
14
  }
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- return dayjs__default["default"](time, "HH:mm:ss.SSS");
15
+ return dayjs(time, "HH:mm:ss.SSS");
26
16
  }
27
17
 
28
18
  function toApiTime(time) {
29
19
  if (!time) {
30
20
  return undefined;
31
21
  }
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
22
  return time.format("HH:mm:ss.SSS");
34
23
  }
35
24
 
36
25
  function fromApiDate(date) {
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- return dayjs__default["default"](date);
26
+ return dayjs(date);
39
27
  }
40
28
 
41
- dayjs__default["default"].extend(utc__default["default"]);
29
+ dayjs.extend(utc);
42
30
  /**
43
31
  * This function keeps local time (excluding timezone/offset) but sets its offset to UTC
44
32
  */ function dropLocalOffset(time) {
@@ -46,48 +34,45 @@ dayjs__default["default"].extend(utc__default["default"]);
46
34
  }
47
35
 
48
36
  function toApiDate(date) {
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
37
  return dropLocalOffset(date).startOf("day").format("YYYY-MM-DD");
51
38
  }
52
39
 
53
- dayjs__default["default"].extend(customParseFormat__default["default"]);
40
+ dayjs.extend(customParseFormat);
54
41
  function fromApiDateTimeOffset(datetime) {
55
42
  if (!datetime) {
56
43
  return undefined;
57
44
  }
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- return dayjs__default["default"](datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
45
+ return dayjs(datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
60
46
  }
61
47
 
62
48
  function toApiDateTimeOffset(time) {
63
49
  if (!time) {
64
50
  return undefined;
65
51
  }
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
52
  return time.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
68
53
  }
69
54
 
70
- dayjs__default["default"].extend(duration__default["default"]);
55
+ dayjs.extend(duration);
71
56
  function fromApiTimeSpan(timeSpan) {
72
57
  if (!timeSpan) {
73
58
  return undefined;
74
59
  }
75
60
  const parsedDuration = apiDateUtils.parseApiTimeSpan(timeSpan);
76
61
  const isNegative = parsedDuration.sign === "-";
77
- const dayjsDuration = dayjs__default["default"].duration(parsedDuration.values);
62
+ const dayjsDuration = dayjs.duration(parsedDuration.values);
78
63
  if (isNegative) {
79
- return dayjs__default["default"].duration(-dayjsDuration.asMilliseconds());
64
+ return dayjs.duration(-dayjsDuration.asMilliseconds());
80
65
  }
81
66
  return dayjsDuration;
82
67
  }
83
68
 
84
- dayjs__default["default"].extend(duration__default["default"]);
69
+ dayjs.extend(duration);
85
70
  function toApiTimeSpan(duration) {
86
71
  if (!duration) {
87
72
  return undefined;
88
73
  }
89
74
  const isNegative = duration.asMilliseconds() < 0;
90
- const absDuration = dayjs__default["default"].duration(Math.abs(duration.asMilliseconds()));
75
+ const absDuration = dayjs.duration(Math.abs(duration.asMilliseconds()));
91
76
  const days = Math.floor(absDuration.asDays());
92
77
  let stringTimeSpan = "";
93
78
  if (isNegative) {
@@ -97,7 +82,6 @@ function toApiTimeSpan(duration) {
97
82
  stringTimeSpan += `${days}.`;
98
83
  }
99
84
  stringTimeSpan += absDuration.format("HH:mm:ss.SSS");
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
85
  return stringTimeSpan;
102
86
  }
103
87
 
@@ -111,7 +95,7 @@ exports.toApiDateTimeOffset = toApiDateTimeOffset;
111
95
  exports.toApiTime = toApiTime;
112
96
  exports.toApiTimeSpan = toApiTimeSpan;
113
97
  Object.keys(apiDate).forEach(function (k) {
114
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
98
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
115
99
  enumerable: true,
116
100
  get: function () { return apiDate[k]; }
117
101
  });
package/index.esm.js CHANGED
@@ -10,7 +10,6 @@ function fromApiTime(time) {
10
10
  if (!time) {
11
11
  return undefined;
12
12
  }
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
13
  return dayjs(time, "HH:mm:ss.SSS");
15
14
  }
16
15
 
@@ -18,12 +17,10 @@ function toApiTime(time) {
18
17
  if (!time) {
19
18
  return undefined;
20
19
  }
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
20
  return time.format("HH:mm:ss.SSS");
23
21
  }
24
22
 
25
23
  function fromApiDate(date) {
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
24
  return dayjs(date);
28
25
  }
29
26
 
@@ -35,7 +32,6 @@ dayjs.extend(utc);
35
32
  }
36
33
 
37
34
  function toApiDate(date) {
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
35
  return dropLocalOffset(date).startOf("day").format("YYYY-MM-DD");
40
36
  }
41
37
 
@@ -44,7 +40,6 @@ function fromApiDateTimeOffset(datetime) {
44
40
  if (!datetime) {
45
41
  return undefined;
46
42
  }
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
43
  return dayjs(datetime, "YYYY-MM-DDTHH:mm:ss.SSSZ");
49
44
  }
50
45
 
@@ -52,7 +47,6 @@ function toApiDateTimeOffset(time) {
52
47
  if (!time) {
53
48
  return undefined;
54
49
  }
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
50
  return time.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
57
51
  }
58
52
 
@@ -86,7 +80,6 @@ function toApiTimeSpan(duration) {
86
80
  stringTimeSpan += `${days}.`;
87
81
  }
88
82
  stringTimeSpan += absDuration.format("HH:mm:ss.SSS");
89
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
83
  return stringTimeSpan;
91
84
  }
92
85
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@leancodepl/api-date-dayjs",
3
- "version": "7.8.2",
3
+ "version": "8.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
- "@leancodepl/api-date": "7.8.2",
7
- "@leancodepl/api-date-utils": "7.8.2",
6
+ "@leancodepl/api-date": "8.0.0",
7
+ "@leancodepl/api-date-utils": "8.0.0",
8
8
  "dayjs": ">=1.9.0"
9
9
  },
10
10
  "devDependencies": {
@@ -14,10 +14,12 @@
14
14
  "./package.json": "./package.json",
15
15
  ".": {
16
16
  "module": "./index.esm.js",
17
+ "types": "./index.esm.d.ts",
17
18
  "import": "./index.cjs.mjs",
18
19
  "default": "./index.cjs.js"
19
20
  }
20
21
  },
21
22
  "module": "./index.esm.js",
22
- "main": "./index.cjs.js"
23
+ "main": "./index.cjs.js",
24
+ "types": "./index.esm.d.ts"
23
25
  }