Source code: raining/util/LazyDate.java
1 package raining.util;
2 import java.util.*;
3 /** a date that updates every "refresh" millis.
4 * copied from Bulka. There are 2 millis() happening in a row.
5 * can that be improved.
6 */
7 class LazyDate {
8 private long lastCheck = 0; // Never checked before
9 private String today;
10 private long cacheRefresh;
11 public LazyDate(long refresh) {
12 cacheRefresh = refresh;
13 update();
14 }
15 public String todaysDate() {
16 long now = System.currentTimeMillis();
17 if ((now-lastCheck) > cacheRefresh) {
18 update();
19 }
20 return today;
21 }
22 private void update() {
23 lastCheck = System.currentTimeMillis();
24 today = (new Date()).toString();
25 }
26 }