bugGNUstep - Bugs: bug #26361, NSCalendarDate %e format shows...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #26361: NSCalendarDate %e format shows leading zeros

Submitted by:  Doug Simons <theeggcamefirst>
Submitted on:  Mon 27 Apr 2009 06:41:29 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

Sat 16 May 2009 07:36:29 PM UTC, comment #3:

Thanks, I applied your patch in svn.

Richard Frith-Macdonald <CaS>
Project Member
Tue 28 Apr 2009 04:36:54 PM UTC, comment #2:

Okay, here's an additional patch to NSCalendarDate that implements optional field widths for numeric fields in a date format. I believe this functionality is working the same as Cocoa's. You can supply a field width such as "%5d" which will left-pad the day of the month with spaces, or "%05d" which will fill with zeros. This capability is mainly useful for things like "%1d" (equivalent to "%e" now) or "%1m" which is the only way to get a single-digit month to appear as a single character.

I also set %e to work the same as Cocoa, without a leading space for single-digit days.

(file #18043)

Doug Simons <theeggcamefirst>
Mon 27 Apr 2009 09:06:40 PM UTC, comment #1:

It looks like someone checked in my patch already, which is great. I just realized that this isn't EXACTLY what Cocoa is doing, though. Apple's implementation isn't including the leading space for days less than 10 -- they just output the single digit. Their documentation is slightly ambiguous on this: "same as %d but does not print the leading 0 for days 1 through 9".

I think most implementations of the strftime() function that support %e include a leading space before a single digit, so it's certainly a reasonable way to go. I also plan to tweak this code to support a field width specifier (which Cocoa supports), which will then allow a format of "%1d" (or "%1e") to suppress the leading zero or space.

Nevertheless, I thought I'd let you all know that the current implementation is still not quite in sync with Apple's, in case you prefer to go for 100% compatibility with Cocoa rather than compatibility with the rest of the world. :-)

Doug Simons <theeggcamefirst>
Mon 27 Apr 2009 06:41:29 PM UTC, original submission:

Date formatting with %e is identical to %d (both show leading zero before single-digit day of month). On Cocoa (and most other systems?) the %e format shows a leading space rather than a 0.

It looks like the implementation of the %e format is just wrong. Here's a patch that works for me:

Index: NSCalendarDate.m
===================================================================
--- NSCalendarDate.m (revision 28244)
+++ NSCalendarDate.m (working copy)
@@ -1967,16 +1967,15 @@
v = info->dom;
Grow(info, 2);
v = v % 100;
- if (v%10 == '0')
+ if (v < 10)
{
- info->t[info->offset+1] = ' ';
+ info->t[info->offset+0] = ' ';
}
else
{
- info->t[info->offset+1] = (v%10) + '0';
+ info->t[info->offset+0] = (v/10) + '0';
}
- v /= 10;
- info->t[info->offset+0] = (v%10) + '0';
+ info->t[info->offset+1] = (v%10) + '0';
info->offset += 2;
break;

Doug Simons <theeggcamefirst>

 

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by CaS (Posted a comment)
  • -unavailable- added by theeggcamefirst (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 16 May 2009 07:36:29 PM UTCCaSStatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Tue 28 Apr 2009 04:36:54 PM UTCtheeggcamefirstAttached File-=>Added NSCalendarDate.m.patch, #18043

    Back to the top


    Powered by Savane 3.1-cleanup1