Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 1.19 KB

ConsistentTimeZones.md

File metadata and controls

30 lines (22 loc) · 1.19 KB

How to have consistent time zones

Contents

Problem Description

When running tests on multiple machines and CI systems distributed around the globe, the system's time zone can cause inconsistencies in test results.

Solution: Using WithTimeZone

ApprovalTests provides a convenience class, WithTimeZone, to set a consistent time zone for a block of code. This ensures that all code within the block uses the same time zone, avoiding inconsistencies caused by different system time zones.

Here is an example:

try (WithTimeZone tz = new WithTimeZone("UTC"))
{
  // All code within this block will see the computer as being in the UTC time zone
}
// The computer's time zone will revert to previous setting here

snippet source | anchor