Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lldb/source/Plugins/Language/ObjC/Cocoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,22 +1256,28 @@ bool lldb_private::formatters::ObjCSELSummaryProvider(
// this call gives the POSIX equivalent of the Cocoa epoch
time_t lldb_private::formatters::GetOSXEpoch() {
static time_t epoch = 0;
#ifndef _AIX
if (!epoch) {
#if !defined(_WIN32) && !defined(_AIX)
#ifndef _WIN32
tzset();
#endif
tm tm_epoch;
tm_epoch.tm_sec = 0;
tm_epoch.tm_hour = 0;
tm_epoch.tm_min = 0;
tm_epoch.tm_mon = 0;
tm_epoch.tm_hour = 0;
tm_epoch.tm_mday = 1;
tm_epoch.tm_mon = 0;
tm_epoch.tm_year = 2001 - 1900;
tm_epoch.tm_isdst = -1;
#ifdef _WIN32
epoch = _mkgmtime(&tm_epoch);
#else
tm_epoch.tm_gmtoff = 0;
tm_epoch.tm_zone = nullptr;
epoch = timegm(&tm_epoch);
#endif
}
#endif
return epoch;
}

Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ bool lldb_private::formatters::swift::Date_SummaryProvider(

ValueObjectSP time_sp(valobj.GetChildAtNamePath({g__time}));

#ifdef _WIN32
static ConstString g__timeIntervalSinceReferenceDate(
"_timeIntervalSinceReferenceDate");
if (!time_sp)
time_sp = valobj.GetChildAtNamePath(
{g__timeIntervalSinceReferenceDate, "_value"});
#endif

if (!time_sp)
return false;

Expand Down
10 changes: 9 additions & 1 deletion lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,16 @@ LoadFoundationValueTypesFormatters(lldb::TypeCategoryImplSP swift_category_sp) {

lldb_private::formatters::AddCXXSummary(
swift_category_sp, lldb_private::formatters::swift::Date_SummaryProvider,
"Foundation.Date summary provider", ConstString("Foundation.Date"),
"Foundation.Date summary provider",
ConstString("Foundation(Essentials)?\\.Date"),
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true), true);

#ifdef _WIN32
lldb_private::formatters::AddCXXSummary(
swift_category_sp, lldb_private::formatters::swift::Date_SummaryProvider,
"Foundation.NSDate summary provider", ConstString("Foundation.NSDate"),
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true));
#endif

lldb_private::formatters::AddCXXSummary(
swift_category_sp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Test Foundation.Date summary strings.
"""

import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil

import sys


class TestCase(TestBase):
@swiftTest
def test_swift_date_formatters(self):
"""Test Date summary strings."""
self.build()

_ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)

self.expect(
"v date",
startstr="(Foundation.Date) date = 1999-11-05 23:17:00 UTC",
)

if sys.platform != "win32":
return

self.expect(
"v nsdate",
startstr="(Foundation.NSDate) date = 1999-11-05 23:17:00 UTC",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

let paris = TimeZone(identifier: "Europe/Paris")!

var comps = DateComponents()
comps.year = 1999
comps.month = 11
comps.day = 6
comps.hour = 0
comps.minute = 17
comps.timeZone = paris

let date = Calendar(identifier: .gregorian).date(from: comps)!
let nsdate = date as NSDate

print("break here")