jimwan jimwan -4 years ago 145
Objective-C Question

How to get the date from a 5 digit number

From my code, i get manufacture date as below:

.....
- (NSDictionary *)getBatteryInfo
{
matching = IOServiceNameMatching("AppleSmartBattery");
entry = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
IORegistryEntryCreateCFProperties(entry, &properties, NULL, 0);
return (__bridge NSDictionary *)properties;
}
......

NSDictionary *Info = [self getBatteryInfo];

NSNumber *manufacturerDate = [Info objectForKey:@"ManufactureDate"];


I tried these codes in a macbook and get 17492 for the date, and I also check the date with a app installed from App store and know the exact date is 2014/02/20.

In another macbook, i get 16727 for the date, and the exact date is 2012/10/23.
Who can tell me how to calculate the exact date with this 5 digit number.

Answer Source

Date is published in a bitfield per the Smart Battery Data spec rev 1.1 in section 5.1.26 (see)

  • Bits 0...4 => day (value 1-31; 5 bits)
  • Bits 5...8 => month (value 1-12; 4 bits)
  • Bits 9...15 => years since 1980 (value 0-127; 7 bits)

UPD. Example

17492 is in binary notation 0100010001010100 (unsigned interpretation for 16-bit number). So,

  • Bits 0...4 => 10100 => 20 day
  • Bits 5...8 => 0010 => 2 month
  • Bits 9...15 => 34 + 1980 = 2014 year

Thus, we've got that 17492 is 2014/02/20

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download