[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with NSDateFormatter

From: Philippe Roussel
Subject: Re: Problem with NSDateFormatter
Date: Tue, 24 Aug 2010 11:42:00 +0200
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

On Tue, Aug 24, 2010 at 01:06:56AM +0200, Fred Kiefer wrote:
> Am 24.08.2010 00:16, schrieb Fred Kiefer:
> > Am 23.08.2010 15:20, schrieb Philippe Roussel:
> >> In SimpleAgenda I use an instance of NSDateFormatter created with
> >>
> >> dateFormatter = AUTORELEASE([[NSDateFormatter alloc]
> >> initWithDateFormat:[[NSUserDefaults standardUserDefaults]
> >> objectForKey:NSShortDateFormatString] allowNaturalLanguage:NO]);
> >>
> >> in the appointment editor for a textbox where you can enter the last
> >> date of a recurring event. I *think* it used to work but with latest svn
> >> I'm unable to change the date and the textbox has a really strange
> >> behaviour.
> >>
> >> I'm using a French locale but the problem exists in English too.
> >>
> >> Is my code wrong or is this a bug in NSDateFormatter ?
> >> Did someone recently tested that code ?
> > 
> > I was able to reproduce a problem here (probably with an older version
> > of SimpleAgenda). Could you please write a detailed bug report. I am
> > going to look into this in the next days and it would be great to have a
> > place where we gather all relevant information.
> My first impression when looking at a back trace from the code is that
> [NSCell setObjectValue:] gets called too often. I would expect that we
> only get that call, when the editor actually finished editing the text.
> But I get it each time I delete a character from the string.
> I still don't understand whether this is actually wrong and if so, where
> it goes wrong. Perhaps it is just too late over here. :-(

You probably understood that already but here's what I found :

setObjectValue is called because the NSTextField has a formatter so
when I asked for its objectValue it does the validation and, if the
validation succeeds, sets the objectValue.

As I call objectValue in controlTextDidChange, setObjectValue is
called almost for each text modification.

I just did an test: the field contains 24/09/2010, I press the end key
to move the cursor after the last character and press backspace. In
[AppointmentEditor controlTextDidChange:] I ask for the field
stringValue: and the result is '24/09/0201' instead of '24/09/201'.
This is because NSDateFormatter getObjectValue:forString: accepts
24/09/201 as a date which is formatted as 24/09/0201 and set as the
field string.

Last detail : if I remove [AppointmentEditor controlTextDidChange:] or
just don't call [NSTextField objectValue] everything works correctly.
I could rework my code to avoid controlTextDidChange: but even if my
code is ugly it should work as is I think.

A NSTextField method returning the current string without validating
it could be useful.

Would you like a bug report on savannah with these informations ?


> Breakpoint 1, -[NSCell setObjectValue:] (self=0xe007a0,
> _cmd=0x7ffff78108a0,
>     object=0xcde270) at NSCell.m:331
> 331     {
> (gdb) po object
> 29.09.2010
> (gdb) bt
> #0  -[NSCell setObjectValue:] (self=0xe007a0, _cmd=0x7ffff78108a0,
> object=0xcde270)
>     at NSCell.m:331
> #1  0x00007ffff7384577 in -[NSActionCell setObjectValue:] (self=0xe007a0,
>     _cmd=<value optimized out>, anObject=0xcde270) at NSActionCell.m:228
> #2  0x00007ffff74d70cf in -[NSTextField validateEditing] (self=<value
> optimized out>,
>     _cmd=<value optimized out>) at NSTextField.m:485
> #3  0x00007ffff738415f in -[NSActionCell objectValue] (self=0xe007a0,
>     _cmd=<value optimized out>) at NSActionCell.m:153
> #4  0x000000000040d0aa in -[AppointmentEditor controlTextDidChange:]
> (self=0xd70210,
>     _cmd=<value optimized out>, aNotification=<value optimized out>)
>     at AppointmentEditor.m:169
> #5  0x00007ffff6d5fb03 in -[NSNotificationCenter _postAndRelease:]
> (self=0x6dc210,
>     _cmd=<value optimized out>, notification=0x800020) at
> NSNotificationCenter.m:1161
> #6  0x00007ffff73f64bc in -[NSControl textDidChange:] (self=0xc95d30,
>     _cmd=<value optimized out>, aNotification=0x875a10) at NSControl.m:577
> #7  0x00007ffff74d796c in -[NSTextField textDidChange:] (self=0xc95d30,
>     _cmd=<value optimized out>, aNotification=0x875a10) at NSTextField.m:522
> #8  0x00007ffff6d5fb03 in -[NSNotificationCenter _postAndRelease:]
> (self=0x6dc210,
>     _cmd=<value optimized out>, notification=0x875a10) at
> NSNotificationCenter.m:1161
> #9  0x00007ffff754f0db in -[NSTextView didChangeText] (self=0x802e30,
>     _cmd=<value optimized out>) at NSTextView.m:2659
> #10 0x00007ffff7436c5a in -[NSInputManager handleKeyboardEvents:client:]
> (self=0x92c530,
>     _cmd=<value optimized out>, eventArray=<value optimized out>,
> client=0x802e30)
>     at NSInputManager.m:652
> #11 0x00007ffff7555a13 in -[NSTextView(leftovers) keyDown:] (self=0x802e30,
>     _cmd=<value optimized out>, theEvent=0xaf72f0) at NSTextView.m:5392
> ---Type <return> to continue, or q <return> to quit---
> #12 0x00007ffff73a0578 in -[NSApplication run] (self=0x930e00,
> _cmd=<value optimized out>)
>     at NSApplication.m:1532
> #13 0x00007ffff7380857 in NSApplicationMain (argc=<value optimized out>,
>     argv=<value optimized out>) at Functions.m:89

My mom had Windows at work and it hurt her eyes real bad.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]