Last active
December 16, 2015 11:49
-
-
Save biovisualize/5430237 to your computer and use it in GitHub Desktop.
Parse dates with quarters (i.e., "Q4-2010")
This file contains 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
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var dates = ["Q4-2010", "Q1-2011", "Q2-2011", "Q3-2011", "Q4-2011", "Q1-2012", "Q2-2012", "Q3-2012","Q4-2012"]; | |
var dateParsed = dates.map(function(d, i){ | |
var splitted = d.split('-'); | |
var quarterEndMonth = splitted[0].charAt(1) * 3; | |
var quarterStartMonth = quarterEndMonth - 3; | |
return [d3.time.format('%m %Y').parse(quarterStartMonth + ' ' + splitted[1]), | |
d3.time.format('%m %Y').parse(quarterEndMonth + ' ' + splitted[1])]; | |
}); | |
console.log(JSON.stringify(dateParsed)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment