Hi Gene,
sorry, long time and no word from my side.
I'll try to make up for this by posting the logic of how I construct the label for the current sunphase.
I extracted the relevant code and generalized it a bit and added comments to explain what is happening.
Let me know if this is self-explaining enough to adapt it for the app or if I need to elaborate a bit more. Here we go:
// used variable
var DataTimers = { // this object contains all calculated timestamps for phases start and end in a chronological order
label: // Timestamp label.
// The variable "label" simply contains the variable name from the widget settings that holds the phase time.
// e.g. "jkUtils.SolarAltitude.Evening.Nautical.Start" => "20:52"
//
// It is used to resolve the localized value of the span with the matching attribute "data-local-id"=label from within
// the hidden settings section of the html template, e.g.
// "jkUtils.SolarAltitude.Morning.Nautical.Start" references the span containing "Nautical Dawn" as text.
time: // unix-timestamp
timeStr: // time as string in 24h format, e.g. "02:01"
timePrefix: // 'at', 'till' or 'since'
icon: // icon file name, e.g. "Evening.Nautical.Start.png"
// the icon-filename itself is always the variable name without the plugin-name-prefix
// e.g. jkUtils.SolarAltitude.Evening.Nautical.Start => Evening.Nautical.Start.png
// those icons are located in the images/status sub-folder
};
// for the timePrefix part of the object:
// this is hard coded for the relevant/used phases. I currently use the following timers for display:
[ 'Morning.Night.End', 'till' ],
[ 'Morning.Astronomical.Start', 'since' ],
[ 'Morning.Nautical.Start', 'since' ],
[ 'Morning.Civil.Start', 'since' ],
[ 'Morning.Sunrise.Start', 'since' ],
[ 'Morning.Sunrise.End', 'at' ],
[ 'Morning.GoldenHour.Start', 'since' ],
[ 'Morning.GoldenHour.End', 'since' ],
[ 'Day.Noon', 'at' ],
[ 'Evening.GoldenHour.Start', 'till' ],
[ 'Evening.GoldenHour.End', 'till' ],
[ 'Evening.Sunset.Start', 'at' ],
[ 'Evening.Sunset.End', 'till' ],
[ 'Evening.Civil.End', 'till' ],
[ 'Evening.Nautical.End', 'till' ],
[ 'Evening.Astronomical.End', 'till' ],
[ 'Evening.Night.Start', 'since' ],
[ 'Night.Nadir', 'at' ]
//-------------------------------------------------------------------------
// -- START: Code for composing the phase display text
//-- Setup Variables
//
var now = new Date(), // get current timestamp
currentTime = 0,
description, offset, closestOffset;
//-- Find Closest Timestamp To Current Time
//
closestOffset = Infinity; //initially set offset to max value (infinity)
for( var i = 0; i < DataTimers.length; ++i ) { //calculate which given timestamp is closest to current timestamp
var loopTimer = DataTimers[i].time;
offset = Math.abs( +loopTimer - +now );
if ( offset < closestOffset ) {
closestOffset = offset;
currentTime = i;
}
}
//-- Exceptions: pick another timestamp under certain conditions:
//
//
//-- Jump To Next Timestamp When Current Time Is Past 'till' Or 'at'
if( now > DataTimers[currentTime].time &&
( DataTimers[currentTime].timePrefix == 'till' || DataTimers[currentTime].timePrefix == 'at' ) ) currentTime++;
//-- next Exception:
//
//
//-- Jump Back To Previous Timestamp When Time Before 'since'
if( now < this.DataTimers[currentTime].time &&
this.DataTimers[currentTime].timePrefix == 'since' ) currentTime--;
//-- Construct Current Phase Display Text
//
description += '<span>' + DataTimers[currentTime].timePrefix + '</span><span>' + DataTimers[currentTime].timeStr + '</span><br/>';
// -- END: Code for composing the phase display text