@leancodepl/api-date-datefns 8.4.0 → 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 CHANGED
@@ -1,25 +1,61 @@
1
1
  {
2
2
  "name": "@leancodepl/api-date-datefns",
3
- "version": "8.4.0",
3
+ "version": "8.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
- "@leancodepl/api-date": "8.4.0",
7
- "@leancodepl/api-date-utils": "8.4.0",
6
+ "@leancodepl/api-date": "8.5.0",
7
+ "@leancodepl/api-date-utils": "8.5.0",
8
8
  "date-fns": ">=2.0.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-datefns"
24
+ },
25
+ "homepage": "https://github.com/leancodepl/js_corelibrary",
26
+ "bugs": {
27
+ "url": "https://github.com/leancodepl/js_corelibrary/issues"
28
+ },
29
+ "description": "Date-fns integration for API date type conversion",
30
+ "keywords": [
31
+ "date",
32
+ "date-fns",
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.esm.d.ts",
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.esm.d.ts"
60
+ "types": "./index.d.ts"
25
61
  }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;
package/index.cjs.js DELETED
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- var apiDate = require('@leancodepl/api-date');
4
- var dateFns = require('date-fns');
5
- var apiDateUtils = require('@leancodepl/api-date-utils');
6
-
7
- function fromApiTime(time) {
8
- if (!time) {
9
- return undefined;
10
- }
11
- return dateFns.parse(time, "HH:mm:ss.SSS", new Date());
12
- }
13
-
14
- function toApiTime(time) {
15
- if (!time) {
16
- return undefined;
17
- }
18
- return dateFns.format(time, "HH:mm:ss.SSS");
19
- }
20
-
21
- function fromApiDate(date) {
22
- if (date && typeof date === "string") {
23
- return dateFns.parse(date, "yyyy-MM-dd", new Date());
24
- }
25
- return undefined;
26
- }
27
-
28
- function toApiDate(date) {
29
- if (!date) {
30
- return undefined;
31
- }
32
- return dateFns.format(date, "yyyy-MM-dd");
33
- }
34
-
35
- function fromApiDateTimeOffset(dateTimeOffset) {
36
- if (!dateTimeOffset) {
37
- return undefined;
38
- }
39
- return dateFns.parse(dateTimeOffset, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", new Date());
40
- }
41
-
42
- function toApiDateTimeOffset(dateTimeOffset) {
43
- if (!dateTimeOffset) {
44
- return undefined;
45
- }
46
- return dateFns.format(dateTimeOffset, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
47
- }
48
-
49
- function fromApiTimeSpan(timeSpan) {
50
- if (!timeSpan) {
51
- return undefined;
52
- }
53
- const parsedApiTimeSpan = apiDateUtils.parseApiTimeSpan(timeSpan);
54
- const parsedApiTimeSpanValues = parsedApiTimeSpan.values;
55
- const daysInMilliseconds = dateFns.hoursToMilliseconds(parsedApiTimeSpanValues.days * 24);
56
- const hoursInMilliseconds = dateFns.hoursToMilliseconds(parsedApiTimeSpanValues.hours);
57
- const minutesInMilliseconds = dateFns.minutesToMilliseconds(parsedApiTimeSpanValues.minutes);
58
- const secondsInMilliseconds = dateFns.secondsToMilliseconds(parsedApiTimeSpanValues.seconds);
59
- const differenceInMilliseconds = daysInMilliseconds + hoursInMilliseconds + minutesInMilliseconds + secondsInMilliseconds + parsedApiTimeSpanValues.milliseconds;
60
- const signBasedMultiplier = parsedApiTimeSpan.sign === "-" ? -1 : 1;
61
- return signBasedMultiplier * differenceInMilliseconds;
62
- }
63
-
64
- function padTo2(x) {
65
- var _x_toFixed;
66
- const stringified = (_x_toFixed = x == null ? void 0 : x.toFixed(0)) != null ? _x_toFixed : "0";
67
- return stringified.padStart(2, "0");
68
- }
69
-
70
- function parseDifferenceInMilliseconds(differenceInMilliseconds) {
71
- const milliseconds = differenceInMilliseconds % 1000;
72
- const seconds = Math.floor(differenceInMilliseconds / 1000 % 60);
73
- const minutes = Math.floor(differenceInMilliseconds / (1000 * 60) % 60);
74
- const hours = Math.floor(differenceInMilliseconds / (1000 * 60 * 60) % 24);
75
- const days = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24));
76
- return {
77
- milliseconds,
78
- seconds,
79
- minutes,
80
- hours,
81
- days
82
- };
83
- }
84
-
85
- function toApiTimeSpan(differenceInMilliseconds) {
86
- let stringTimeSpan = "";
87
- if (!differenceInMilliseconds) {
88
- return undefined;
89
- }
90
- const isNegative = differenceInMilliseconds < 0;
91
- const absDifferenceInMilliseconds = Math.abs(differenceInMilliseconds);
92
- const { milliseconds, seconds, minutes, hours, days } = parseDifferenceInMilliseconds(absDifferenceInMilliseconds);
93
- if (isNegative) {
94
- stringTimeSpan += "-";
95
- }
96
- if (days > 0) {
97
- stringTimeSpan += `${days}.`;
98
- }
99
- stringTimeSpan += `${padTo2(hours)}:${padTo2(minutes)}:${padTo2(seconds)}`;
100
- if (milliseconds > 0) {
101
- stringTimeSpan += `.${milliseconds}`;
102
- }
103
- return stringTimeSpan;
104
- }
105
-
106
- exports.fromApiDate = fromApiDate;
107
- exports.fromApiDateTimeOffset = fromApiDateTimeOffset;
108
- exports.fromApiTime = fromApiTime;
109
- exports.fromApiTimeSpan = fromApiTimeSpan;
110
- exports.toApiDate = toApiDate;
111
- exports.toApiDateTimeOffset = toApiDateTimeOffset;
112
- exports.toApiTime = toApiTime;
113
- exports.toApiTimeSpan = toApiTimeSpan;
114
- Object.keys(apiDate).forEach(function (k) {
115
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
116
- enumerable: true,
117
- get: function () { return apiDate[k]; }
118
- });
119
- });
package/index.cjs.mjs DELETED
@@ -1,2 +0,0 @@
1
- export * from './index.cjs.js';
2
- export { _default as default } from './index.cjs.default.js';
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
package/index.esm.js DELETED
@@ -1,104 +0,0 @@
1
- export * from '@leancodepl/api-date';
2
- import { parse, format, hoursToMilliseconds, minutesToMilliseconds, secondsToMilliseconds } from 'date-fns';
3
- import { parseApiTimeSpan } from '@leancodepl/api-date-utils';
4
-
5
- function fromApiTime(time) {
6
- if (!time) {
7
- return undefined;
8
- }
9
- return parse(time, "HH:mm:ss.SSS", new Date());
10
- }
11
-
12
- function toApiTime(time) {
13
- if (!time) {
14
- return undefined;
15
- }
16
- return format(time, "HH:mm:ss.SSS");
17
- }
18
-
19
- function fromApiDate(date) {
20
- if (date && typeof date === "string") {
21
- return parse(date, "yyyy-MM-dd", new Date());
22
- }
23
- return undefined;
24
- }
25
-
26
- function toApiDate(date) {
27
- if (!date) {
28
- return undefined;
29
- }
30
- return format(date, "yyyy-MM-dd");
31
- }
32
-
33
- function fromApiDateTimeOffset(dateTimeOffset) {
34
- if (!dateTimeOffset) {
35
- return undefined;
36
- }
37
- return parse(dateTimeOffset, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", new Date());
38
- }
39
-
40
- function toApiDateTimeOffset(dateTimeOffset) {
41
- if (!dateTimeOffset) {
42
- return undefined;
43
- }
44
- return format(dateTimeOffset, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
45
- }
46
-
47
- function fromApiTimeSpan(timeSpan) {
48
- if (!timeSpan) {
49
- return undefined;
50
- }
51
- const parsedApiTimeSpan = parseApiTimeSpan(timeSpan);
52
- const parsedApiTimeSpanValues = parsedApiTimeSpan.values;
53
- const daysInMilliseconds = hoursToMilliseconds(parsedApiTimeSpanValues.days * 24);
54
- const hoursInMilliseconds = hoursToMilliseconds(parsedApiTimeSpanValues.hours);
55
- const minutesInMilliseconds = minutesToMilliseconds(parsedApiTimeSpanValues.minutes);
56
- const secondsInMilliseconds = secondsToMilliseconds(parsedApiTimeSpanValues.seconds);
57
- const differenceInMilliseconds = daysInMilliseconds + hoursInMilliseconds + minutesInMilliseconds + secondsInMilliseconds + parsedApiTimeSpanValues.milliseconds;
58
- const signBasedMultiplier = parsedApiTimeSpan.sign === "-" ? -1 : 1;
59
- return signBasedMultiplier * differenceInMilliseconds;
60
- }
61
-
62
- function padTo2(x) {
63
- var _x_toFixed;
64
- const stringified = (_x_toFixed = x == null ? void 0 : x.toFixed(0)) != null ? _x_toFixed : "0";
65
- return stringified.padStart(2, "0");
66
- }
67
-
68
- function parseDifferenceInMilliseconds(differenceInMilliseconds) {
69
- const milliseconds = differenceInMilliseconds % 1000;
70
- const seconds = Math.floor(differenceInMilliseconds / 1000 % 60);
71
- const minutes = Math.floor(differenceInMilliseconds / (1000 * 60) % 60);
72
- const hours = Math.floor(differenceInMilliseconds / (1000 * 60 * 60) % 24);
73
- const days = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24));
74
- return {
75
- milliseconds,
76
- seconds,
77
- minutes,
78
- hours,
79
- days
80
- };
81
- }
82
-
83
- function toApiTimeSpan(differenceInMilliseconds) {
84
- let stringTimeSpan = "";
85
- if (!differenceInMilliseconds) {
86
- return undefined;
87
- }
88
- const isNegative = differenceInMilliseconds < 0;
89
- const absDifferenceInMilliseconds = Math.abs(differenceInMilliseconds);
90
- const { milliseconds, seconds, minutes, hours, days } = parseDifferenceInMilliseconds(absDifferenceInMilliseconds);
91
- if (isNegative) {
92
- stringTimeSpan += "-";
93
- }
94
- if (days > 0) {
95
- stringTimeSpan += `${days}.`;
96
- }
97
- stringTimeSpan += `${padTo2(hours)}:${padTo2(minutes)}:${padTo2(seconds)}`;
98
- if (milliseconds > 0) {
99
- stringTimeSpan += `.${milliseconds}`;
100
- }
101
- return stringTimeSpan;
102
- }
103
-
104
- export { fromApiDate, fromApiDateTimeOffset, fromApiTime, fromApiTimeSpan, toApiDate, toApiDateTimeOffset, toApiTime, toApiTimeSpan };
package/src/index.d.ts DELETED
@@ -1,9 +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";
@@ -1,3 +0,0 @@
1
- import type { ApiDateOnly } from "@leancodepl/api-date";
2
- export declare function fromApiDate(date: ApiDateOnly): Date;
3
- export declare function fromApiDate(date: ApiDateOnly | undefined): Date | undefined;
@@ -1,3 +0,0 @@
1
- import type { ApiDateOnly } from "@leancodepl/api-date";
2
- export declare function toApiDate(date: Date): ApiDateOnly;
3
- export declare function toApiDate(date: Date | undefined): ApiDateOnly | undefined;
@@ -1,6 +0,0 @@
1
- import type { ApiDateTimeOffset } from "@leancodepl/api-date";
2
- /**
3
- *This function handles at most milliseconds precision, smaller units are lost in conversion process
4
- */
5
- export declare function fromApiDateTimeOffset(dateTimeOffset: ApiDateTimeOffset): Date;
6
- export declare function fromApiDateTimeOffset(dateTimeOffset: ApiDateTimeOffset | undefined): Date | undefined;
@@ -1,6 +0,0 @@
1
- import type { ApiDateTimeOffset } from "@leancodepl/api-date";
2
- /**
3
- *This function handles at most milliseconds precision, smaller units are lost in conversion process
4
- */
5
- export declare function toApiDateTimeOffset(dateTimeOffset: Date): ApiDateTimeOffset;
6
- export declare function toApiDateTimeOffset(dateTimeOffset: Date | undefined): ApiDateTimeOffset | undefined;
@@ -1,6 +0,0 @@
1
- import type { ApiTimeOnly } from "@leancodepl/api-date";
2
- /**
3
- *This function handles at most milliseconds precision, smaller units are lost in conversion process
4
- */
5
- export declare function fromApiTime(time: ApiTimeOnly): Date;
6
- export declare function fromApiTime(time: ApiTimeOnly | undefined): Date | undefined;
@@ -1,6 +0,0 @@
1
- import type { ApiTimeOnly } from "@leancodepl/api-date";
2
- /**
3
- *This function handles at most milliseconds precision, smaller units are lost in conversion process
4
- */
5
- export declare function toApiTime(time: Date): ApiTimeOnly;
6
- export declare function toApiTime(time: Date | undefined): ApiTimeOnly | undefined;
@@ -1,3 +0,0 @@
1
- import type { ApiTimeSpan } from "@leancodepl/api-date";
2
- export declare function fromApiTimeSpan(timeSpan: ApiTimeSpan): number;
3
- export declare function fromApiTimeSpan(timeSpan: ApiTimeSpan | undefined): number | undefined;
@@ -1,3 +0,0 @@
1
- import type { ApiTimeSpan } from "@leancodepl/api-date";
2
- export declare function toApiTimeSpan(differenceInMilliseconds: number): ApiTimeSpan;
3
- export declare function toApiTimeSpan(differenceInMilliseconds: number | undefined): ApiTimeSpan | undefined;
@@ -1 +0,0 @@
1
- export declare function padTo2(x?: number): string;
@@ -1,7 +0,0 @@
1
- export declare function parseDifferenceInMilliseconds(differenceInMilliseconds: number): {
2
- milliseconds: number;
3
- seconds: number;
4
- minutes: number;
5
- hours: number;
6
- days: number;
7
- };