Commits

Anonymous committed 4041e9f

Fix week dates for certain weekdays.

One of these subtractions gave a negative result for certain weekdays, and since all of these variables were unsigned, that change to the interpretation of the result threw a comparison out of whack. The fix is simply to make all of these signed integers.

Comments (0)

Files changed (1)

ISO8601DateFormatter.m

 		monday, tuesday, wednesday, thursday, friday, saturday, sunday
 	};
 	enum {
-		january = 1U, february, march,
+		january = 1, february, march,
 		april, may, june,
 		july, august, september,
 		october, november, december
 	};
 
-	unsigned year = components.year;
-	unsigned week = 0U;
+	int year = components.year;
+	int week = 0;
 	//The old unparser added 6 to [calendarDate dayOfWeek], which was zero-based; components.weekday is one-based, so we now add only 5.
-	unsigned dayOfWeek = (components.weekday + 5U) % 7U;
-	unsigned dayOfYear = ordinalComponents.day;
+	int dayOfWeek = (components.weekday + 5) % 7;
+	int dayOfYear = ordinalComponents.day;
 
-	unsigned prevYear = year - 1U;
+	int prevYear = year - 1;
 
 	BOOL yearIsLeapYear = is_leap_year(year);
 	BOOL prevYearIsLeapYear = is_leap_year(prevYear);
 
-	unsigned YY = prevYear % 100U;
-	unsigned C = prevYear - YY;
-	unsigned G = YY + YY / 4U;
-	unsigned Jan1Weekday = (((((C / 100U) % 4U) * 5U) + G) % 7U);
+	int YY = prevYear % 100;
+	int C = prevYear - YY;
+	int G = YY + YY / 4;
+	int Jan1Weekday = (((((C / 100) % 4) * 5) + G) % 7);
 
-	unsigned weekday = ((dayOfYear + Jan1Weekday) - 1U) % 7U;
+	int weekday = ((dayOfYear + Jan1Weekday) - 1) % 7;
 
-	if((dayOfYear <= (7U - Jan1Weekday)) && (Jan1Weekday > thursday)) {
-		week = 52U + ((Jan1Weekday == friday) || ((Jan1Weekday == saturday) && prevYearIsLeapYear));
+	if((dayOfYear <= (7 - Jan1Weekday)) && (Jan1Weekday > thursday)) {
+		week = 52 + ((Jan1Weekday == friday) || ((Jan1Weekday == saturday) && prevYearIsLeapYear));
 		--year;
 	} else {
-		unsigned lengthOfYear = 365U + yearIsLeapYear;
+		int lengthOfYear = 365 + yearIsLeapYear;
 		if((lengthOfYear - dayOfYear) < (thursday - weekday)) {
 			++year;
-			week = 1U;
+			week = 1;
 		} else {
-			unsigned J = dayOfYear + (sunday - weekday) + Jan1Weekday;
-			week = J / 7U - (Jan1Weekday > thursday);
+			int J = dayOfYear + (sunday - weekday) + Jan1Weekday;
+			week = J / 7 - (Jan1Weekday > thursday);
 		}
 	}
 
 	} else
 		timeString = @"";
 
-	return [NSString stringWithFormat:@"%u-W%02u-%02u%@", year, week, dayOfWeek + 1U, timeString];
+	return [NSString stringWithFormat:@"%u-W%02u-%02u%@", (unsigned)year, (unsigned)week, ((unsigned)dayOfWeek) + 1U, timeString];
 }
 
 @end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.