diff --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp --- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp +++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp @@ -867,7 +867,7 @@ // is generally true and POSIXly happy, but might break if a library vendor // decides to get creative time_t epoch = GetOSXEpoch(); - epoch = epoch + (time_t)date_value; + epoch = epoch + static_cast(std::floor(date_value)); tm *tm_date = gmtime(&epoch); if (!tm_date) return false; diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py b/lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py --- a/lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSDate.py @@ -43,6 +43,15 @@ self.expect('frame variable date4_abs', substrs=['1970']) self.expect('frame variable date5_abs', substrs=[now_year]) + # Check that LLDB always follow's NSDate's rounding behavior (which + # is always rounding down). + self.expect_expr("date_1970_minus_06", result_summary="1969-12-31 23:59:59 UTC") + self.expect_expr("date_1970_minus_05", result_summary="1969-12-31 23:59:59 UTC") + self.expect_expr("date_1970_minus_04", result_summary="1969-12-31 23:59:59 UTC") + self.expect_expr("date_1970_plus_06", result_summary="1970-01-01 00:00:00 UTC") + self.expect_expr("date_1970_plus_05", result_summary="1970-01-01 00:00:00 UTC") + self.expect_expr("date_1970_plus_04", result_summary="1970-01-01 00:00:00 UTC") + self.expect('frame variable cupertino home europe', substrs=['@"America/Los_Angeles"', '@"Europe/Rome"', diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-objc/main.m b/lldb/test/API/functionalities/data-formatter/data-formatter-objc/main.m --- a/lldb/test/API/functionalities/data-formatter/data-formatter-objc/main.m +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-objc/main.m @@ -655,6 +655,14 @@ [NSDate dateWithTimeIntervalSinceReferenceDate: floor([[NSDate date] timeIntervalSinceReferenceDate])]; + NSDate *date_1970_minus_06 = [NSDate dateWithTimeIntervalSince1970:-0.6]; + NSDate *date_1970_minus_05 = [NSDate dateWithTimeIntervalSince1970:-0.5]; + NSDate *date_1970_minus_04 = [NSDate dateWithTimeIntervalSince1970:-0.4]; + + NSDate *date_1970_plus_06 = [NSDate dateWithTimeIntervalSince1970:0.6]; + NSDate *date_1970_plus_05 = [NSDate dateWithTimeIntervalSince1970:0.5]; + NSDate *date_1970_plus_04 = [NSDate dateWithTimeIntervalSince1970:0.4]; + CFAbsoluteTime date1_abs = CFDateGetAbsoluteTime(date1); CFAbsoluteTime date2_abs = CFDateGetAbsoluteTime(date2); CFAbsoluteTime date3_abs = CFDateGetAbsoluteTime(date3);