Skip to content

Commit

Permalink
Fixed date parse for every browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
hotoo committed Sep 26, 2014
1 parent d11d2da commit 4ff5774
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions markline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,34 @@ function Markline(element, markdown_filepath){
}

// @param {String} date
function parseDate(date){
if (!date) {
function parseDate(date_string){

if (!date_string) {
return new Date();
}
return new Date(date.replace(/\-/g, "/").replace("T", " "));
}

var RE_YEAR = /^\d{4}$/;
var RE_MONTH = /^\d{4}[\/\-]\d{1,2}$/;
var RE_DATE = /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/;
// year month date hour minute second
var RE_DATE = /^(\d{4})(?:[/-](\d{1,2})(?:[/-](\d{1,2})(?:[T ](\d{1,2})(?::(\d{1,2})(?::(\d{1,2}))?)?)?)?)?$/;

var match = date_string.match(RE_DATE);
if (!match){return;}

var year = match[1];
var month = match[2] || 0;
var date = match[3] || 1;
var hour = match[4] || 0;
var minute = match[5] || 0;
var second = match[6] || 0;
return new Date(year, month, date, hour, minute, second);
}

// @param {String} date.
function parseDateEnd(date){

var RE_YEAR = /^\d{4}$/;
var RE_MONTH = /^\d{4}[\/\-]\d{1,2}$/;
var RE_DATE = /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/;

var dt = parseDate(date);

if (RE_YEAR.test(date)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markline",
"version": "0.1.1",
"version": "0.1.2",
"description": "Timeline via Markdown",
"keywords": ["Timeline", "Markdown"],
"homepage": "https://github.com/hotoo/markline",
Expand Down

0 comments on commit 4ff5774

Please sign in to comment.