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

 
 

bug #26361: NSCalendarDate %e format shows leading zeros

Submitter:  Doug Simons <theeggcamefirst>
Submitted:  Mon 27 Apr 2009 06:41:29 PM UTC
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-05-16 CaS StatusNone Fixed
        Open/ClosedOpen Closed
    2009-04-28 theeggcamefirst Attached File- Added NSCalendarDate.m.patch, #18043

    Back to the top

    Powered by Savane 3.10