bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.62k stars 491 forks source link

Generate random Timezone IDs #437

Open developervariety opened 1 year ago

developervariety commented 1 year ago

Please describe why you are requesting a feature

It would go well with random locale.

Please provide a code example of what you are trying to achieve


var faker = new Bogus.Faker();
faker.Random.RandomTimezoneId();

Expected output: "America/Argentina/San_Juan"

A list of timezone IDs I've found: https://raw.githubusercontent.com/mattjohnsonpint/TimeZoneNames/main/src/TimeZoneNames.DataBuilder/data/zone-precedence.txt

If the feature request is approved, would you be willing to submit a PR? No

bchavez commented 4 months ago

Some options for this:

using NodaTime;

void Main()
{
   var faker = new Faker();
   var timezones = DateTimeZoneProviders.Tzdb.Ids.ToArray();
   var randomTimezones = Enumerable.Range(1, 10)
       .Select(_ => faker.PickRandom(timezones));
   randomTimezones.Dump();
}

image