@item-enonic-types/lib-time 0.1.2 → 1.0.2

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 CHANGED
@@ -19,7 +19,7 @@ repositories {
19
19
  }
20
20
 
21
21
  dependencies {
22
- include "no.item:lib-xp-time:0.1.0"
22
+ include "no.item:lib-xp-time:1.0.0"
23
23
  }
24
24
  ```
25
25
 
@@ -54,9 +54,11 @@ You can import `java.time` and `java.time.format` classes from `"/lib/time"`.
54
54
  import { LocalDateTime, DateTimeFormatter } from "/lib/time";
55
55
 
56
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"
57
+ const formatter = DateTimeFormatter.ofPattern("dd.MM hh:mm")
58
+ const inThreeWeeksStr = today
59
+ .plusWeeks(3)
60
+ .format(formatter);
61
+ // inThreeWeeksStr = "14.03 12:15"
60
62
  ```
61
63
 
62
64
  *Example of doing time math using a `ZonedDateTime`:*
@@ -75,13 +77,35 @@ const time = fiftyMinutesAgo.toLocalTime();
75
77
  ```typescript
76
78
  import { formatDate } from "/lib/time";
77
79
 
78
- const today = t.formatDate({
80
+ const today = formatDate({
79
81
  date: "2023-02-21",
80
82
  pattern: "dd-MM-yyyy",
81
83
  locale: "no"
82
84
  });
83
85
  // today = "21-02-2023"
84
86
  ```
87
+ *Use `formatDate()` with a given timezoneId*
88
+ ```typescript
89
+ import { formatDate } from "/lib/time";
90
+
91
+ const today = formatDate({
92
+ date: "2023-02-21",
93
+ pattern: "dd-MM-yyyy",
94
+ locale: "no",
95
+ timezoneId: "Europe/Oslo"
96
+ });
97
+ // today = "21-02-2023"
98
+ ```
99
+
100
+ *Example of using `Locale` in formatting a `LocalDateTime` and get a normalized timestamp :*
101
+ ```typescript
102
+ import { LocalDateTime, DateTimeFormatter, Locale } from "/lib/time";
103
+
104
+ const today = LocalDateTime.parse("2023-02-21T12:15:30");
105
+ const formatter = DateTimeFormatter.ofPattern("EEEE d. MMMM yyyy hh:mm:ss", new Locale("no"));
106
+ const time = today.format(formatter);
107
+ // time = "tirsdag 21. februar 2023 12:15:30"
108
+ ```
85
109
 
86
110
  ### Constants exposed from `"/lib/time"`
87
111
  The following classes is exposed/exported from `"/lib/time"`:
package/day-of-week.d.ts CHANGED
@@ -6,8 +6,12 @@ export declare const DayOfWeek: DayOfWeekConstructor;
6
6
  export type WeekDayNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7;
7
7
  export interface DayOfWeekConstructor {
8
8
  of(dayOfWeek: WeekDayNumber): DayOfWeek;
9
+ valueOf(name: string): DayOfWeek;
10
+ values(): DayOfWeek[];
9
11
  }
10
12
  export interface DayOfWeek {
11
13
  getValue(): WeekDayNumber;
14
+ minus(days: number): DayOfWeek;
15
+ plus(days: number): DayOfWeek;
12
16
  toString(): string;
13
17
  }
package/index.d.ts CHANGED
@@ -19,15 +19,17 @@ export { ZoneOffset } from "/lib/time/zone-offset";
19
19
  * @param pattern The shape of the output string
20
20
  * @param locale The locale of the country you are formatting to
21
21
  */
22
- export declare function formatDate({ date, pattern, locale }: FormatDateParams): string;
23
- export declare function formatDate({ date, pattern, locale }: FormatDateParamsAllowNullable): string | undefined;
22
+ export declare function formatDate({ date, pattern, locale, timezoneId }: FormatDateParams): string;
23
+ export declare function formatDate({ date, pattern, locale, timezoneId }: FormatDateParamsAllowNullable): string | undefined;
24
24
  export interface FormatDateParams {
25
25
  date: string | Date;
26
26
  pattern: string;
27
27
  locale?: string | undefined;
28
+ timezoneId?: string | undefined;
28
29
  }
29
30
  export interface FormatDateParamsAllowNullable {
30
31
  date: string | Date | undefined | null;
31
32
  pattern: string;
32
33
  locale?: string | undefined;
34
+ timezoneId?: string | undefined;
33
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@item-enonic-types/lib-time",
3
- "version": "0.1.2",
3
+ "version": "1.0.2",
4
4
  "description": "Type definitions for lib-time",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -14,7 +14,7 @@
14
14
  "dist:server": "cross-env NODE_ENV=production webpack --config webpack.server.config.js --color",
15
15
  "dist": "run-p -c dist:*",
16
16
  "lint": "eslint --fix 'src/**/*.ts'",
17
- "prepublishOnly": "tsc --declarationDir build/types --emitDeclarationOnly true --declaration true && cp -r ./build/types/* .",
17
+ "prepublishOnly": "tsc --declarationDir build/types --emitDeclarationOnly true --declaration true && cp -r ./build/types/src/main/resources/lib/time/* .",
18
18
  "postpublish": "rm ./*.d.ts && rm -r ./format"
19
19
  },
20
20
  "devDependencies": {
package/tsconfig.json CHANGED
@@ -17,9 +17,6 @@
17
17
  "declaration": true,
18
18
  "declarationDir": "build/types"
19
19
  },
20
- "include": [
21
- "./src/main/resources/**/*"
22
- ],
23
20
  "exclude": [
24
21
  "./build/*",
25
22
  ],