mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Allow date to be fixed at a certain timestamp
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user