Dbe889ac78c192a3f73fdb6da07eae5c

Check this in a cleaner way? (code written in LUA 4.0)

function Date:after(otherDate, noHour)
	return (self.year > otherDate.year or (self.year == otherDate.year and 
			(self.month > otherDate.month or (self.month == otherDate.month and 
				(self.day > otherDate.day or (self.day == otherDate.day and 
					(not noHour and (self.hour > otherDate.hour or (self.hour == otherDate.hour and
						(self.minute > otherDate.minute  or (self.minute == otherDate.minute and
							(self.second > otherDate.second))))))))))))
end

Refactorings

No refactoring yet !

F9a9ba6663645458aa8630157ed5e71e

Ants

December 7, 2009, December 07, 2009 20:56, permalink

No rating. Login to rate!

I'm not fluent with LUA, but it seems to me that this can be simplified following this pseudo code:

selfDate = self
if noHour then
selfDate.hour = otherDate.hour
selfDate.minute = otherDate.minute
selfDate.second = otherDate.second
end
return os.difftime(os.time(selfDate), os.time(otherDate)) > 0

Your refactoring





Format Copy from initial code

or Cancel