From d6924f7fbb9403d106022f58a1bda3b159e88ae6 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 21 Jun 2024 11:44:57 +0200 Subject: feat(date)!: separate timeZone method (#2947) --- src/modules/date/index.ts | 19 +++++++++++++++++++ src/modules/location/index.ts | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index 10196d6e..f2eac1cf 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -685,4 +685,23 @@ export class DateModule extends SimpleDateModule { assertLocaleData(values, 'date.weekday', type); return this.faker.helpers.arrayElement(values); } + + /** + * Returns a random IANA time zone name. + * + * The returned time zone is not tied to the current locale. + * + * @see [IANA Time Zone Database](https://www.iana.org/time-zones) + * @see faker.location.timeZone(): For generating a timezone based on the current locale. + * + * @example + * faker.location.timeZone() // 'Pacific/Guam' + * + * @since 9.0.0 + */ + timeZone(): string { + return this.faker.helpers.arrayElement( + this.faker.definitions.date.time_zone + ); + } } diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 8fbbbe30..d55e0c8a 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -596,7 +596,12 @@ export class LocationModule extends ModuleBase { } /** - * Returns a random time zone. + * Returns a random IANA time zone relevant to this locale. + * + * The returned time zone is tied to the current locale. + * + * @see [IANA Time Zone Database](https://www.iana.org/time-zones) + * @see faker.date.timeZone(): For generating a random time zone from all available time zones. * * @example * faker.location.timeZone() // 'Pacific/Guam' -- cgit v1.2.3