Allow date to be fixed at a certain timestamp

pull/69/head
Alinson S. Xavier 10 years ago
parent 1930db3cd1
commit 3d1c53396c

@ -32,14 +32,22 @@ import java.util.TimeZone;
public class DateHelper public class DateHelper
{ {
public static int millisecondsInOneDay = 24 * 60 * 60 * 1000; public static int millisecondsInOneDay = 24 * 60 * 60 * 1000;
private static Long fixedLocalTime = null;
public static long getLocalTime() public static long getLocalTime()
{ {
if(fixedLocalTime != null) return fixedLocalTime;
TimeZone tz = TimeZone.getDefault(); TimeZone tz = TimeZone.getDefault();
long now = new Date().getTime(); long now = new Date().getTime();
return now + tz.getOffset(now); return now + tz.getOffset(now);
} }
public static void setFixedLocalTime(Long timestamp)
{
fixedLocalTime = timestamp;
}
public static long toLocalTime(long timestamp) public static long toLocalTime(long timestamp)
{ {
TimeZone tz = TimeZone.getDefault(); TimeZone tz = TimeZone.getDefault();
@ -54,9 +62,7 @@ public class DateHelper
public static GregorianCalendar getStartOfTodayCalendar() public static GregorianCalendar getStartOfTodayCalendar()
{ {
GregorianCalendar day = new GregorianCalendar(TimeZone.getTimeZone("GMT")); return getCalendar(getStartOfToday());
day.setTimeInMillis(DateHelper.getStartOfDay(DateHelper.getLocalTime()));
return day;
} }
public static GregorianCalendar getCalendar(long timestamp) public static GregorianCalendar getCalendar(long timestamp)
@ -187,5 +193,4 @@ public class DateHelper
return weekday; return weekday;
} }
} }

Loading…
Cancel
Save