Re: RSS feed with JS is displaying old dates

85 views
Skip to first unread message

Jeremy Geerdes

unread,
Feb 21, 2013, 1:02:39 PM2/21/13
to google-ajax...@googlegroups.com
Well, I haven't completely gone through your code, but here are a couple of thoughts for you.

First, you might want to produce a page which reproduces this issue with only the bare minimum code. There seems to be a lot of extraneous stuff.

Second, once you've produced that page, post a link to it rather than the code itself. This allows us to utilize debugging tools and makes helping you immensely easier.

Third, RSS in general struggles with future dates. You might want to consider something different.

Finally, you say that the feed is only accessible internally. If that's the case, then the Feeds API will be totally useless to you. It has to be able to access the feed, or it won't be able to cache it.

If you could at least work on the first two of these things, I would be happy to take a look and see if I can help.

jg

On Thu, Feb 21, 2013 at 10:54 AM, Thomas Palumbo <thoma...@gmail.com> wrote:

The RSS feed has no dates on it at all. However once this code runs, it will still display old dates/events anyways. I have been working on this for awhile with no avail.

The actual RSS feed isn't view able to those outside the network but here is the JS.

I want ONLY future dates. As of now a display_all gives me dates back from January and then only 1 future date.



here is the code: 


(function($){

var source = {

  init: function(o){


    /*-----------------   Configuration   ------------------------*/

    var filter_by   = o.filter_by;
    var filter_by_2 = o.filter_by_2; 
    var count       = o.count;
    var feed_url    = o.feed_url;
    var link_url    = o.link_url
    var display_all = o.display_all; //Set to 'true' to display all calendar entries without filters

    /*----------------- end Configuration  ------------------------*/

    /*----------------- No need to edit below this line  ------------------------*/

    //Preloader
    $('div#calendar').prepend('<div id="loading"></div>');

    //Months to be used
    var month_names = new Array ();
    month_names[month_names.length] = "Jan";
    month_names[month_names.length] = "Feb";
    month_names[month_names.length] = "Mar";
    month_names[month_names.length] = "Apr";
    month_names[month_names.length] = "May";
    month_names[month_names.length] = "Jun";
    month_names[month_names.length] = "Jul";
    month_names[month_names.length] = "Aug";
    month_names[month_names.length] = "Sep";
    month_names[month_names.length] = "Oct";
    month_names[month_names.length] = "Nov";
    month_names[month_names.length] = "Dec";

    //days of the week
    var day_of_week = new Array ();
    day_of_week['1'] = "Monday";
    day_of_week['2'] = "Tuesday";
    day_of_week['3'] = "Wednesday";
    day_of_week['4'] = "Thursday";
    day_of_week['5'] = "Friday";
    day_of_week['6'] = "Saturday";
    day_of_week['7'] = "Sunday";

    //Fix timezone issue
    Date.prototype.addHours= function(h){
        this.setHours(this.getHours()+h);
        return this;
    }

    //function to format time
    function formatTime(date) {
        //Change this "-5" to "-4" when the timezone changes
        var d  = new Date(date).addHours(-5);
        var hh = d.getUTCHours();
        var m  = d.getMinutes();
        var dd = "am";
        var h  = hh;

        //Day of the week
        var day = day_of_week[d.getDay(date)];

        //hours to am pm
        if(hh > 12){
            hh = hh-12;
            dd = "pm"
        } 

        //minutes
        m = m<10?"0"+m:m;

        return(day + ' at ' + hh + ':' + m + dd );
    }

    new Date(0).toString()
    //function to convert plain text to links
    function replaceURLWithHTMLLinks(text) {
        var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
        return text.replace(exp,"<a href='$1'>$1</a>"); 
    }

    //Load the feed
      google.load("feeds", "1");

    //For espacing html characters
      // String.prototype.unescapeHtml = function () {
      //   var temp       = document.createElement("div");
      //   temp.innerHTML = this;
      //   var result     = temp.childNodes[0].nodeValue;
      //   temp.removeChild(temp.firstChild);
      //   return result;}

    // Our callback function, for when a feed is loaded.
    function feedLoaded(result) {

      if (!result.error) {

        // Grab the container we will put the results into
        var content = document.getElementById("calendar");
        var html    = '';

        // Get current height of container div then set it manually (for animation later)
        var containerHeight = $(content).outerHeight();
        $(content).css({height: containerHeight});

        //Function that removes date from begining of title string
        function removeDateTitle(strValue){
            var string = strValue.substr(16);
            var string = $.trim(string);
            return string;
        };

        function removeDateDesc(strValue){
            var string = strValue.substr(25);
            var string = $.trim(string);
            return string;
        };

        // Check out the result object for a list of properties returned in each entry.
        // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON

        for (var i = 0; i < result.feed.entries.length; i++) {


          var entry           = result.feed.entries[i];
        console.log(result.feed.entries.length);
          //RegEx queries for 'match' method
          var filter_by_REG   = RegExp(filter_by, 'i');
          var filter_by_2_REG = RegExp(filter_by_2, 'i');

          var cond1           = result.feed.entries[i].title.match(filter_by_REG);
          var cond2           = result.feed.entries[i].title.match(filter_by_2_REG);
          var today           = new Date;
          var pubDate         = new Date(entry.publishedDate);

        console.log("pubdate = " + pubDate + "todays" + today);



          //Display All items
          if(display_all){

            cond1 = true; cond2 = true;

          }



          //Query entries for matches and add them to "entry" array for display      
          if(cond1 || cond2 ){

            var pubDate     = new Date(entry.publishedDate);

            var pubMonth    = month_names[pubDate.getMonth()];
            var pubdateNum  = pubDate.getDate();
            var href        = 'http://calendargoeshere.aspx';//entry.link;
            var title       = removeDateTitle(entry.title);
            var location    = entry.categories[0];
                if(location != undefined){
                    location    = location.replace(/[+]/g ," ");
                }


            var time        = formatTime( entry.publishedDate );
            var desc = entry.content; 
                desc = removeDateDesc(desc);
                desc_short = desc.split(" ").splice(0, 25).join(" ");
                desc_short += "...";


            var fb_url ='<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.facebook.com/f&action=recommend" scrolling="no" frameborder="0" class="fb_like_btn"></iframe>';

            // Output
            html += '<div class="calentry' + ' tooltip_' + i + '">' + '<div class="calcon">' + '<div class="caltop">' + pubMonth + '</div>' + '<div class="calbottom">' + 
            pubdateNum + '</div>' + '</div>' + '<div class="description"><h3 class="calhead"><a href="' + href + '" target="_blank">' + title + '</a></h3>' + 
            '<div class=callocation>' + time + ' in ' + location + '</div>' + '<p>' + desc_short + '<br />' + 
            '</p></div><div class="clear"></div>' + '</div>';

            //QtipContent
            html += '<div style="display: none;">' + 
            '<b>Full Description:</b><br />' + replaceURLWithHTMLLinks(desc) + '<br />' +
            '<p><b>Time: </b>' + time + '<br />' +
            '<b>Location: </b>' + location +
            '</p>' + fb_url +'</div>';
            //throw new Error(html);
            //update content
            content.innerHTML = html;

          }




        }//end loop


        //Display message when no feed items found
        if(html == ''){
          html += '<p class="cal_noEvents">No events currently scheduled.</p>';
          content.innerHTML = html;
        }

        //Hide PreLoader
        $('#loading').fadeOut('slow');

        //Animate loaded content
        $(content).wrapInner('<div class="calendarInner" />'); //wrap with inner div
        var contentHeight = $('.calendarInner').outerHeight();// Get the height of the content div.
        contentHeight = contentHeight;
        $(content).animate({height:contentHeight}, 1000); // Animate the height 
        $('.calendarInner').css('width','100%'); //Fix border line issue after animation

        //Qtip

        var cal_items 
        $('.calentry').each(function() {
            var thisEntry = $(this);

            thisEntry.qtip(
            {
                content: {
                    text: thisEntry.next('div:hidden'),
                    title: {
                        text: thisEntry.find('h3').text(),
                        button: true
                    }
                },
                position: {
                    my: 'center', // ...at the center of the viewport
                    at: 'center',
                    target: $(window)
                },
                show: {
                    event: 'click', // Show it on click...
                    solo: true, // ...and hide all other tooltips...
                    modal: true // ...and make it modal
                },
                hide: false,
                style: {
                    classes: 'ui-tooltip-light ui-tooltip-rounded',
                    width: 500
                }
            });   
        }).bind('click', function(event){ event.preventDefault(); return false; }); 
        //end qtip 


      }

    }
    function OnLoad() {
      // Create a feed instance that will grab the feed.
      var feed = new google.feeds.Feed(feed_url);
      feed.setNumEntries(count);

      // Calling load sends the request off.  It requires a callback function.
      feed.load(feedLoaded);

    }

    google.setOnLoadCallback(OnLoad);


  } //end init

};

$.fn.extend({ 

    //pass the options variable to the function
    calendar: function(options) {


        //Set the default values, use comma to separate the settings, example:
        var defaults = {
            filter_by   : false,
            filter_by_2 : false,
            count       : 5,
            display_all : false,
            feed_url    : 'noFeed',
            link_url    : 'http://calendarrssfeedhere.aspx'
        }

        var options =  $.extend(defaults, options);

            var o = options;

            //Call the init method (get the ball rollin) -- passing options 'o'
                source.init(o);
    }
});

})(jQuery);

--
--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to
google-ajax-searc...@googlegroups.com
To view this message on the web, visit
https://groups.google.com/d/msg/google-ajax-search-api/-/Hm_vUIsEK_gJ
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-searc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

Thomas Palumbo

unread,
Feb 26, 2013, 10:58:51 AM2/26/13
to google-ajax...@googlegroups.com
The site can be found here: http://cge.fsu.edu you can see the "no events currently scheduled" at the bottom of the page. (Even though there are events in the future.)

The link to the feed is not viewable from the outside but here is the end of the link: &cpath=&rssview=daysfrom&days=31&getdate  (so you can see it is displaying correctly, future dates)

And I can attach the javascript file if you need that.


Reply all
Reply to author
Forward
0 new messages