Skip to content

Instantly share code, notes, and snippets.

@gitname
Created November 22, 2017 08:14
Show Gist options
  • Save gitname/597cdc5afc81cd568ef27a66ce7be04a to your computer and use it in GitHub Desktop.
Save gitname/597cdc5afc81cd568ef27a66ce7be04a to your computer and use it in GitHub Desktop.
Construct copyright date range on client
<html>
<head>
<!-- ... -->
</head>
<body>
<!-- ... -->
<p>
&copy; <span id="copyright-year-initial">2017</span><span id="copyright-year-separator"></span><span id="copyright-year-current"></span>
</p>
<script>
(function () {
var constructCopyrightMessage = function () {
var initialYear = parseInt(document.getElementById("copyright-year-initial").innerHTML);
var currentYear = (new Date()).getFullYear();
if (initialYear < currentYear) {
document.getElementById("copyright-year-separator").innerHTML = "-";
document.getElementById("copyright-year-current").innerHTML = currentYear.toString();
}
};
// Change "(c) 2017" to "(c) 2017-2018" when 2018 arrives.
constructCopyrightMessage();
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment