From 0b952443c1c523890f3f0586754eab8c1c3f2e5d Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Tue, 26 Jan 2016 06:32:36 -0500 Subject: [PATCH] Propagate (full) date placeholder after every change. --- entry.js | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/entry.js b/entry.js index a2a1026..95d642c 100644 --- a/entry.js +++ b/entry.js @@ -127,15 +127,31 @@ function get_entry_id() { /* Convert a 21st century date to 34th century. */ function elite_date(then) { - var now = new Date(); - var year = String(now.getFullYear() + 1286); - var month = zero_pad(now.getMonth() + 1); - var day = zero_pad(now.getDate()); - var date = (then) ? then : [year, month, day].join('-'); - var hours = zero_pad(now.getHours()); - var minutes = zero_pad(now.getMinutes()); - var seconds = zero_pad(now.getSeconds()); - var time = [hours, minutes, seconds].join(':'); + var now = null; + var then_date = null; + var then_time = null; + if (then) { + var m = then.match(/^(\d\d\d\d-\d\d-\d\d)(?:\s+(\d\d:\d\d:\d\d))?$/); + if (m) { + then_date = m[1]; + then_time = m[2]; + } + } + if (! then_date || ! then_time) now = new Date(); + if (then_date) date = then_date; + else { + var year = String(now.getFullYear() + 1286); + var month = zero_pad(now.getMonth() + 1); + var day = zero_pad(now.getDate()); + var date = [year, month, day].join('-'); + } + if (then_time) time = then_time; + else { + var hours = zero_pad(now.getHours()); + var minutes = zero_pad(now.getMinutes()); + var seconds = zero_pad(now.getSeconds()); + var time = [hours, minutes, seconds].join(':'); + } return [date, time].join(' '); } @@ -669,7 +685,8 @@ function changed(event) { var m = input.id.match(/^lap(\d+)station(\d+)$/); if (! m) return; var table = get_table(); - return changed_cell(table, parseInt(m[2]), parseInt(m[1]), input); + changed_cell(table, parseInt(m[2]), parseInt(m[1]), input); + if (input.value.match(input.pattern)) propagate_placeholder(table, input.value); } /* A hull percentage was changed. */ @@ -755,7 +772,6 @@ function add_lap(table, date) { p.appendChild(summary(lap)); td.appendChild(p); table.rows[last_row(table) + 1].appendChild(td); - propagate_placeholder(table, date); } /* Remove the last lap. */ @@ -846,6 +862,7 @@ function loaded() { } } } + else propagate_placeholder(table); var joker = get_joker(); if (joker) joker.addEventListener('change', changed_joker, true); if (typeof distances != 'undefined') update_raikogram(table); -- 2.7.4