Skip to content

Commit

Permalink
2004-06-14 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* TimeSpan.cs: Fixed timespan with large values for hours or minutes
	(overflow is only checked for days but can also occurs in hours and
	minutes which uses Int32 when multiplying). The new results match MS
	implementation.

svn path=/trunk/mcs/; revision=29520
  • Loading branch information
Sebastien Pouliot committed Jun 14, 2004
1 parent 43f8d7e commit 92935b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions mcs/class/corlib/System/ChangeLog
@@ -1,3 +1,10 @@
2004-06-14 Sebastien Pouliot <sebastien@ximian.com>

* TimeSpan.cs: Fixed timespan with large values for hours or minutes
(overflow is only checked for days but can also occurs in hours and
minutes which uses Int32 when multiplying). The new results match MS
implementation.

2004-06-14 Atsushi Enomoto <atsushi@ximian.com>

* FloatingPointFormatter.cs : Recognize '%' and '\u2030' and replace
Expand Down
14 changes: 7 additions & 7 deletions mcs/class/corlib/System/TimeSpan.cs
Expand Up @@ -71,14 +71,14 @@ public TimeSpan (int days, int hours, int minutes, int seconds, int milliseconds

internal static long CalculateTicks (int days, int hours, int minutes, int seconds, int milliseconds)
{
bool overflow = false;

// this part cannot overflow Int64
long t = checked (TimeSpan.TicksPerHour * hours +
TimeSpan.TicksPerMinute * minutes +
TimeSpan.TicksPerSecond * seconds +
TimeSpan.TicksPerMillisecond * milliseconds);
// there's no overflow checks for hours, minutes, ...
// so big hours/minutes values can overflow at some point and change expected values
int hrssec = (hours * 3600); // break point at (Int32.MaxValue - 596523)
int minsec = (minutes * 60);
long t = ((long)(hrssec + minsec + seconds) * 1000L + (long)milliseconds);
t *= 10000;

bool overflow = false;
// days is problematic because it can overflow but that overflow can be
// "legal" (i.e. temporary) (e.g. if other parameters are negative) or
// illegal (e.g. sign change).
Expand Down

0 comments on commit 92935b3

Please sign in to comment.