xamarin-macios/tests/monotouch-test
Rolf Bjarne Kvinge e4c940cdb8
[Foundation] Fix NSDate's explicit conversion operators with DateTime. (#16872)
We recently tried to fix NSDate's conversion operators with DateTime
(3c65ab1756), but unfortunately a corner case
was missed.

The new approach in the above-mentioned commit would get the individual
date/time components for a given date and use the appropriate constructor for
the other type to re-construct the date/time in question.

However, one case was missed: when converting from NSDate to DateTime, we'd
get a fractional number of milliseconds. This fractional number could be
something like 999.99 milliseconds, and when converting that to the int the
DateTime constructor expected for the number of milliseconds, then DateTime
would throw an exception, because the number of milliseconds could only be
between 0 and 999.

I've solved this by not using floating-point math in the computations. We're
now getting the number of nanoseconds from the NSDate (which is a natural
number, and represents the total number of nanoseconds less than a whole
second), and then converting that to the number of milliseconds, microseconds
and ticks that can be used with DateTime using integral math. Unfortunately
DateTime doesn't have a constructor that takes the remaining number of ticks
after all the other fields have been provided, but that can be added
afterwards.

I've also made a few other improvements:

* Improve the validation for the NSDate -> DateTime conversion to detect BC
  dates by using the NSDate's Era component (to throw because DateTime only
  supports AC dates). Also don't allow a tick later than year 10.000 (DateTime
  only supports up to a tick before year 10.000) - but explicitly support
  exactly year 10.000, and convert it to DateTime.MaxValue (this is because
  due to precision errors NSDate can't actually express 'a tick before year
  10.000', it ends up being rounded up to year 10.000 exactly). This means
  there are no more magical values in the range validation checks.
* Increase precision in the DateTime -> NSDate conversion by starting with the
  sub-second amount of ticks from the DateTime instance (instead of the number
  of milliseconds). This allows us to compute the nanoseconds NSDate expects
  with much higher precision.
* More tests!

Fixes this test:

    MonoTouchFixtures.Foundation.DateTest.DateTimeToNSDate : 2 ms
        [FAIL] Precision32022 : System.ArgumentOutOfRangeException : Valid values are between 0 and 999, inclusive.
            Parameter name: millisecond
            at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day, System.Int32 hour, System.Int32 minute, System.Int32 second, System.Int32 millisecond, System.DateTimeKind kind) [0x0002d] in <4d40c65adfc14d7fb19bad9310f3eb2a>:0
            at Foundation.NSDate.op_Explicit (Foundation.NSDate d) [0x000b8] in <9cb1e1018c034b75ba5f4ed7b83ba2f2>:0
            at MonoTouchFixtures.Foundation.DateTest.Precision32022 () [0x0000c] in <c44b5df5f7b84b69b737e9fd61bddaed>:0
            at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
            at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <4d40c65adfc14d7fb19bad9310f3eb2a>:0

Fixes https://github.com/xamarin/maccore/issues/2632.

Date and time is difficult.

Ref: https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca
Ref: the rest of internet...
2022-11-23 07:55:22 +01:00
..
ARKit [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
AVFoundation [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
AVKit [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
AVRouting [AVKit and AVRouting] Updates for Xcode14 Beta3 (#15811) 2022-09-08 15:13:15 -05:00
Accessibility [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
AdSupport [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
AddressBook [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
AddressBookUI [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
AppKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Assets.xcassets/AppIcons.appiconset [tests] Import 2016-05-26 15:06:52 +02:00
AudioToolbox [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
AudioUnit [autoformat] Autoformat after a PR race. (#16720) 2022-11-14 08:43:39 +01:00
AuthenticationServices [AuthenticationServices] Updates for Xcode13 Beta3 (#12203) 2021-08-04 10:11:26 -04:00
BackgroundTasks [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CarPlay [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
ClockKit [ClockKit] Add support for Xcode 12 beta 1. (#9010) 2020-07-14 11:12:26 -04:00
CloudKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Compression [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Contacts [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreAnimation [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreAudioKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreBluetooth [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreData [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreFoundation [DevOps] Do not use ta vm for the pkgs upload due to its hdd size. (#16765) 2022-11-15 18:15:36 -05:00
CoreGraphics [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreImage [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreLocation [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
CoreML [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreMedia [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreMidi [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreServices [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreText [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreVideo [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
CoreWlan Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
Darwin [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
EventKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
ExternalAccessory [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
FileProvider [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Foundation [Foundation] Fix NSDate's explicit conversion operators with DateTime. (#16872) 2022-11-23 07:55:22 +01:00
GLKit [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
GameController [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
GameKit [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
GameplayKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
HealthKit [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
HomeKit [autoformat] Add .NET tests. (#16811) 2022-11-21 09:45:49 +01:00
HttpClient [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
ImageIO [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Intents Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
JavascriptCore [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MLCompute [dotnet] Remove Runtime.Arch and ObjCRuntime.Arch from Mac Catalyst. Fixes #10312. (#13562) 2021-12-15 22:32:14 +01:00
MapKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MediaAccessibility [tests] Adjust ImageCaptioningTest to skip network-related failures in CI. (#16814) 2022-11-21 20:55:49 +01:00
MediaPlayer [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MediaToolbox [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MessageUI [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
Messages [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
Metal [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MetalPerformanceShaders [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
MetricKit Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
MobileCoreServices [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
ModelIO [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MonoMac [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
MultipeerConnectivity [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
NaturalLanguage [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
NearbyInteraction [NearbyInteraction] Updates for Xcode14 Beta 1 (#15840) 2022-09-06 16:11:52 -04:00
Network [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
NetworkExtension [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
ObjCRuntime [tests] Ignore SWCollaborationView in DelegateAndSourceTest. (#16777) 2022-11-18 08:02:42 +01:00
OpenGL [tests] Preserve all test fixtures. (#10870) 2021-03-16 15:15:30 +01:00
OpenGLES Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
PassKit [tests] Ignore PassLibraryTest.PassLibraryTest on bots if PKPassLibrary.GetPasses returns null. Fixes #xamarin/maccore@2598. (#16738) 2022-11-16 07:54:57 +01:00
PdfKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Phase [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Photos [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
PushKit [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
QuickLook [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
ReplayKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Resources [xcode12] [ImageIO] Update bindings for Xcode11 (#8942) 2020-06-25 15:28:29 -04:00
SafariServices [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
SceneKit [autoformat] Add the Security, SensorKit, Social, SpriteKit, StoreKit, SystemConfiguration, TVServices, VideoToolbox, Vision and WKWebKit frameworks. (#16763) 2022-11-16 07:38:18 +01:00
ScriptingBridge [ScriptingBridge] Improve API and add nullability. (#13787) 2022-01-19 20:52:18 +01:00
SearchKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Security [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
SharedWithYouCore [SharedWithYouCore] Added support for Xcode 14.1 b3 (#16198) 2022-10-12 12:09:00 -04:00
Simd [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
SpriteKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
StoreKit [tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350) 2021-11-15 08:06:36 +01:00
System.Net.Http [tests] Adjust TestNSurlSessionHandlerCookieContainer* tests to not fail in CI in case of network problems. Fixes #2197. (#16817) 2022-11-23 07:54:04 +01:00
SystemConfiguration [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
UIKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
UniformTypeIdentifiers [monotouch-test] Ignore a few tests in non-ARM64 simulators. (#13487) 2021-12-07 21:10:39 +01:00
UserNotifications [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
VideoToolbox [tests] Adjust MonoTouchFixtures.VideoToolbox.VTCompressionSessionTests.TestCallback to ignore timeouts in CI. (#16816) 2022-11-21 09:37:08 +01:00
Vision [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
WebKit [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
dotnet [dotnet] Make it possible to specify the registrar using a 'Registrar' property in MSBuild. (#15483) 2022-08-18 17:21:48 +02:00
mono [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
.gitignore Make our local .NET the default .NET for the build. (#15086) 2022-06-07 10:11:02 +02:00
AppDelegate.cs [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Asserts.cs [Foundation] Fix NSDate's explicit conversion operators with DateTime. (#16872) 2022-11-23 07:55:22 +01:00
AssertsMac.cs [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
BoardingPass.pkpass [tests] Import 2016-05-26 15:06:52 +02:00
EmptyNib.xib [tests] Import 2016-05-26 15:06:52 +02:00
Entitlements.plist [Network] Partial bindings of Network for Xcode 12 beta 6. (#9623) 2020-09-28 18:22:42 -04:00
Hand.wav [tests] Import 2016-05-26 15:06:52 +02:00
Info.plist Bump the minimum iOS version to 7.0. Fixes #6213. (#6878) 2019-08-30 01:07:30 -07:00
LL-171A-B-B797E457-16AB-C708-1E0F-32C19DBD47B5.icc [tests] Import 2016-05-26 15:06:52 +02:00
LaunchScreen.storyboard [tests] Import 2016-05-26 15:06:52 +02:00
Main.cs [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Makefile [tests] Import 2016-05-26 15:06:52 +02:00
Model3.arobject [arkit] Update to Xcode 10 beta 3 (#4406) 2018-07-05 22:36:33 -04:00
NativeTypesTest.cs [autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Pacifico.ttf [tests] Import 2016-05-26 15:06:52 +02:00
Tamarin.pdf [tests] Import 2016-05-26 15:06:52 +02:00
access-denied.html [wkwebkit] Update for Xcode 11 beta 3 (#6496) 2019-07-04 13:08:21 -04:00
access-granted.html [wkwebkit] Update for Xcode 11 beta 3 (#6496) 2019-07-04 13:08:21 -04:00
app.config [monotouch-test] Add test to ensure config files are properly bundled in apps. (#1291) 2016-12-02 14:13:25 +01:00
basn3p08.png [tests] Import 2016-05-26 15:06:52 +02:00
compressed_lz4 [Compression] Add compression framework bindings. (#3942) 2018-05-11 15:54:31 -04:00
compressed_lze [Compression] Add compression framework bindings. (#3942) 2018-05-11 15:54:31 -04:00
compressed_lzma [Compression] Add compression framework bindings. (#3942) 2018-05-11 15:54:31 -04:00
compressed_zip [Compression] Add compression framework bindings. (#3942) 2018-05-11 15:54:31 -04:00
drum01.mp3 [tests] Import 2016-05-26 15:06:52 +02:00
example.pac [Tests] Update xamarin domain to make tests not fail. (#11408) 2021-05-02 20:11:16 -04:00
monotouch-test.csproj [SharedWithYouCore] Added support for Xcode 14.1 b3 (#16198) 2022-10-12 12:09:00 -04:00
uncompressed.txt [Compression] Add compression framework bindings. (#3942) 2018-05-11 15:54:31 -04:00
xamvideotest.mp4 [tests] Import 2016-05-26 15:06:52 +02:00