Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I've come up with a solution.</p> <p>When data is fetched, the following is done... </p> <pre><code>editPrefs.putLong("fetchTime", System.currentTimeMillis()); </code></pre> <p><br /> When the application starts and data is normally requested, it now does..<br> (<strong>Note:</strong> The page is updated daily at "9pm AEDT" - (Australia Eastern Daylight Savings time), and I assume it would change to AEST (Australia Eastern Standard time) when daylight savings ends. "Australia/ACT" is a timezone that goes by these zones)</p> <pre><code>//create calendar date for update threshold based on last fetch time preference Calendar updateThresh = new GregorianCalendar(TimeZone.getTimeZone("Australia/ACT")); updateThresh.setTimeInMillis(prefs.getLong("fetchTime", 0)); //increment day if last fetch was &gt;= 9pm of that day if (updateThresh.get(Calendar.HOUR_OF_DAY) &gt;= 21) updateThresh.add(Calendar.DAY_OF_MONTH, 1); //set time to 9:00:00pm updateThresh.set(Calendar.HOUR_OF_DAY , 21); updateThresh.set(Calendar.MINUTE , 0); updateThresh.set(Calendar.SECOND , 0); //check if current date is before or after if (updateThresh.before(new GregorianCalendar(TimeZone.getTimeZone("Australia/ACT")))) { //update needed (fetch data) } else { //update not needed (show message) } </code></pre> <p>This seems to work fine. I've tested it using a DateFormat set to Australia/ACT and it seems to work... e.g. Making another calendar object that is set to the fetch time and using:</p> <pre><code>DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone(TimeZone.getTimeZone("Australia/ACT")); testTextField.setText("Last fetch in East AU time: " + df.format(fetchTime.getTimeInMillis()) + "\nUpdate threshold in East AU time: " + df.format(updateThresh.getTimeInMillis()) ); </code></pre> <p>This shows me consistently correct output even if I play around with the timezone settings on my phone... I'm fairly certain this solution works, so I'll mark it correct/accepted - but if anyone notices an error or has a better suggestion, feel free to contribute! :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload