Code: Select all
if (isset($_GET['year'])) {
$tableYear = $_GET['year'];
} else {
$tableYear = date("Y");
}
Code: Select all
if (isset($_GET['year'])) {
$tableYear = $_GET['year'];
} else {
$tableYear = date('Y', strtotime('-1 day'));
}
Code: Select all
if (isset($_GET['year'])) {
$tableYear = $_GET['year'];
} else {
$tableYear = date("Y");
}
Code: Select all
if (isset($_GET['year'])) {
$tableYear = $_GET['year'];
} else {
$tableYear = date('Y', strtotime('-1 day'));
}
Code: Select all
if (isset($_GET['year'])) { $tableYear = $_GET['year']; }
else
{
if (date("n") == 1 and date("j") == 1) { $tableYear = date("Y") - 1; }
else { $tableYear = date("Y"); }
}
Code: Select all
$tableYear = date ('Y', filemtime('dayfile.txt'));
gives a JavaScript equivalent way to read last file modifed date (where X is used for Ajax XMLHttpRequest). This can then replace 'new Date()' inaduncan wrote:= X.getResponseHeader('Last-Modified');
Code: Select all
if(urlParams['year']){drawYear=urlParams['year'];}else{var d=new Date();var curr_date=d.getDate();drawYear=d.getFullYear();}
What this implies is that for a midnight rollover, file creation date will be either midnight (if Cumulus was running) or some time after (if rollover happened in catch up). In the running case, the date will still contain the year of 1 January at rollover, and at least one minute will need to be subtracted to get correct year of last dayfile.txt record. For 9 (or 10) am rollovers, subtract 9 (or 10) hours plus at least one minute to get correct year of last dayfile.txt record.steve wrote:when dayfile.txt is updated:
Cumulus uses a timer which triggers once a minute, on the minute. It checks each time whether the configured rollover hour has been reached (i.e. a new meteorological day is just starting), and if so, does the rollover, part of which involves writing an entry to dayfile.txt. The exact timing will depend on what the system is doing at the time. This assumes that Cumulus is actually running at the time. If it wasn't, and it's using logger data, then it does the rollover when it encounters an entry from the logger which takes it into the next meteorological day.
Code: Select all
<script>var metDate=['<#metdate format="dd">','<#metdate format="mm">','<#metdate format="yyyy">',(parseInt("0"+"<#rollovertime>",10))];</script><!-- Pass current Meteorological date and rollover time to script to read dayfile, so knows what is default start up year -->
<script src="readDayfile.js" type="text/javascript"></script><!-- calls ECMA-262 Script to read the 'dayfile.txt' file -->
</body>
</html>
Code: Select all
if(urlParams['year']){drawYear=urlParams['year'];}else{var d=new Date();var curr_date=d.getDate();drawYear=d.getFullYear();}
Code: Select all
var d=new Date(metDate[2],(metDate[1]-1),metDate[0], metDate[3]); // metDate is an array containing the date and time for the last rollover time
var todayMS = d.getTime(); // Milliseconds since midnight 1 January 1970
d=new Date(todayMS -(1000*60*60*24)); // Now looking at one day ago, so okay
var curr_year=d.getFullYear(); // default to calendar year for 1 day ago if parameters undefined on entry
Code: Select all
if(urlParams['year']){drawYear=urlParams['year'];}else{drawYear=curr_year;}
I wrote that 20 days ago, but did not instantly know the correct code, but here is the relevant extract from jScript code I shall post in a new topic:sfws wrote:(a) The simplest solution, as the (PHP or jQuery) scripts produce a list of years from reading the dayfile, is don't read current date property of PHP or JavaScript at all, just default to latest year found as you build up the year selection list. A simple solution but it works at any time, including if Cumulus has not been running recently, so the dayfile.txt is not up to date.
Code: Select all
$.get(dayfile,function(data) // Open dayfile.txt to read file contents and copy them to 'data'
{ // begining of anonymous function
var dRow=data.split("\n"); // split that 'data' into array with newline used as delimiter
var last_record=dRow[dRow.length-2]
wd_data=last_record.split(field_delimiter); // split row into fields
cumulus_date=wd_data[0].split(date_delimiter);
latest_year='20'+String(cumulus_date[2]);
tableYear=latest_year;