Created
September 29, 2015 18:37
-
-
Save RobertFischer/3c397b02f5eeb264a8bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum TimePeriod { | |
ONE_YEAR_AGO(Calendar.YEAR, -1), | |
THREE_MONTHS_AGO(Calendar.MONTH, -3), | |
// and so on... | |
; | |
private int calendarField; | |
private int changeMagnitude; | |
private TimePeriod(int calendarField, int changeMagnitude) { | |
Calendar.getInstance().add(calendarField, changeMagnitude).getTime(); // Sanity check | |
this.calendarField = calendarField; | |
this.changeMagnitude = changeMagnitude; | |
} | |
public long fromNowMillis() { | |
return Calendar.getInstance().add(calendarField, changeMagnitude); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment