0

I'm querying a google calendar using json, then posting the resulting data to a php file using ajax, which formats the dates, then returns them as the following string of arrays:

["2014-03-06"]["2014-05-01","2014-05-02","2014-05-03","2014-05-04","2014-05-05"]["2014-02-21"]

I then need to get this string of arrays and somehow make it into this:

var arDates = [new Date("2014-02-21").valueOf(),new Date("2014-03-06").valueOf(),new Date("2014-05-01").valueOf(),new Date("2014-05-02").valueOf(),new Date("2014-05-03").valueOf(),new Date("2014-05-04").valueOf(),new Date("2014-05-05").valueOf()];

... so that I can disable some dates in a jquery datepicker.

This question follows on from a previous question i posted - jQuery PickMeUp datepicker: disable array of dates

Any ideas how I do this please? Full code below: (including a few things i've already tried unsuccessfully.

        $j=jQuery.noConflict(); 
        $j(document).ready(function(){                      
            var eventName = '';
            var gclaData = 'http://www.google.com/calendar/feeds/hello%40freestretch.co.uk/public/basic?orderby=starttime&sortorder=ascending&max-results=8&futureevents=true&alt=json';
            $j.getJSON(gclaData,function(data){
                for(var i = 0; i < data.feed.entry.length; i++){
                    eventName += data.feed.entry[i].summary.$t+"</br>";
                }                                   
                $j.ajax({
                    type: 'POST',
                    url: 'myprocess.php',
                    data: {'dates': eventName},
                    success: function(gcdates) {
                        // returned data is: ["2014-03-06"]["2014-05-01","2014-05-02","2014-05-03","2014-05-04","2014-05-05"]["2014-02-21"]
                        var str = gcdates.replace(/]/g, ",");
                        str = str.replace(/\[/g, "");
                        var lastChar = str.slice(-1);
                        if(lastChar == ',') {
                            str = str.slice(0, -1);
                        }                                   
                        //var match = str.split(',');
                        //console.log(str)
                        /*for (var a in match){
                            var mynewdate = match[a];
                            //mynewdate = 'new Date(' + mynewdate + ').valueOf()';
                            //console.log(mynewdate)
                        }   */
                        //console.log(str);                     
                        var arDates = [new Date("2014-02-21").valueOf(),new Date("2014-03-06").valueOf(),new Date("2014-05-01").valueOf(),new Date("2014-05-02").valueOf(),new Date("2014-05-03").valueOf(),new Date("2014-05-04").valueOf(),new Date("2014-05-05").valueOf()];
                        //console.log(arDates)                                              
                        $j('input#cdate').pickmeup({
                            position  : 'right',                                        
                            mode      : 'range',                            
                            render: function(date) {
                                return {                                    
                                    disabled: arDates.indexOf(date.valueOf()) != -1                             
                                }
                            }                           
                        });                                     
                    }
                });           
            }); 
        }); 
1
  • What format are your dates in? Strings? An array of strings? How are you getting the dates? What have you tried? What are you stuck on? What is the problem here? Commented Feb 21, 2014 at 22:02

1 Answer 1

1

Why is jquery needed here? A simple loop can solve this

var source = ["2014-03-06","2014-05-01","2014-05-02"];
var dest = [];
for (var i in source) {
  dest.push(new Date(i).valueOf());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.