// Calculating the date using GregorianCalendar is rather slow, so we cache.
// As stamp, we use 'midnight at the end of the day', in minutes since Epoch.
long millis = System.currentTimeMillis();
int curMinutes = (int)(millis / MILLIS_PER_MINUTE);
int[] cacheValidUntilMinutes = new int[1];
ETuple cachedResult = cachedDate.get(cacheValidUntilMinutes);
if (curMinutes < cacheValidUntilMinutes[0] && cachedResult != null) { // Still valid
return cachedResult;
}
// Cache is invalid.
// Calculate the current date:
GregorianCalendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH)+1;
int day = cal.get(Calendar.DAY_OF_MONTH);
ETuple result = ETuple.make(ERT.box(year), ERT.box(month), ERT.box(day));
// Calculate valid-until, i.e. next midnight:
cal.add(Calendar.DAY_OF_YEAR, 1);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);