smart-on-fhir / Swift-SMART

Swift SMART on FHIR framework for iOS and OS X
Other
135 stars 47 forks source link

DateTime wrapper rounds to nearest second #35

Open sjanic opened 4 years ago

sjanic commented 4 years ago

Given this example

func testExample() throws {
  let start = DateTime(
    date: FHIRDate(string: "1990-08-17")!,
    time: FHIRTime(hour: 12, minute: 8, second: 20.99999),
    timeZone: TimeZone.current
  )
  print("Start date as json: \(start.description)")
  print("Start date as NSDate: \(start.nsDate)")
}

I get the following output

Start date as json: 1990-08-17T12:08:21+02:00
Start date as NSDate: 1990-08-17 10:08:20 +0000

I'm wondering why the DateTime rounds up to the nearest second (it has a precision of 4 decimals of milliseconds), when the NSDate doesn't. Is this an issue (it could potentially mean that something happen a second earlier/later then expected)?

I'm using Swift-SMART version 4.2.0