bugGNUstep - Bugs: bug #16426, NSCalendarDate don't work properly...

Group
 
 

bug #16426: NSCalendarDate don't work properly with milliseconds

Submitter:  Sergei Golovin <svg>
Submitted:  Mon 24 Apr 2006 04:31:38 AM 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
   

Wed 26 Apr 2006 01:36:56 PM UTC, comment #1: 

The actual bug was a floaring point rounding error ... in your test case the .901 of a second value was stored as .90099999

This is now fixed in SVN to round to the nearest millisecond (with a half millisecond rounding up).

Richard Frith-Macdonald <CaS>
Group Member
Mon 24 Apr 2006 04:31:38 AM UTC, original submission:  

There is a bug #14863 with suggesting:
----------------------------------------------------------------------------------------------
I think the milliseconds are accidentally getting truncated at line 1868 of the current CVS file (1.110) with the statement:
v = (int)s;

I believe the correct line is
v = (int) (s * 1000);
----------------------------------------------------------------------------------------------

But variable "s" has type "double". So "1000" also cast to that type. Here is an error which can see in the  followed testcase:

----------------------------------------------------------------------------------------------
NSString *fmt = [NSString
            stringWithFormat:@"%%Y-%%m-%%d %%H:%%M:%%S:%%F"];
NSString *dateString = [NSString
            stringWithFormat:@"2006-4-22 22:22:22:901"];
NSCalendarDate *date = [NSCalendarDate
            dateWithString:dateString calendarFormat:fmt];
NSLog(@"format %@", fmt);
NSLog(@"input date %@", dateString);
NSLog(@"output date %@", [date descriptionWithCalendarFormat:fmt]);
----------------------------------------------------------------------------------------------

With results:

----------------------------------------------------------------------------------------------
2006-04-24 04:15:42.923 nscalday[12266] format %Y-%m-%d %H:%M:%S:%F
2006-04-24 04:15:42.932 nscalday[12266] input date 2006-4-22 22:22:22:901
2006-04-24 04:15:42.932 nscalday[12266] output date 2006-04-22 22:22:22:900
----------------------------------------------------------------------------------------------

900 milliseconds but must be 901.

So the line (1868) could be looked:

v = (int) (s * 10000 / 10);

or

v = (int) round(s * 1000);




Sergei Golovin <svg>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

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 2 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-04-26 CaS StatusNone Fixed
    Open/ClosedOpen Closed

Back to the top

Powered by Savane 3.13-f8d8.
Corresponding source code