From 84bebc9569f4c4e8236749376acf4d4177d5ac1c Mon Sep 17 00:00:00 2001
From: Sebastian Lasse
Date: Sat, 19 Nov 2016 20:30:01 +0100
Subject: [PATCH 1/2] Parse truncated dates as such
fixes https://github.com/glennjones/microformat-node/issues/38
---
lib/index.js | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index 861b6b2..93c4b09 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -985,7 +985,7 @@ var Modules = (function (modules) {
if(uf) {
uf.dates.push([className, new modules.ISODate(out).toString( format )]);
}
- return new modules.ISODate(out).toString( format );
+ return new modules.ISODate(out).toString( format ).replace('9999-','--');
}
} else {
return '';
@@ -3231,12 +3231,22 @@ var Modules = (function (modules) {
parts = dateString.match( /(\d\d\d\d)?-?(\d\d)?-?(\d\d)?/ );
if(parts[1]) {
this.dY = parts[1];
- }
- if(parts[2]) {
- this.dM = parts[2];
- }
- if(parts[3]) {
- this.dD = parts[3];
+ if(parts[2]) {
+ this.dM = parts[2];
+ }
+ if(parts[3]) {
+ this.dD = parts[3];
+ }
+ } else {
+ // --MM-DD
+ parts = dateString.match( /(\d\d)-(\d\d)/ );
+ this.dY = '9999';
+ if(parts[1]) {
+ this.dM = parts[1];
+ }
+ if(parts[2]) {
+ this.dD = parts[2];
+ }
}
}
return this.toString(this.format);
@@ -4602,4 +4612,4 @@ module.exports = {
countAsync: Modules.countAsync,
isMicroformatAsync: Modules.isMicroformatAsync,
hasMicroformatsAsync: Modules.hasMicroformatsAsync
-}
\ No newline at end of file
+}
From bf80c21a1013d7cb3b29d2a16a419d8462b41221 Mon Sep 17 00:00:00 2001
From: Sebastian Lasse
Date: Sat, 19 Nov 2016 21:06:06 +0100
Subject: [PATCH 2/2] better fix ...
better fix for https://github.com/glennjones/microformat-node/issues/38
---
lib/index.js | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index 93c4b09..0439a15 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -985,7 +985,7 @@ var Modules = (function (modules) {
if(uf) {
uf.dates.push([className, new modules.ISODate(out).toString( format )]);
}
- return new modules.ISODate(out).toString( format ).replace('9999-','--');
+ return new modules.ISODate(out).toString( format );
}
} else {
return '';
@@ -3240,13 +3240,20 @@ var Modules = (function (modules) {
} else {
// --MM-DD
parts = dateString.match( /(\d\d)-(\d\d)/ );
- this.dY = '9999';
if(parts[1]) {
this.dM = parts[1];
}
if(parts[2]) {
this.dD = parts[2];
}
+ var _d = new Date(['9999',this.dM,this.dD].join('-'));
+ var _now = new Date();
+ var _y = _now.getFullYear();
+ if (_d.getMonth() === _now.getMonth()) {
+ this.dY = (_d.getDate() < _now.getDate()-1) ? (_y+1) : _y;
+ } else {
+ this.dY = (_d.getMonth() < _now.getMonth()) ? (_y+1) : _y;
+ }
}
}
return this.toString(this.format);