FAQ
Hello! I have a task set up to show my first calendar event of the day using the JavaScript below, but it pulls up 24 hour time and I can't get it to show 12 hour time. I'm not familiar with JavaScript at all, so I tried googling and adjusting it and testing with no luck. Can anyone let me know what I'm doing wrong?




function checkCalendar()
{
    var dateparts = tk.global('DATE').split('-');
    var time = tk.global('TIME');
    var date = dateparts[2] + "-" + dateparts[0] + "-" + dateparts[1];
    // startMin becomes today's date at the current time
    var startMin = date + "T" + time.split(".").join(":") + ":00-05:00";
    // startMax becomes today's date at midnight
    var startMax = date + "T23:59:59-05:00";

    // replace these with your values
    var username = "username";
    var key = "key";

        $.ajax({
                url: "https://www.google.com/calendar/feeds/" + username + "%40gmail.com/private-" + key + "/full?singleevents=true&orderby=starttime&sortorder=ascending&q=appt&start-min=" + escape(startMin) + "&start-max=" + escape(startMax),
                type: "GET",
                dataType: "xml",
                async: false,
                success: function(data) {
                        // count number of entries returned
                        var entries = $(data).find("entry");
                        var numResults = entries.length;

                        if (numResults != 0) {
                                // if there are entries, pull the next description and start time
                                var nextEntry = entries.first().find("title").first().text();
                                var nextEntryStart = entries.first().find("when").first().attr('startTime');

                                // if statement is for error handling
                                if (typeof nextEntryStart == "undefined")
                                        nextEntryStart = "";
                            else
                                        nextEntryStart = nextEntryStart.substring(11,16);

                                // set the output
                                caloutput = nextEntry + " at " + nextEntryStart;
                        } else {
                                // return blank, you can also set this to something like "You have no appointments today."
                                caloutput = "";
                        }
                },
                error: function(error){
                        tk.flash('Error fetching calendar.');
                        caloutput = "Error fetching calendar.";
                }
        });
}

var caloutput = '';
checkCalendar();
// before we exit, set a global variable with the output
tk.setGlobal('Caltext', caloutput);

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Brandon Horwath at May 10, 2014 at 6:38 pm
    If you get the value into a variable, here's how tasker could do it. (Don't really know java either)

      A1: Variable Set [ Name:%time To:%TIME Do Maths:Off Append:Off ]
      A2: Variable Split [ Name:%time Splitter:. Delete Base:Off ]
      A3: If [ %time1 < 12 ]
      A4: Variable Set [ Name:%time3 To:am Do Maths:Off Append:Off ]
      A5: Else
      A6: Variable Set [ Name:%time3 To:pm Do Maths:Off Append:Off ]
      A7: End If
      A8: Variable Subtract [ Name:%time1 Value:12 ] If [ %time1 > 12.59 ]
      A9: Flash [ Text:%time1:%time2 %time3 Long:Off ]

    Sorry it's not exactly what you're looking for :(

    --
    You received this message because you are subscribed to the Google Groups "Tasker" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to tasker+unsubscribe@googlegroups.com.
    Visit this group at http://groups.google.com/group/tasker.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptasker @
categoriesandroid
postedMay 10, '14 at 5:34p
activeMay 10, '14 at 6:38p
posts2
users2
websitetasker.dinglisch.net

2 users in discussion

Heather: 1 post Brandon Horwath: 1 post

People

Translate

site design / logo © 2022 Grokbase