Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(date)!: separate timeZone method #2947

Merged
merged 14 commits into from
Jun 21, 2024
9 changes: 9 additions & 0 deletions docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,15 @@ Now, this throws an error raising awareness of that bad value.

This affects the `refDate` parameter of the `anytime()`, `birthdate()`, `past()`, `future()`, `recent()` and `soon()`, methods as well as the `from` and `to` parameters of `between()` and `betweens()`.

### Separate Timezone Methods

The `timeZone` functionality has been divided to enhance specificity:

- Use `faker.date.timeZone()` to generate a random global time zone.
- Use `faker.location.timeZone()` to obtain time zone specific to the current locale.

We haven't updated all locale dependent time zone data yet, so if you encounter unexpected values, please create a new issue.

### Prices Now Return More Price-Like Values

The `faker.commerce.price()` method now produces values that also return fractional values.
Expand Down
9 changes: 9 additions & 0 deletions src/definitions/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export type DateDefinition = LocaleEntry<{
* The translations for weekdays (Sunday - Saturday).
*/
weekday: DateEntryDefinition;

/**
* The names of the IANA time zones. Not tied to the current locale.
*
* Since this is the same for all locales, it is only defined in the `base` locale.
*
* @see [IANA Time Zone Database](https://www.iana.org/time-zones)
*/
time_zone: string[];
}>;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/definitions/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export type LocationDefinition = LocaleEntry<{
secondary_address: string[];

/**
* A list of timezones names.
* A list of time zones names relevant to this locale.
*
* @see [IANA Time Zone Database](https://www.iana.org/time-zones)
*/
time_zone: string[];
}>;
12 changes: 12 additions & 0 deletions src/locales/base/date/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { DateDefinition } from '../../..';
import time_zone from './time_zone';

const date: DateDefinition = {
time_zone,
};

export default date;
Loading