Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-jokes-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@item-enonic-types/lib-time": patch
---

Fix return type of `Locale.filterTags` from `Locale` to the correct `string`.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,32 @@ const time = today.format(formatter);
// time = "tirsdag 21. februar 2023 12:15:30"
```

*Example of using hte `LanguageRange` utility to find the preferred locale among the ones supported by the application.*

```typescript
import { LanguageRange, Locale } from "/lib/time";
import { getSupportedLocales } from "/lib/xp/i18n";
import type { Request, Response } from "@enonic-types/core";

export function get(req: Request): Response {
const languageRange = LanguageRange.parse(req.headers["Accept-Language"]);

const locale: string = Locale.filterTags(
languageRange,
getSupportedLocales(["i18n/phrases"])
)[0];

...
}

```

### Constants exposed from `"/lib/time"`
The following classes is exposed/exported from `"/lib/time"`:
* `DateTimeFormatter`
* `DayOfWeek`
* `Instant`
* `LanguageRange`
* `LocalDate`
* `LocalDateTime`
* `Locale`
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lib/time/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface LocaleConstructor {
UNICODE_LOCALE_EXTENSION: Locale;
US: Locale;
filter(priorityList: LanguageRange[], locales: Locale[]): Locale[];
filterTags(priorityList: LanguageRange[], tags: string[]): Locale[];
filterTags(priorityList: LanguageRange[], tags: string[]): string[];
forLanguageTag(languageTag: string): Locale;
getAvailableLocales(): Locale[];
getDefault(): Locale;
Expand Down