exporter: convert NOT_CHANGED_SINCE epoch to ISO on passthrough; set to now on re-serialize
This commit is contained in:
@@ -112,11 +112,24 @@ function _instrCharacterLines(instr) {
|
||||
});
|
||||
}
|
||||
|
||||
// RFC §4.4.1: DATE = YYYY-MM-DD HH:MM:SS
|
||||
// notChangedSince from AST log is a float epoch; score YAML must have ISO date.
|
||||
|
||||
function _epochToISO(val) {
|
||||
if (!val) return null;
|
||||
if (typeof val === 'string') return val;
|
||||
return new Date(val * 1000).toISOString().slice(0, 19).replace('T', ' ');
|
||||
}
|
||||
|
||||
function _nowISO() {
|
||||
return new Date().toISOString().slice(0, 19).replace('T', ' ');
|
||||
}
|
||||
|
||||
// RFC §4.4: embedded instrument key is "instrument NAME:" not "instrument: 'NAME'"
|
||||
|
||||
export function exportInstrument(instr) {
|
||||
const lines = [`instrument ${instr.name}:`];
|
||||
if (instr.notChangedSince) lines.push(` NOT_CHANGED_SINCE: ${instr.notChangedSince}`);
|
||||
lines.push(` NOT_CHANGED_SINCE: ${_nowISO()}`);
|
||||
lines.push(` character:`);
|
||||
lines.push(..._instrCharacterLines(instr));
|
||||
return lines.join('\n');
|
||||
@@ -210,6 +223,13 @@ function _patchInstrumentHeader(text, instruments) {
|
||||
} else if (instr.isLinked && !instr._modified) {
|
||||
result.push(line);
|
||||
i++;
|
||||
while (i < lines.length && (lines[i].startsWith(' ') || lines[i] === '')) {
|
||||
if (/^\s+NOT_CHANGED_SINCE\s*:/.test(lines[i]))
|
||||
result.push(` NOT_CHANGED_SINCE: ${_epochToISO(instr.notChangedSince)}`);
|
||||
else
|
||||
result.push(lines[i]);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
while (i < lines.length && (lines[i].startsWith(' ') || lines[i] === '')) i++;
|
||||
|
||||
Reference in New Issue
Block a user