Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added getUpdatedDate to fetch updated info of a post

  • Loading branch information...
commit 8b66825cd9a3de75e93b88c7a20fa9fad55ba974 1 parent 4fc96c1
andris9 authored
Showing with 57 additions and 3 deletions.
  1. +36 −2 lib/nodepie.js
  2. +1 −1  package.json
  3. +20 −0 test/npm-debug.log
View
38 lib/nodepie.js
@@ -749,7 +749,7 @@ NodePie.Item.prototype.getTitle = function(){
};
/**
- * NodePie.Item#getTitle() -> Date | False
+ * NodePie.Item#getDate() -> Date | False
*
* Fetches the date of the post as a Date object
*
@@ -757,7 +757,7 @@ NodePie.Item.prototype.getTitle = function(){
*
* var item = np.getItem(0);
* date = item.getDate();
- * console.log(date.getFullYear());
+ * console.log("Created: " + date.getFullYear());
**/
NodePie.Item.prototype.getDate = function(){
var dcns = this.feed.namespaces[NodePie.NS.DC], date;
@@ -782,6 +782,40 @@ NodePie.Item.prototype.getDate = function(){
};
/**
+ * NodePie.Item#getUpdateDate() -> Date | False
+ *
+ * Fetches the update date of the post as a Date object
+ *
+ * Usage:
+ *
+ * var item = np.getItem(0);
+ * date = item.getUpdateDate();
+ * console.log("Updated: " + date.getFullYear());
+ **/
+NodePie.Item.prototype.getUpdateDate = function(){
+ var dcns = this.feed.namespaces[NodePie.NS.DC], date;
+
+ date = this.element.updated || this.element.modified || (dcns && this.element[dcns+":date"]) || false;
+
+ if(!date){
+ // fallback to creation date
+ return this.getDate();
+ }
+
+ date = new Date(date);
+ if(!date.getFullYear()){
+ // fallback to creation date
+ return this.getDate();
+ }
+
+ if(date.getTime() > Date.now()){
+ return new Date();
+ }
+
+ return date;
+};
+
+/**
* NodePie.Item#getDescription() -> String | False
*
* Fetches the description of the post (prefers summaries)
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "nodepie",
"description": "RSS/Atom parser for Node.JS",
- "version": "0.2.3",
+ "version": "0.3.0",
"author" : "Andris Reinman",
"maintainers":[
{
View
20 test/npm-debug.log
@@ -0,0 +1,20 @@
+info it worked if it ends with ok
+verbose cli [ 'node', '/usr/local/bin/npm', 'publish' ]
+info using npm@1.0.18
+info using node@v0.5.4
+verbose config file /root/.npmrc
+verbose config file /usr/local/etc/npmrc
+verbose publish [ '.' ]
+ERR! Could not install: .
+ERR! Error: ENOENT, No such file or directory 'package.json'
+ERR! Report this *entire* log at:
+ERR! <http://github.com/isaacs/npm/issues>
+ERR! or email it to:
+ERR! <npm-@googlegroups.com>
+ERR!
+ERR! System Linux 2.6.18-028stab091.2
+ERR! command "node" "/usr/local/bin/npm" "publish"
+ERR! cwd /root/nodepie/test
+ERR! node -v v0.5.4
+ERR! npm -v 1.0.18
+verbose exit [ 2, true ]
Please sign in to comment.
Something went wrong with that request. Please try again.