@item-enonic-types/lib-time 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Item Consulting AS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # Time library for Enonic XP
2
+
3
+ This library enables the usage of classes from the [`java.time`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/package-summary.html) package from Enonic XP application code.
4
+ Other JavaScript-based time libraries like _Moment.js_ or _date-fns_ will negatively impact your bundle size and build time. This library is only a **thin TypeScript-wrapper** around the excellent core `java.time` library already present in your system!
5
+
6
+ [![](https://jitpack.io/v/no.item/lib-xp-time.svg)](https://jitpack.io/#no.item/lib-xp-time)
7
+
8
+ <img src="https://github.com/ItemConsulting/lib-xp-time/raw/main/docs/icon.svg?sanitize=true" width="150">
9
+
10
+ ## Installation
11
+
12
+ To install this library you need to add a new dependency to your app's build.gradle file.
13
+
14
+ ### Gradle
15
+
16
+ ```groovy
17
+ repositories {
18
+ maven { url 'https://jitpack.io' }
19
+ }
20
+
21
+ dependencies {
22
+ include "no.item:lib-xp-time:0.1.0"
23
+ }
24
+ ```
25
+
26
+ ### TypeScript
27
+
28
+ To update the version of *enonic-types* in *package.json* using npm, run the following command:
29
+ ```bash
30
+ npm install --save-dev @item-enonic-types/lib-time
31
+ ```
32
+
33
+ You can add the following changes to your *tsconfig.json* to get TypeScript-support.
34
+
35
+ ```diff
36
+ {
37
+ "compilerOptions": {
38
+ + "baseUrl": "./",
39
+ + "paths": {
40
+ + "/lib/xp/*": ["./node_modules/@enonic-types/lib-*"],
41
+ + "/lib/*": [ "./node_modules/@item-enonic-types/lib-*" ,"./src/main/resources/lib/*"],
42
+ + }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### Usage
48
+
49
+ You can import `java.time` and `java.time.format` classes from `"/lib/time"`.
50
+
51
+ *Example of date math on a `LocalDateTime` using `"/lib/time"`:*
52
+
53
+ ```typescript
54
+ import { LocalDateTime, DateTimeFormatter } from "/lib/time";
55
+
56
+ const today = LocalDateTime.parse("2023-02-21T12:15:30");
57
+ const inThreeWeeks = today.plusWeeks(3);
58
+ const dateStr = inThreeWeeks.format(DateTimeFormatter.ofPattern("dd-MM-yyyy hh:mm:ss"));
59
+ // dateStr = "14-03-2023 12:15:30"
60
+ ```
61
+
62
+ *Example of doing time math using a `ZonedDateTime`:*
63
+
64
+ ```typescript
65
+ import { ZonedDateTime } from "/lib/time";
66
+
67
+ const date = ZonedDateTime.parse("2023-02-21T12:15:30+01:00");
68
+ const fiftyMinutesAgo = date.minusMinutes(50);
69
+ const time = fiftyMinutesAgo.toLocalTime();
70
+ // time = "11:25:30"
71
+ ```
72
+
73
+ *This library also exposes a utility function `formatDate()` to simply format a date:*
74
+
75
+ ```typescript
76
+ import { formatDate } from "/lib/time";
77
+
78
+ const today = t.formatDate({
79
+ date: "2023-02-21",
80
+ pattern: "dd-MM-yyyy",
81
+ locale: "no"
82
+ });
83
+ // today = "21-02-2023"
84
+ ```
85
+
86
+ ### Constants exposed from `"/lib/time"`
87
+ The following classes is exposed/exported from `"/lib/time"`:
88
+ * `DateTimeFormatter`
89
+ * `DayOfWeek`
90
+ * `Instant`
91
+ * `LocalDate`
92
+ * `LocalDateTime`
93
+ * `Locale`
94
+ * `LocalTime`
95
+ * `Month`
96
+ * `OffsetDateTime`
97
+ * `OffsetTime`
98
+ * `ZonedDateTime`
99
+ * `ZoneId`
100
+ * `ZoneOffset`
101
+
102
+ ### Building
103
+
104
+ To build the project run the following code
105
+
106
+ ```bash
107
+ ./gradlew build
108
+ ```
109
+
110
+ ### Deploy locally
111
+
112
+ Deploy locally for testing purposes:
113
+
114
+ ```bash
115
+ ./gradlew publishToMavenLocal
116
+ ```
117
+ ## Deploy to Jitpack
118
+
119
+ Go to the [Jitpack page for lib-xp-time](https://jitpack.io/#no.item/lib-xp-time) to deploy from GitHub (after
120
+ [creating a new versioned release](https://github.com/ItemConsulting/lib-xp-time/releases/new)).
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const DayOfWeek: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const DateTimeFormatter: any;
package/index.d.ts ADDED
@@ -0,0 +1,225 @@
1
+ declare const _exports: {
2
+ readonly DayOfWeek: any;
3
+ readonly __esModule: boolean;
4
+ readonly LocalDateTime: any;
5
+ readonly ZonedDateTime: any;
6
+ readonly Locale: any;
7
+ readonly DateTimeFormatter: any;
8
+ readonly Instant: any;
9
+ readonly LocalDate: any;
10
+ readonly LocalTime: any;
11
+ readonly Month: any;
12
+ readonly OffsetDateTime: any;
13
+ readonly OffsetTime: any;
14
+ readonly ZoneId: any;
15
+ readonly ZoneOffset: any;
16
+ formatDate: (_a: any) => any;
17
+ } | {
18
+ readonly DateTimeFormatter: any;
19
+ readonly __esModule: boolean;
20
+ readonly DayOfWeek: any;
21
+ readonly LocalDateTime: any;
22
+ readonly ZonedDateTime: any;
23
+ readonly Locale: any;
24
+ readonly Instant: any;
25
+ readonly LocalDate: any;
26
+ readonly LocalTime: any;
27
+ readonly Month: any;
28
+ readonly OffsetDateTime: any;
29
+ readonly OffsetTime: any;
30
+ readonly ZoneId: any;
31
+ readonly ZoneOffset: any;
32
+ formatDate: (_a: any) => any;
33
+ } | {
34
+ readonly Instant: any;
35
+ readonly __esModule: boolean;
36
+ readonly DayOfWeek: any;
37
+ readonly LocalDateTime: any;
38
+ readonly ZonedDateTime: any;
39
+ readonly Locale: any;
40
+ readonly DateTimeFormatter: any;
41
+ readonly LocalDate: any;
42
+ readonly LocalTime: any;
43
+ readonly Month: any;
44
+ readonly OffsetDateTime: any;
45
+ readonly OffsetTime: any;
46
+ readonly ZoneId: any;
47
+ readonly ZoneOffset: any;
48
+ formatDate: (_a: any) => any;
49
+ } | {
50
+ readonly LocalDate: any;
51
+ readonly __esModule: boolean;
52
+ readonly DayOfWeek: any;
53
+ readonly LocalDateTime: any;
54
+ readonly ZonedDateTime: any;
55
+ readonly Locale: any;
56
+ readonly DateTimeFormatter: any;
57
+ readonly Instant: any;
58
+ readonly LocalTime: any;
59
+ readonly Month: any;
60
+ readonly OffsetDateTime: any;
61
+ readonly OffsetTime: any;
62
+ readonly ZoneId: any;
63
+ readonly ZoneOffset: any;
64
+ formatDate: (_a: any) => any;
65
+ } | {
66
+ readonly LocalDateTime: any;
67
+ readonly __esModule: boolean;
68
+ readonly DayOfWeek: any;
69
+ readonly ZonedDateTime: any;
70
+ readonly Locale: any;
71
+ readonly DateTimeFormatter: any;
72
+ readonly Instant: any;
73
+ readonly LocalDate: any;
74
+ readonly LocalTime: any;
75
+ readonly Month: any;
76
+ readonly OffsetDateTime: any;
77
+ readonly OffsetTime: any;
78
+ readonly ZoneId: any;
79
+ readonly ZoneOffset: any;
80
+ formatDate: (_a: any) => any;
81
+ } | {
82
+ readonly LocalTime: any;
83
+ readonly __esModule: boolean;
84
+ readonly DayOfWeek: any;
85
+ readonly LocalDateTime: any;
86
+ readonly ZonedDateTime: any;
87
+ readonly Locale: any;
88
+ readonly DateTimeFormatter: any;
89
+ readonly Instant: any;
90
+ readonly LocalDate: any;
91
+ readonly Month: any;
92
+ readonly OffsetDateTime: any;
93
+ readonly OffsetTime: any;
94
+ readonly ZoneId: any;
95
+ readonly ZoneOffset: any;
96
+ formatDate: (_a: any) => any;
97
+ } | {
98
+ readonly Month: any;
99
+ readonly __esModule: boolean;
100
+ readonly DayOfWeek: any;
101
+ readonly LocalDateTime: any;
102
+ readonly ZonedDateTime: any;
103
+ readonly Locale: any;
104
+ readonly DateTimeFormatter: any;
105
+ readonly Instant: any;
106
+ readonly LocalDate: any;
107
+ readonly LocalTime: any;
108
+ readonly OffsetDateTime: any;
109
+ readonly OffsetTime: any;
110
+ readonly ZoneId: any;
111
+ readonly ZoneOffset: any;
112
+ formatDate: (_a: any) => any;
113
+ } | {
114
+ readonly OffsetDateTime: any;
115
+ readonly __esModule: boolean;
116
+ readonly DayOfWeek: any;
117
+ readonly LocalDateTime: any;
118
+ readonly ZonedDateTime: any;
119
+ readonly Locale: any;
120
+ readonly DateTimeFormatter: any;
121
+ readonly Instant: any;
122
+ readonly LocalDate: any;
123
+ readonly LocalTime: any;
124
+ readonly Month: any;
125
+ readonly OffsetTime: any;
126
+ readonly ZoneId: any;
127
+ readonly ZoneOffset: any;
128
+ formatDate: (_a: any) => any;
129
+ } | {
130
+ readonly OffsetTime: any;
131
+ readonly __esModule: boolean;
132
+ readonly DayOfWeek: any;
133
+ readonly LocalDateTime: any;
134
+ readonly ZonedDateTime: any;
135
+ readonly Locale: any;
136
+ readonly DateTimeFormatter: any;
137
+ readonly Instant: any;
138
+ readonly LocalDate: any;
139
+ readonly LocalTime: any;
140
+ readonly Month: any;
141
+ readonly OffsetDateTime: any;
142
+ readonly ZoneId: any;
143
+ readonly ZoneOffset: any;
144
+ formatDate: (_a: any) => any;
145
+ } | {
146
+ readonly Locale: any;
147
+ readonly __esModule: boolean;
148
+ readonly DayOfWeek: any;
149
+ readonly LocalDateTime: any;
150
+ readonly ZonedDateTime: any;
151
+ readonly DateTimeFormatter: any;
152
+ readonly Instant: any;
153
+ readonly LocalDate: any;
154
+ readonly LocalTime: any;
155
+ readonly Month: any;
156
+ readonly OffsetDateTime: any;
157
+ readonly OffsetTime: any;
158
+ readonly ZoneId: any;
159
+ readonly ZoneOffset: any;
160
+ formatDate: (_a: any) => any;
161
+ } | {
162
+ /***/ readonly ZoneId: any;
163
+ readonly __esModule: boolean;
164
+ readonly DayOfWeek: any;
165
+ readonly LocalDateTime: any;
166
+ readonly ZonedDateTime: any;
167
+ readonly Locale: any;
168
+ readonly DateTimeFormatter: any;
169
+ readonly Instant: any;
170
+ readonly LocalDate: any;
171
+ readonly LocalTime: any;
172
+ readonly Month: any;
173
+ readonly OffsetDateTime: any;
174
+ readonly OffsetTime: any;
175
+ readonly ZoneOffset: any;
176
+ formatDate: (_a: any) => any;
177
+ } | {
178
+ readonly ZoneOffset: any;
179
+ readonly __esModule: boolean;
180
+ readonly DayOfWeek: any;
181
+ readonly LocalDateTime: any;
182
+ readonly ZonedDateTime: any;
183
+ readonly Locale: any;
184
+ readonly DateTimeFormatter: any;
185
+ readonly Instant: any;
186
+ readonly LocalDate: any;
187
+ readonly LocalTime: any;
188
+ readonly Month: any;
189
+ readonly OffsetDateTime: any;
190
+ readonly OffsetTime: any;
191
+ readonly ZoneId: any;
192
+ formatDate: (_a: any) => any;
193
+ } | {
194
+ readonly ZonedDateTime: any;
195
+ readonly __esModule: boolean;
196
+ readonly DayOfWeek: any;
197
+ readonly LocalDateTime: any;
198
+ readonly Locale: any;
199
+ readonly DateTimeFormatter: any;
200
+ readonly Instant: any;
201
+ readonly LocalDate: any;
202
+ readonly LocalTime: any;
203
+ readonly Month: any;
204
+ readonly OffsetDateTime: any;
205
+ readonly OffsetTime: any;
206
+ readonly ZoneId: any;
207
+ readonly ZoneOffset: any;
208
+ formatDate: (_a: any) => any;
209
+ };
210
+ export = _exports;
211
+ export const __esModule: boolean;
212
+ export const DayOfWeek: any;
213
+ export const LocalDateTime: any;
214
+ export const ZonedDateTime: any;
215
+ export const Locale: any;
216
+ export const DateTimeFormatter: any;
217
+ export const Instant: any;
218
+ export const LocalDate: any;
219
+ export const LocalTime: any;
220
+ export const Month: any;
221
+ export const OffsetDateTime: any;
222
+ export const OffsetTime: any;
223
+ export const ZoneId: any;
224
+ export const ZoneOffset: any;
225
+ export function formatDate(_a: any): any;
package/instant.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const Instant: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const LocalDateTime: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const LocalDate: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const LocalTime: any;
package/month.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const Month: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const OffsetDateTime: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const OffsetTime: any;
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@item-enonic-types/lib-time",
3
+ "version": "0.1.1",
4
+ "description": "Type definitions for lib-time",
5
+ "license": "MIT",
6
+ "files": [
7
+ "*.d.ts",
8
+ "format/*.d.ts",
9
+ "tsconfig.json"
10
+ ],
11
+ "scripts": {
12
+ "build:server": "webpack --config webpack.server.config.js --color",
13
+ "build": "run-p -c build:*",
14
+ "dist:server": "cross-env NODE_ENV=production webpack --config webpack.server.config.js --color",
15
+ "dist": "run-p -c dist:*",
16
+ "lint": "eslint --fix 'src/**/*.ts'",
17
+ "prepublishOnly": "tsc --declarationDir build/types --emitDeclarationOnly true --declaration true && cp -r ./build/types/build/resources/main/lib/time/* .",
18
+ "postpublish": "rm ./*.d.ts && rm -r ./format"
19
+ },
20
+ "devDependencies": {
21
+ "@babel/core": "^7.19.6",
22
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
23
+ "@babel/preset-env": "^7.19.4",
24
+ "@babel/register": "^7.18.9",
25
+ "@typescript-eslint/eslint-plugin": "^5.41.0",
26
+ "@typescript-eslint/parser": "^5.41.0",
27
+ "babel-loader": "^8.2.5",
28
+ "browserslist": "^4.21.4",
29
+ "browserslist-config-enonic": "^1.0.7",
30
+ "cross-env": "^7.0.3",
31
+ "eslint": "^8.26.0",
32
+ "eslint-config-prettier": "^8.5.0",
33
+ "eslint-plugin-prettier": "^4.2.1",
34
+ "glob": "^8.0.3",
35
+ "npm-run-all": "^4.1.5",
36
+ "prettier": "^2.7.1",
37
+ "ramda": "^0.28.0",
38
+ "ts-loader": "^9.4.1",
39
+ "typescript": "^4.8.4",
40
+ "webpack": "^5.74.0",
41
+ "webpack-cli": "^4.10.0",
42
+ "@item-enonic-types/lib-testing": "^7.11.3",
43
+ "enonic-types": "^7.11.3"
44
+ },
45
+ "browserslist": [
46
+ "extends browserslist-config-enonic"
47
+ ],
48
+ "engines": {
49
+ "node": ">= 16.13.1",
50
+ "npm": ">= 8.1.2"
51
+ }
52
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "moduleResolution": "node",
5
+ "target": "es5",
6
+ "sourceMap": true,
7
+ "allowJs": true,
8
+ "noImplicitAny": true,
9
+ "noImplicitReturns": true,
10
+ "noImplicitThis": true,
11
+ "strictNullChecks": true,
12
+ "baseUrl": "./",
13
+ "paths": {
14
+ "/lib/xp/*": ["node_modules/@enonic-types/lib-*"],
15
+ "/lib/*": [ "./node_modules/@item-enonic-types/lib-*" ,"./src/main/resources/lib/*"]
16
+ },
17
+ "declaration": true,
18
+ "declarationDir": "build/types"
19
+ },
20
+ "types": [
21
+ "types"
22
+ ]
23
+ }
package/util.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const Locale: any;
package/zone-id.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const ZoneId: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const ZoneOffset: any;
@@ -0,0 +1,2 @@
1
+ export const __esModule: boolean;
2
+ export const ZonedDateTime: any;