Created
May 5, 2020 15:36
-
-
Save imme-emosol/af83ca4bdf8c6cd58c23ccfd24b4cfdd to your computer and use it in GitHub Desktop.
Deterministic ISO 8601
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-GB-oxendict" xml:lang="en-GB-oxendict"> | |
<head> | |
<title> Deterministic ISO 8601 </title> | |
<meta charset="UTF-8" /> | |
<style type="text/css"> | |
/*<![CDATA[*/ | |
body | |
, input | |
{ | |
background-color : #333 ; | |
color : #CCC ; | |
} | |
input | |
{ | |
padding : 0.3rem ; | |
border-radius : 0.4rem ; | |
} | |
output | |
{ | |
display : block ; | |
} | |
/*]]>*/ | |
</style> | |
</head> | |
<body> | |
<h1> Deterministic ISO 8601 </h1> | |
<script type="text/javascript"> | |
/*<![CDATA[*/ | |
var longYears = [ | |
4 , 32 , 60 , 88 | |
, 9 , 37 , 65 , 93 | |
, 15 , 43 , 71 , 99 | |
, 20 , 48 , 76 | |
, 26 , 54 , 82 | |
, 105 , 133 , 161 , 189 | |
, 111 , 139 , 167 , 195 | |
, 116 , 144 , 172 | |
, 122 , 150 , 178 | |
, 128 , 156 , 184 | |
, 201 , 229 , 257 , 285 | |
, 207 , 235 , 263 , 291 | |
, 212 , 240 , 268 , 296 | |
, 218 , 246 , 274 | |
, 224 , 252 , 280 | |
, 303 , 331 , 359 , 387 | |
, 308 , 336 , 364 , 392 | |
, 314 , 342 , 370 , 398 | |
, 320 , 348 , 376 | |
, 325 , 353 , 381 | |
] | |
; | |
// f( y ) = is ( y % 400 ) in set longYears | |
var isLong = function ( y ) | |
{ | |
return -1 != longYears.indexOf( y % 400 ); | |
} | |
; | |
var fillWeeks = function () | |
{ | |
var yInputElement = document.getElementsByName( 'year' )[ 0 ] ; | |
var yInput = yInputElement.value ; | |
var y = yInput < 0 ? -1 * yInput : yInput ; | |
var wOutputElement = document.getElementsByName( 'weeks' )[ 0 ] ; | |
wOutputElement.value = isLong( y ) ? 53 : 52 ; | |
} | |
; | |
var y = new Date().getFullYear() ; | |
var form = '<form onsubmit=" event.preventDefault() ; fillWeeks() ; return false ; " method="POST" >'; | |
form += '<input type="number" name="year" value="' + y + '" onkeyup=" fillWeeks() ; " onchange=" fillWeeks() ; " />'; | |
form += '<output name="weeks" ></output>'; | |
form += '</form>'; | |
document.body.innerHTML += form; | |
fillWeeks(); | |
/*]]>*/ | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment