1

How can the DAAppearance Time from the Disk​Arbitration be converted to a valid Timestamp?

I tried the following:

  if let appearanceTime = diskinfo["DAAppearanceTime"] as? NSNumber{
                            print(appearanceTime)
                            let date = NSDate(timeIntervalSince1970: TimeInterval(appearanceTime))
                            print(date)                             
                        }

I get the correct DAAppearanceTime back from the function but the wrong Year after the conversion:

511348742.912949

1986-03-16 09:19:02 +0000

nja
  • 571
  • 1
  • 7
  • 15
  • You are getting correct date for timestamp `511348742.912949` you can confirm it here http://www.onlineconversion.com/unix_time.htm – Nirav D Mar 16 '17 at 10:02
  • So that means that the DiskArbitration is providing false numbers? The time is correct but my USB stick is not connected since 1986 – nja Mar 16 '17 at 10:03

1 Answers1

2

The "DAAppearanceTime" key is not officially documented, but the DiskArbitration framework is open source.

DAInternal.c:

 const CFStringRef kDADiskDescriptionAppearanceTimeKey  = CFSTR( "DAAppearanceTime"  );

DADisk.c:

/*
 * Create the disk description -- appearance time.
 */

time = CFAbsoluteTimeGetCurrent( );

object = CFNumberCreate( allocator, kCFNumberDoubleType, &time );
if ( object == NULL )  goto DADiskCreateFromIOMediaErr;

CFDictionarySetValue( disk->_description, kDADiskDescriptionAppearanceTimeKey, object );
CFRelease( object );

So the value of that key is what CFAbsoluteTimeGetCurrent() returns, and that is the

Absolute time is measured in seconds relative to the absolute reference date of Jan 1 2001 00:00:00 GMT.

You convert it to a Date like this:

if let time = diskinfo["DAAppearanceTime"] as? Double {
    let date = Date(timeIntervalSinceReferenceDate: time)
    print(date)
}

For the value 511348742.912949 this results in the date 2017-03-16 09:19:02 +0000.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382