From: Benjamin Auder Date: Fri, 7 Dec 2018 23:10:16 +0000 (+0100) Subject: Pretty date printing in PGN X-Git-Url: https://git.auder.net/?p=vchess.git;a=commitdiff_plain;h=16984853e12058bd51b2e5ac065ed84febebc162 Pretty date printing in PGN --- diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 71695c49..48a5602c 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -1134,12 +1134,13 @@ class ChessRules // The score is already computed when calling this function getPGN(mycolor, score, fenStart, mode) { + const zeroPad = x => { return (x<10 ? "0" : "") + x; }; let pgn = ""; pgn += '[Site "vchess.club"]
'; const d = new Date(); const opponent = mode=="human" ? "Anonymous" : "Computer"; pgn += '[Variant "' + variant + '"]
'; - pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + '"]
'; + pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + zeroPad(d.getDate()) + '"]
'; pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]
'; pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]
'; pgn += '[FenStart "' + fenStart + '"]
';