TimeHelpers noTime always returns current Date #1280

Closed
wants to merge 2 commits into from

4 participants

@tuhlmann
Lift Web Framework member

I'm playing with the TimeHelpers and I ran across the following:

Using "3.days.ago.noTime" would always give me the current day, but
using "3.days.ago" would give me today - 3 days (with the time filled.

I have looked at the definition of noTime and I think it's wrong:

/** This class adds a noTime method the Date class, in order to get at Date object starting at 00:00 /
class DateExtension(date: Date) {
/
* @return a Date object starting at 00:00 from date */
def noTime = {
val calendar = Calendar.getInstance
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
calendar.getTime
}
}

The important thing is that the date parameter is not used when creating the Calendar. Calendar.getInstance creates a Calendar object of now and then the time is stripped away.

The solution would be to create the Calendar object from the given date parameter using calendar.setTime.

@tuhlmann tuhlmann was assigned Jun 17, 2012
@fmpwizard
Lift Web Framework member

Could you add a spec test for it?
Other than that, thanks for fixing it!

@tuhlmann
Lift Web Framework member
@fmpwizard
Lift Web Framework member

Thanks for adding the test. I never tried to run the mongo tests on purpose, but if I run just test, all test pass for me. And I don;t have any mongodb instance installed on my machine.

Maybe you can ask on the lift list?

@tuhlmann
Lift Web Framework member
@fmpwizard
Lift Web Framework member

Yes +1 from me.

I normally wait a few days before rebasing my changes to master. I don;t think we have a set number of +1, but my personal rule is that if the change is pretty small or easy to read, then 4-5 days is enough, if it is a big change, I have waited about two weeks, just to give people time.

@Shadowfiend
Lift Web Framework member

+1 from me.

@eltimn
Lift Web Framework member

@tuhlmann if the mongo test that is failing is for JObjectParser, I just committed a fix for it. If it's something else, let me know.

@tuhlmann
Lift Web Framework member
@eltimn
Lift Web Framework member

I just pushed a commit to master that should fix that test.

Thanks for letting me know about it and I'm glad someone else is running the mongo tests.

@tuhlmann tuhlmann added a commit that referenced this pull request Jun 20, 2012
@tuhlmann tuhlmann Issue #1280: Adding noTime tests. 6d55cd3
@tuhlmann
Lift Web Framework member

I merged the pull request into master.

@tuhlmann tuhlmann closed this Jun 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment