Skip to content

Commit

Permalink
feat(date)!: separate timeZone method (#2947)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Jun 21, 2024
1 parent 5801cc5 commit d6924f7
Show file tree
Hide file tree
Showing 13 changed files with 560 additions and 426 deletions.
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

0 comments on commit d6924f7

Please sign in to comment.