views:

241

answers:

1

I have a 10.4 style date formatter applied to an NSTextFieldCell. I call setTwoDigitStartDate: (tried with both the epoch date and the "reference" date) but when I type in a date with a two digit year it sets the year to 0009 instead of 2009.

Header:

IBOutlet NSTextFieldCell *transactionDateField; // outlet *IS* set correctly in IB

Implementation:

- (void)awakeFromNib {
    NSDate *startDate = [NSDate dateWithTimeIntervalSinceReferenceDate:0];
    //NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:0];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormat setDateStyle:NSDateFormatterMediumStyle];
    [dateFormat setTwoDigitStartDate:startDate];
    [dateFormat setLenient:YES]; // tried with & without this
    [transactionDateField setFormatter:dateFormat];
}

Am I missing something obvious?

A: 

Try changing NSDateFormatterMediumStyle to this NSDateFormatterShortStyle

Anthony
It turns out that setTwoDigitStartDate: only works with date formats with a two digit year (NSDateFormatterShortStyle being one such format). I thought you'd be able to control the input of abbreviated long dates with this convenience method but alas you can not.
Matthew