@leancodepl/api-date-datefns 8.4.0 → 8.5.1
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/README.md +130 -0
- package/package.json +36 -5
- package/src/lib/date/fromApiDate.d.ts +16 -0
- package/src/lib/date/toApiDate.d.ts +16 -0
- package/index.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @leancodepl/api-date-datefns
|
|
2
|
+
|
|
3
|
+
Date conversion utilities using date-fns for API date types.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @leancodepl/api-date-datefns
|
|
9
|
+
# or
|
|
10
|
+
yarn add @leancodepl/api-date-datefns
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### `fromApiDate(date)`
|
|
16
|
+
|
|
17
|
+
Converts ApiDateOnly to JavaScript Date using date-fns.
|
|
18
|
+
|
|
19
|
+
**Parameters:**
|
|
20
|
+
|
|
21
|
+
- `date: ApiDateOnly` - The API date string to convert
|
|
22
|
+
|
|
23
|
+
**Returns:** JavaScript Date object
|
|
24
|
+
|
|
25
|
+
### `toApiDate(date)`
|
|
26
|
+
|
|
27
|
+
Converts JavaScript Date to ApiDateOnly using date-fns.
|
|
28
|
+
|
|
29
|
+
**Parameters:**
|
|
30
|
+
|
|
31
|
+
- `date: Date` - The JavaScript Date to convert
|
|
32
|
+
|
|
33
|
+
**Returns:** ApiDateOnly string
|
|
34
|
+
|
|
35
|
+
### `fromApiTime(time)`
|
|
36
|
+
|
|
37
|
+
Converts ApiTimeOnly to JavaScript Date using date-fns.
|
|
38
|
+
|
|
39
|
+
**Parameters:**
|
|
40
|
+
|
|
41
|
+
- `time: ApiTimeOnly` - The API time string to convert
|
|
42
|
+
|
|
43
|
+
**Returns:** JavaScript Date object
|
|
44
|
+
|
|
45
|
+
### `toApiTime(time)`
|
|
46
|
+
|
|
47
|
+
Converts JavaScript Date to ApiTimeOnly using date-fns.
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
|
|
51
|
+
- `time: Date` - The JavaScript Date to convert
|
|
52
|
+
|
|
53
|
+
**Returns:** ApiTimeOnly string
|
|
54
|
+
|
|
55
|
+
### `fromApiDateTimeOffset(dateTimeOffset)`
|
|
56
|
+
|
|
57
|
+
Converts ApiDateTimeOffset to JavaScript Date using date-fns.
|
|
58
|
+
|
|
59
|
+
**Parameters:**
|
|
60
|
+
|
|
61
|
+
- `dateTimeOffset: ApiDateTimeOffset` - The API datetime with offset string to convert
|
|
62
|
+
|
|
63
|
+
**Returns:** JavaScript Date object
|
|
64
|
+
|
|
65
|
+
### `toApiDateTimeOffset(dateTimeOffset)`
|
|
66
|
+
|
|
67
|
+
Converts JavaScript Date to ApiDateTimeOffset using date-fns.
|
|
68
|
+
|
|
69
|
+
**Parameters:**
|
|
70
|
+
|
|
71
|
+
- `dateTimeOffset: Date` - The JavaScript Date to convert
|
|
72
|
+
|
|
73
|
+
**Returns:** ApiDateTimeOffset string
|
|
74
|
+
|
|
75
|
+
### `fromApiTimeSpan(timeSpan)`
|
|
76
|
+
|
|
77
|
+
Converts ApiTimeSpan to milliseconds using date-fns.
|
|
78
|
+
|
|
79
|
+
**Parameters:**
|
|
80
|
+
|
|
81
|
+
- `timeSpan: ApiTimeSpan` - The API timespan string to convert
|
|
82
|
+
|
|
83
|
+
**Returns:** Duration in milliseconds
|
|
84
|
+
|
|
85
|
+
### `toApiTimeSpan(differenceInMilliseconds)`
|
|
86
|
+
|
|
87
|
+
Converts milliseconds to ApiTimeSpan using date-fns.
|
|
88
|
+
|
|
89
|
+
**Parameters:**
|
|
90
|
+
|
|
91
|
+
- `differenceInMilliseconds: number` - The duration in milliseconds to convert
|
|
92
|
+
|
|
93
|
+
**Returns:** ApiTimeSpan string
|
|
94
|
+
|
|
95
|
+
## Usage Examples
|
|
96
|
+
|
|
97
|
+
### Date Conversion
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { fromApiDate, toApiDate } from "@leancodepl/api-date-datefns"
|
|
101
|
+
|
|
102
|
+
const apiDate = "2023-12-25"
|
|
103
|
+
const jsDate = fromApiDate(apiDate)
|
|
104
|
+
console.log(jsDate) // Date object
|
|
105
|
+
|
|
106
|
+
const convertedBack = toApiDate(jsDate)
|
|
107
|
+
console.log(convertedBack) // '2023-12-25'
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Time Conversion
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { fromApiTime, toApiTime } from "@leancodepl/api-date-datefns"
|
|
114
|
+
|
|
115
|
+
const apiTime = "14:30:00"
|
|
116
|
+
const jsDate = fromApiTime(apiTime)
|
|
117
|
+
const convertedBack = toApiTime(jsDate)
|
|
118
|
+
console.log(convertedBack) // '14:30:00'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### DateTime with Offset
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { fromApiDateTimeOffset, toApiDateTimeOffset } from "@leancodepl/api-date-datefns"
|
|
125
|
+
|
|
126
|
+
const apiDateTime = "2023-12-25T14:30:00+01:00"
|
|
127
|
+
const jsDate = fromApiDateTimeOffset(apiDateTime)
|
|
128
|
+
const convertedBack = toApiDateTimeOffset(jsDate)
|
|
129
|
+
console.log(convertedBack) // '2023-12-25T14:30:00+01:00'
|
|
130
|
+
```
|
package/package.json
CHANGED
|
@@ -1,25 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/api-date-datefns",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.1",
|
|
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.1",
|
|
7
|
+
"@leancodepl/api-date-utils": "8.5.1",
|
|
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
|
+
"sideEffects": false,
|
|
13
44
|
"exports": {
|
|
14
45
|
"./package.json": "./package.json",
|
|
15
46
|
".": {
|
|
16
47
|
"module": "./index.esm.js",
|
|
17
|
-
"types": "./index.
|
|
48
|
+
"types": "./index.d.ts",
|
|
18
49
|
"import": "./index.cjs.mjs",
|
|
19
50
|
"default": "./index.cjs.js"
|
|
20
51
|
}
|
|
21
52
|
},
|
|
22
53
|
"module": "./index.esm.js",
|
|
23
54
|
"main": "./index.cjs.js",
|
|
24
|
-
"types": "./index.
|
|
55
|
+
"types": "./index.d.ts"
|
|
25
56
|
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import type { ApiDateOnly } from "@leancodepl/api-date";
|
|
2
|
+
/**
|
|
3
|
+
* Converts ApiDateOnly to JavaScript Date using date-fns.
|
|
4
|
+
*
|
|
5
|
+
* Parses API date string format to JavaScript Date object with support
|
|
6
|
+
* for optional parameters. Uses date-fns parse function internally.
|
|
7
|
+
*
|
|
8
|
+
* @param date - The API date string to convert
|
|
9
|
+
* @returns JavaScript Date object or undefined if date is undefined
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { fromApiDate } from '@leancodepl/api-date-datefns';
|
|
13
|
+
*
|
|
14
|
+
* const jsDate = fromApiDate('2023-12-25');
|
|
15
|
+
* console.log(jsDate); // Date object for December 25, 2023
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
2
18
|
export declare function fromApiDate(date: ApiDateOnly): Date;
|
|
3
19
|
export declare function fromApiDate(date: ApiDateOnly | undefined): Date | undefined;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import type { ApiDateOnly } from "@leancodepl/api-date";
|
|
2
|
+
/**
|
|
3
|
+
* Converts JavaScript Date to ApiDateOnly using date-fns.
|
|
4
|
+
*
|
|
5
|
+
* Formats JavaScript Date object to API date string format with support
|
|
6
|
+
* for optional parameters. Uses date-fns format function internally.
|
|
7
|
+
*
|
|
8
|
+
* @param date - The JavaScript Date to convert
|
|
9
|
+
* @returns ApiDateOnly string or undefined if date is undefined
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { toApiDate } from '@leancodepl/api-date-datefns';
|
|
13
|
+
*
|
|
14
|
+
* const apiDate = toApiDate(new Date('2023-12-25'));
|
|
15
|
+
* console.log(apiDate); // '2023-12-25'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
2
18
|
export declare function toApiDate(date: Date): ApiDateOnly;
|
|
3
19
|
export declare function toApiDate(date: Date | undefined): ApiDateOnly | undefined;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
File without changes
|