1

I am puzzled by the differences underlined in red below:

enter image description here

How come this very same NSDate object is displayed in BST in the debug pane, but in GMT in the LLDB terminal when asked to '"Print description of "date"' ?

This is with Xcode 4.6.1

verec
  • 5,224
  • 5
  • 33
  • 40

2 Answers2

4

An NSDate represents a specific moment in time, without any consideration of what human beings call that moment. If you look at NSDate, you'll notice that there aren't even hour, minute, or second properties, let alone a timeZone property. The time zone is a feature of the NSCalendar used to interpret that NSDate for display. (You may be more familiar with NSDateFormatter; it internally uses an NSCalendar to interpret the date.)

In this case, Xcode happens to configure the calendar for the variables panel a little differently from how LLDB configures the one for the debug console. I'd have to guess that the debug console is calling -description, which always uses UTC, while the variables panel is using a date formatter that respects the current time zone. (Your Mac is configured to use BST, right? If not, that's an odd choice...)

Becca Royal-Gordon
  • 17,541
  • 7
  • 56
  • 91
  • Yes. DST kicks in at the end of March, so 20130402 is right after ... I am just puzzled that Xcode cannot agree on the time zone/calendar to use depending on which pane you look at ... – verec Mar 23 '13 at 01:50
  • 2
    The debug console is just blindly calling `-description` because that's what you do when you want to convert an object to a string for printing. The variables panel is smarter: it's looked at the object and determined it's a date, so it wants to display it in the most useful way it can come up with. The two places display arrays and dictionaries even more differently. – Becca Royal-Gordon Mar 23 '13 at 01:53
3

Brent's reply is fine - but I wanted to address one detail specifically. lldb has built in type formatters for many common types including NSDate. If you did p date in the debugger console, you would get the same output as you see in the Locals window. When you right-click/control-clicked on the variable and did 'Print description', it is equivalent to writing po date in the console -- as Brent says, it calls the -description method.

This isn't a console vrs. Locals window difference, or an Xcode vrs. lldb difference. One access method is using lldb's built in data formatters and one is calling -description.

Jason Molenda
  • 14,835
  • 1
  • 59
  • 61
  • That's very interesting. Thanks for mentioning it. – Becca Royal-Gordon Mar 24 '13 at 09:06
  • btw, one really unimportant implementation detail is that lldb actually calls `_NSPrintForDebugger` which takes an object pointer as its argument, for the `po` command. gdb did the same thing. There's also a `_CFPrintForDebugger` function. – Jason Molenda Mar 26 '13 at 21:34