@leancodepl/api-date-dayjs 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 +152 -0
- package/package.json +36 -5
- package/src/lib/date/fromApiDate.d.ts +16 -0
- package/src/lib/date/toApiDate.d.ts +17 -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,152 @@
|
|
|
1
|
+
# @leancodepl/api-date-dayjs
|
|
2
|
+
|
|
3
|
+
Date conversion utilities using Day.js for API date types.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @leancodepl/api-date-dayjs
|
|
9
|
+
# or
|
|
10
|
+
yarn add @leancodepl/api-date-dayjs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### `fromApiDate(date)`
|
|
16
|
+
|
|
17
|
+
Converts ApiDateOnly to Day.js object.
|
|
18
|
+
|
|
19
|
+
**Parameters:**
|
|
20
|
+
|
|
21
|
+
- `date: ApiDateOnly` - The API date string to convert
|
|
22
|
+
|
|
23
|
+
**Returns:** Day.js object
|
|
24
|
+
|
|
25
|
+
### `toApiDate(date)`
|
|
26
|
+
|
|
27
|
+
Converts Day.js object to ApiDateOnly.
|
|
28
|
+
|
|
29
|
+
**Parameters:**
|
|
30
|
+
|
|
31
|
+
- `date: dayjs.Dayjs` - The Day.js object to convert
|
|
32
|
+
|
|
33
|
+
**Returns:** ApiDateOnly string
|
|
34
|
+
|
|
35
|
+
### `fromApiTime(time)`
|
|
36
|
+
|
|
37
|
+
Converts ApiTimeOnly to Day.js object.
|
|
38
|
+
|
|
39
|
+
**Parameters:**
|
|
40
|
+
|
|
41
|
+
- `time: ApiTimeOnly` - The API time string to convert
|
|
42
|
+
|
|
43
|
+
**Returns:** Day.js object
|
|
44
|
+
|
|
45
|
+
### `toApiTime(time)`
|
|
46
|
+
|
|
47
|
+
Converts Day.js object to ApiTimeOnly.
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
|
|
51
|
+
- `time: dayjs.Dayjs` - The Day.js object to convert
|
|
52
|
+
|
|
53
|
+
**Returns:** ApiTimeOnly string
|
|
54
|
+
|
|
55
|
+
### `fromApiDateTimeOffset(datetime)`
|
|
56
|
+
|
|
57
|
+
Converts ApiDateTimeOffset to Day.js object.
|
|
58
|
+
|
|
59
|
+
**Parameters:**
|
|
60
|
+
|
|
61
|
+
- `datetime: ApiDateTimeOffset` - The API datetime with offset string to convert
|
|
62
|
+
|
|
63
|
+
**Returns:** Day.js object
|
|
64
|
+
|
|
65
|
+
### `toApiDateTimeOffset(time)`
|
|
66
|
+
|
|
67
|
+
Converts Day.js object to ApiDateTimeOffset.
|
|
68
|
+
|
|
69
|
+
**Parameters:**
|
|
70
|
+
|
|
71
|
+
- `time: dayjs.Dayjs` - The Day.js object to convert
|
|
72
|
+
|
|
73
|
+
**Returns:** ApiDateTimeOffset string
|
|
74
|
+
|
|
75
|
+
### `fromApiTimeSpan(timeSpan)`
|
|
76
|
+
|
|
77
|
+
Converts ApiTimeSpan to Day.js duration.
|
|
78
|
+
|
|
79
|
+
**Parameters:**
|
|
80
|
+
|
|
81
|
+
- `timeSpan: ApiTimeSpan` - The API timespan string to convert
|
|
82
|
+
|
|
83
|
+
**Returns:** Day.js duration object
|
|
84
|
+
|
|
85
|
+
### `toApiTimeSpan(duration)`
|
|
86
|
+
|
|
87
|
+
Converts Day.js duration to ApiTimeSpan.
|
|
88
|
+
|
|
89
|
+
**Parameters:**
|
|
90
|
+
|
|
91
|
+
- `duration: duration.Duration` - The Day.js duration object to convert
|
|
92
|
+
|
|
93
|
+
**Returns:** ApiTimeSpan string
|
|
94
|
+
|
|
95
|
+
### `dropLocalOffset(time)`
|
|
96
|
+
|
|
97
|
+
Utility to remove local timezone offset from Day.js object.
|
|
98
|
+
|
|
99
|
+
**Parameters:**
|
|
100
|
+
|
|
101
|
+
- `time: dayjs.Dayjs` - The Day.js object to process
|
|
102
|
+
|
|
103
|
+
**Returns:** Day.js object with UTC offset but keeping local time
|
|
104
|
+
|
|
105
|
+
## Usage Examples
|
|
106
|
+
|
|
107
|
+
### Date Conversion
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { fromApiDate, toApiDate } from "@leancodepl/api-date-dayjs"
|
|
111
|
+
import dayjs from "dayjs"
|
|
112
|
+
|
|
113
|
+
const apiDate = "2023-12-25"
|
|
114
|
+
const dayjsDate = fromApiDate(apiDate)
|
|
115
|
+
console.log(dayjsDate.format("YYYY-MM-DD")) // '2023-12-25'
|
|
116
|
+
|
|
117
|
+
const convertedBack = toApiDate(dayjsDate)
|
|
118
|
+
console.log(convertedBack) // '2023-12-25'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Time Conversion
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { fromApiTime, toApiTime } from "@leancodepl/api-date-dayjs"
|
|
125
|
+
|
|
126
|
+
const apiTime = "14:30:00"
|
|
127
|
+
const dayjsTime = fromApiTime(apiTime)
|
|
128
|
+
const convertedBack = toApiTime(dayjsTime)
|
|
129
|
+
console.log(convertedBack) // '14:30:00'
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### DateTime with Offset
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { fromApiDateTimeOffset, toApiDateTimeOffset } from "@leancodepl/api-date-dayjs"
|
|
136
|
+
|
|
137
|
+
const apiDateTime = "2023-12-25T14:30:00+01:00"
|
|
138
|
+
const dayjsDateTime = fromApiDateTimeOffset(apiDateTime)
|
|
139
|
+
const convertedBack = toApiDateTimeOffset(dayjsDateTime)
|
|
140
|
+
console.log(convertedBack) // '2023-12-25T14:30:00+01:00'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Timezone Handling
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { dropLocalOffset } from "@leancodepl/api-date-dayjs"
|
|
147
|
+
import dayjs from "dayjs"
|
|
148
|
+
|
|
149
|
+
const localDate = dayjs("2023-12-25T14:30:00")
|
|
150
|
+
const utcDate = dropLocalOffset(localDate)
|
|
151
|
+
console.log(utcDate.format()) // Date without local offset
|
|
152
|
+
```
|
package/package.json
CHANGED
|
@@ -1,25 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/api-date-dayjs",
|
|
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
|
"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
|
+
"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,4 +1,20 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
import type { ApiDateOnly } from "@leancodepl/api-date";
|
|
3
|
+
/**
|
|
4
|
+
* Converts ApiDateOnly to Day.js object.
|
|
5
|
+
*
|
|
6
|
+
* Parses API date string format to Day.js object with support
|
|
7
|
+
* for optional parameters. Uses Day.js constructor internally.
|
|
8
|
+
*
|
|
9
|
+
* @param date - The API date string to convert
|
|
10
|
+
* @returns Day.js object or undefined if date is undefined
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { fromApiDate } from '@leancodepl/api-date-dayjs';
|
|
14
|
+
*
|
|
15
|
+
* const dayjsDate = fromApiDate('2023-12-25');
|
|
16
|
+
* console.log(dayjsDate.format('YYYY-MM-DD')); // '2023-12-25'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare function fromApiDate(date: ApiDateOnly): dayjs.Dayjs;
|
|
4
20
|
export declare function fromApiDate(date: ApiDateOnly | undefined): dayjs.Dayjs | undefined;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
import type { ApiDateOnly } from "@leancodepl/api-date";
|
|
3
|
+
/**
|
|
4
|
+
* Converts Day.js object to ApiDateOnly.
|
|
5
|
+
*
|
|
6
|
+
* Formats Day.js object to API date string format with support
|
|
7
|
+
* for optional parameters. Uses Day.js format function internally.
|
|
8
|
+
*
|
|
9
|
+
* @param date - The Day.js object to convert
|
|
10
|
+
* @returns ApiDateOnly string or undefined if date is undefined
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { toApiDate } from '@leancodepl/api-date-dayjs';
|
|
14
|
+
* import dayjs from 'dayjs';
|
|
15
|
+
*
|
|
16
|
+
* const apiDate = toApiDate(dayjs('2023-12-25'));
|
|
17
|
+
* console.log(apiDate); // '2023-12-25'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
3
20
|
export declare function toApiDate(date: dayjs.Dayjs): ApiDateOnly;
|
|
4
21
|
export declare function toApiDate(date: dayjs.Dayjs | undefined): ApiDateOnly | undefined;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
File without changes
|