@item-enonic-types/lib-time 1.2.0 → 1.2.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 +21 -0
- package/package.json +1 -1
- package/util.d.ts +1 -1
package/README.md
CHANGED
|
@@ -107,11 +107,32 @@ const time = today.format(formatter);
|
|
|
107
107
|
// time = "tirsdag 21. februar 2023 12:15:30"
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
*Example of using hte `LanguageRange` utility to find the preferred locale among the ones supported by the application.*
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { LanguageRange, Locale } from "/lib/time";
|
|
114
|
+
import { getSupportedLocales } from "/lib/xp/i18n";
|
|
115
|
+
import type { Request, Response } from "@enonic-types/core";
|
|
116
|
+
|
|
117
|
+
export function get(req: Request): Response {
|
|
118
|
+
const languageRange = LanguageRange.parse(req.headers["Accept-Language"]);
|
|
119
|
+
|
|
120
|
+
const locale: string = Locale.filterTags(
|
|
121
|
+
languageRange,
|
|
122
|
+
getSupportedLocales(["i18n/phrases"])
|
|
123
|
+
)[0];
|
|
124
|
+
|
|
125
|
+
...
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
110
130
|
### Constants exposed from `"/lib/time"`
|
|
111
131
|
The following classes is exposed/exported from `"/lib/time"`:
|
|
112
132
|
* `DateTimeFormatter`
|
|
113
133
|
* `DayOfWeek`
|
|
114
134
|
* `Instant`
|
|
135
|
+
* `LanguageRange`
|
|
115
136
|
* `LocalDate`
|
|
116
137
|
* `LocalDateTime`
|
|
117
138
|
* `Locale`
|
package/package.json
CHANGED
package/util.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface LocaleConstructor {
|
|
|
32
32
|
UNICODE_LOCALE_EXTENSION: Locale;
|
|
33
33
|
US: Locale;
|
|
34
34
|
filter(priorityList: LanguageRange[], locales: Locale[]): Locale[];
|
|
35
|
-
filterTags(priorityList: LanguageRange[], tags: string[]):
|
|
35
|
+
filterTags(priorityList: LanguageRange[], tags: string[]): string[];
|
|
36
36
|
forLanguageTag(languageTag: string): Locale;
|
|
37
37
|
getAvailableLocales(): Locale[];
|
|
38
38
|
getDefault(): Locale;
|