Skip to content

Instantly share code, notes, and snippets.

@doyle
Created February 18, 2014 02:05
Show Gist options
  • Save doyle/9063247 to your computer and use it in GitHub Desktop.
Save doyle/9063247 to your computer and use it in GitHub Desktop.
Convert a NSAppleEventDescriptor to a NSDate
// Inspired by StefanK http://macscripter.net/profile.php?id=14351
- (NSDate *)dateFromEventDescriptor:(NSAppleEventDescriptor *)descriptor
{
NSDate *resultDate = nil;
OSStatus status;
CFAbsoluteTime absoluteTime;
LongDateTime longDateTime;
if ([descriptor descriptorType] == typeLongDateTime) {
[[descriptor data] getBytes:&longDateTime length:sizeof(longDateTime)];
status = UCConvertLongDateTimeToCFAbsoluteTime(longDateTime, &absoluteTime);
if (status == noErr) {
resultDate = [NSDate dateWithTimeIntervalSinceReferenceDate:absoluteTime];
}
}
return resultDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment