forked from MilosKozak/AndroidAPS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0034952
commit d54651e
Showing
4 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package info.nightscout.utils; | ||
|
||
import android.util.LongSparseArray; | ||
|
||
import java.util.Calendar; | ||
|
||
public class MidnightTime { | ||
private static LongSparseArray times = new LongSparseArray(); | ||
|
||
private static long hits = 0; | ||
private static long misses = 0; | ||
|
||
public static long calc() { | ||
Calendar c = Calendar.getInstance(); | ||
c.set(Calendar.HOUR_OF_DAY, 0); | ||
c.set(Calendar.MINUTE, 0); | ||
c.set(Calendar.SECOND, 0); | ||
c.set(Calendar.MILLISECOND, 0); | ||
return c.getTimeInMillis(); | ||
} | ||
|
||
public static long calc(long time) { | ||
Long m = (Long) times.get(time); | ||
if (m != null) { | ||
++hits; | ||
return m; | ||
} | ||
Calendar c = Calendar.getInstance(); | ||
c.setTimeInMillis(time); | ||
c.set(Calendar.HOUR_OF_DAY, 0); | ||
c.set(Calendar.MINUTE, 0); | ||
c.set(Calendar.SECOND, 0); | ||
c.set(Calendar.MILLISECOND, 0); | ||
m = c.getTimeInMillis(); | ||
times.append(time, m); | ||
++misses; | ||
return m; | ||
} | ||
|
||
public static String log() { | ||
return "Hits: " + hits + " misses: " + misses + " stored: " + times.size(); | ||
} | ||
} |