Re: Correctly entering AM/PM using NSDateFormatter
Re: Correctly entering AM/PM using NSDateFormatter
- Subject: Re: Correctly entering AM/PM using NSDateFormatter
- From: Nicholas Riley <email@hidden>
- Date: Sun, 20 Oct 2002 04:19:59 -0500
- Mail-followup-to: Chris Barnes <email@hidden>, email@hidden
On Sat, Oct 19, 2002 at 11:57:20PM -0700, Chris Barnes wrote:
>
I've attached a NSDateFormatter with the format "%1I:%M%p" to a cell.
>
But when the user enters an explicit reference to any time after noon
>
(say, 5:30 PM), it ends up being recorded as 5:30 AM. Shouldn't it
>
recognize the PM and mark it as 17:30?
NSDateFormatter/NSCalendarDate are the buggiest, worst implemented
classes I've found in Cocoa. Their localization support is next to
nonexistent. Formats such as "%1I" - note that the "1" prefix is
completely undocumented - do not work for input in 10.1. If you try
to set up a NSDateFormatter with that format and don't enable "Allow
natural language", it will not validate. If you use "%I:%M%p" then
input works fine on 10.1.x, but not on 10.2, so to be compatible you
should always enable "Allow natural language" in IB.
Make sure to accommodate different values for %p. Sometimes it's "PM"
(or "pm") and sometimes it's " PM", so you'll end up with too few or
too many spaces if you're not careful.
Also consider that users may have 24-hour time formats, and %p may be
blank, or else for a format such as German there's a time suffix which
is identical for AM and PM, z.B. "Uhr". And don't think %x/%X will
work, because in 10.2 at least, they return the entire date/time
format including time zone (e.g. "Sunday, October 20, 2002 04:02:00
America/Chicago"). Not to mention the time format seems to get
randomly corrupted, so you end up with AM/PM on a 24-hour time or
similar insanity.
My Pester app (download at
<
http://web.sabi.net/nriley/software/#pester>, or you can browse the
current source at <
http://svn.sabi.net/repos/dev/trunk/Cocoa/Pester>)
works properly with NSDateFormatter through a series of kludges, at
least for US date/time formats. Pester does not properly deal with
24-hour time and localized date formats, unfortunately.
I will need to add some more workarounds to compensate for Cocoa bugs
in the next version, or else just switch to the Carbon equivalents.
iCal contains date and time controls which localize a little better,
though still not as well as the Carbon controls do. For example,
Carbon displays the "Uhr" where as Cocoa does not. If you change a
date format while a Carbon app is running, the control automatically
updates for the new format. You need to quit and restart iCal to get
the some result.
Nevertheless, iCal's controls are a gigantic step above
NSDateFormatter, and I look forward to their being available to all
Cocoa apps.
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.