4 Replies
      Latest reply: Oct 19, 2016 3:32 PM by cob8000 RSS
      cob8000 Level 1 Level 1 (0 points)

        With `NSTimeZone` we could change the apps time zone with `setDefaultTimeZone` and run UI tests under various time zones.

        With the Swift 3's `TimeZone` struct there's no equivalent functionality that I can see. 


        Any ideas on how we can continue testing our Swift 3 app under various time zones?

        • Re: setDefaultTimeZone equivalent for testing
          eskimo Apple Staff Apple Staff (6,775 points)

          With the Swift 3's TimeZone struct there's no equivalent functionality that I can see.

          The following is the logical equivalent of -setDefaultTimeZone: and it certainly compiles in Xcode 8:

          import Foundation
          
          NSTimeZone.default = NSTimeZone(forSecondsFromGMT: 0) as TimeZone
          

          However, I’m not sure it’ll do what you need it to do.  Please try it out in your environment and let us know how you get along.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: setDefaultTimeZone equivalent for testing
              cob8000 Level 1 Level 1 (0 points)

              Thanks eskimo, it worked . At least for now under Xcode 8. 


              Also directly instantiating a TimeZone and setting NSTimeZone.default to it, also works as expected.

               

              Removing the setDefaultTimeZone method makes sense (in a normal running app it's an odd thing to do), but there should be something to still allow testing (more properly in the test setup than in TimeZone).

                • Re: setDefaultTimeZone equivalent for testing
                  eskimo Apple Staff Apple Staff (6,775 points)

                  it worked

                  Yay!

                  Removing the setDefaultTimeZone method makes sense (in a normal running app it's an odd thing to do)

                  Agreed.

                  but there should be something to still allow testing

                  Agreed.

                  (more properly in the test setup than in TimeZone).

                  Agreed.  I think this would make a fine enhancement request for XCTest.  If you do file a bug, please post your bug number, just for the record.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"