nickdodd79 / AutoBogus

A C# library complementing the Bogus generator by adding auto creation and population capabilities.
MIT License
423 stars 49 forks source link

Custom timezone for DateTime #66

Closed mnifakram closed 3 years ago

mnifakram commented 3 years ago

Hello,

Is there any way that you can customize Generation of all DateTime properties across all models? In my case I want to set the time zone to UniversalTime, I can also see the benefit of this if someone is using Noda.

Thanks

nickdodd79 commented 3 years ago

Hey @mnifakram

Thanks for your question.

The only options available for controlling how DateTime values are generated are:

  1. Check out the Bogus configuration options. I believe there are some static properties you set, but these may not cover what you need.
  2. Implement your own override for the DateTime type and provide the logic you need. You can find details on overrides int he read me (https://github.com/nickdodd79/AutoBogus#overrides).

Nick.

mnifakram commented 3 years ago

Thank you so much @nickdodd79, the easiest way that I found for the moment is to configure Date class in Bogus

Date.SystemClock = () => DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified);