Get on local time, baby.

This commit is contained in:
mattbk 2023-09-05 21:11:31 -05:00
parent 8a95413224
commit fd61efebba

View File

@ -66,9 +66,8 @@ const char index_html[] PROGMEM = R"rawliteral(
<script> <script>
// Submit timestamps as unix seconds // Submit timestamps as unix seconds
var putDate = function(form) { var putDate = function(form) {
form.inputTimeUnix.value = Math.floor(Date.now() / 1000); form.inputTimeUnix.value = Math.floor(Date.now() / 1000) - new Date().getTimezoneOffset()*60;
//offset_secs = new Date().getTimezoneOffset()*60; document.getElementById("js_start_time_unix").value = ((Date.parse(js_start_time_unix_entry.value))/1000);
document.getElementById("js_start_time_unix").value = ((Date.parse(js_start_time_unix_entry.value))/1000) - new Date().getTimezoneOffset()*60;
}; };
// Refresh page after submit so values are right https://stackoverflow.com/a/1860732/2152245 // Refresh page after submit so values are right https://stackoverflow.com/a/1860732/2152245
window.onload = function() { window.onload = function() {
@ -78,11 +77,14 @@ const char index_html[] PROGMEM = R"rawliteral(
// Current start date to string // Current start date to string
s = %inputStartTimeUnix%; s = %inputStartTimeUnix%;
current_start = new Date(s * 1000); current_start = new Date(s * 1000);
current_start_utc = current_start.toUTCString(); //current_start_utc = current_start.toUTCString();
document.getElementById('current-start').innerHTML = current_start_utc; document.getElementById('current-start').innerHTML = current_start.toString();
} }
</script></head><body> </script></head><body>
<p>Local time: <b>%inputTimeUnix%</b></p>
<form action="/get" target="hidden-form" onsubmit="putDate(this);" accept-charset=utf-8> <form action="/get" target="hidden-form" onsubmit="putDate(this);" accept-charset=utf-8>
<p>Sending program (cycle doesn't work yet) (current value: <b>%inputSend%</b>): <p>Sending program (cycle doesn't work yet) (current value: <b>%inputSend%</b>):
@ -102,9 +104,8 @@ const char index_html[] PROGMEM = R"rawliteral(
<option value="5">5 - MO5</option> <option value="5">5 - MO5</option>
</select></p> </select></p>
<p>Current time (UTC): <b>%inputTimeUnix%</b><br> <p>Program start time <input type="datetime-local" id="js_start_time_unix_entry" /><br>
Current value: <b><span id = current-start></span></b>)
Program start time (current value <b><span id = current-start></span></b>): <input type="datetime-local" id="js_start_time_unix_entry" />
<!-- JS converts the entered start time to a unix timestamp, and copies that value <!-- JS converts the entered start time to a unix timestamp, and copies that value
to this hidden field so the user doesn't have to see it. --> to this hidden field so the user doesn't have to see it. -->
<input type="hidden" name="inputStartTimeUnix" id="js_start_time_unix" /></p> <input type="hidden" name="inputStartTimeUnix" id="js_start_time_unix" /></p>