I'm just need to make sure I have this correct. I don't have 30days (or even a day) to test this.
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
I think all I have to do is add this line of code:
var days = "30";
Is this correct? How can I test that this works after 1 minute while still using the days var? I'm not very good at math :x
I can rest easy knowing everything is working.
I am testing every half-minute with the code below.
var days = "0.00034722222";
Related
I'm trying to get the Description of a Site but it's always null in WebsInfo! Can someone please help me understand this? I also tried using OpenWeb but that was messing up the URL that I passed in.
var site = new SPSite(currentWeb.Url);
string url = currentWeb.Url + #"/" + siteName;
var webObject = site.AllWebs;
foreach (var web in webObject.WebsInfo)
{
siteDescription = web.Description;
}
I guess there is a bug in the WebsInfo that has never been resolved!! I ended up using SPWebCollection.
//This will find the current URL and iterate through it's site Collection
var oSiteCollection = new SPSite(SPContext.Current.Web.Url);
//Gets all webs meaning sub webs and their webs.
var collWebsites = oSiteCollection.AllWebs;
foreach (SPWeb web in collWebsites)
{
if (web.ServerRelativeUrl.StartsWith(kpi.BusinessUnitUrl))
{
kpi.BusinessUnitDescription = web.Description;
kpi.SiteSpecificAreaDescription = web.Description;
var collLists = web.Lists;
IterateLists(collLists, false, ref kpi);
}
}
I have a Google Document with only one date in the body of the document. I am trying to write a script that updates the date every 24 hours.
The date in the document is currently set to "11/01/2016" as text, 1 day less than today (12/01/2016). I assumed using a replaceText() would work.
This is my script at the moment.
ScriptApp.newTrigger("myFunction")
.timeBased()
.atHour(24)
.everyDays(1)
.inTimezone("GMT")
function myFunction()
{
var date = Utilities.formatDate(new Date(), "GMT", "dd/MM/yyy");
var doc = DocumentApp.openById("ID of Document");
doc.replaceText(date-1,date) ;
}
What I am doing wrong here?
You can't replace text on document object, you need to get document body. your date is a string, you can't get yesterday by date-1. refer the date conversion too.
function myFunction()
{
var body = DocumentApp.getActiveDocument().getBody();
var d = new Date();
var yesterdayDate = Utilities.formatDate(new Date(d.getTime()-1*(24*3600*1000)), "GMT", "dd/MM/yyy");
var todayDate = Utilities.formatDate(d, "GMT", "dd/MM/yyy");
body.replaceText(yesterdayDate,todayDate) ;
}
I have set a cookie using the jQuery cookie plugin. I've set the expiration on the cookie to one hour, so after that time the cookie is deleted. I want to display the remaining time left until the cookie expires to the user by retrieving this info from the cookie itself. is this possible using the jQuery cookies plugin? If not is there an eloquent way to achieve this?
I've set the expiration in this way:
jQuery.cookie('Cookie', timedCookie, { expires: new Date(+new Date() + (60 * 60 * 1000)) });
It's impossible to get a cookie's expiration using JavaScript. The only way to do this would be to store the expiration date somehow, such as in a javascript variable or in another cookie or local storage.
Here's an example:
var MINUTES = 1000 * 60;
var expireTime = new Date(+new Date + (60 * MINUTES)); // store the expiration time
jQuery.cookie('Cookie', timedCookie, { expires: expireTime });
var updateMessage = function(msg){
document.getElementById('time-left').innerHTML = msg;
};
var i = setInterval(function(){ // calculate time difference every ~1 min
var timeLeft = expireTime - new Date;
if(timeLeft <= 0){
updateMessage('Your session has expired.');
clearInterval(i);
} else {
updateMessage('You have ' + (timeLeft / MINUTES | 0) + ' minute(s) left in your cookied session.');
}
}, MINUTES);
Here is my code and I can't figure out why replaceText() isn't working.
function createDoc(){
var templateid = "1jM-6Qvy47gQ45u88WfDU_RvfuSTsw27zBP_9MfsUGr8"; // get template file id
var FOLDER_NAME = "Completed Rental Agreements"; // folder name of where to put doc
// get the data from an individual user
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var data = sheet.getRange(2, 1, sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
var lastRow = sheet.getLastRow();
var firstName = sheet.getRange(lastRow, 2, 1,1).getValues();
var lastName = sheet.getRange(lastRow, 3, 1,1).getValues();
var guestEmail = sheet.getRange(lastRow, 7, 1,1).getValues();
var companyEmail = "bearlakeprojectmanagement#yahoo.com";
var companyName = "Bear Lake Project Management";
var username = "jared.hislop.test#gmail.com"; // get their email (from sheet name)
var me = "jared.hislop.test#gmail.com";
//Copy Template
var docid = DocsList.getFileById(templateid).makeCopy("Rental Agreement - "+firstName+""+lastName+"-"+guestEmail).getId();
// var file = DocsList.getFileById(docid).addEditors(me);
// move file to right folder
var file = DocsList.getFileById(docid);
var folder = DocsList.getFolder(FOLDER_NAME);
file.addToFolder(folder);
var doc = DocumentApp.openById(docid);
var body = doc.getActiveSection();
var body_text = doc.addEditor("jared.hislop.test#gmail.com");
// Append Cabin Rules
// doc.appendParagraph("This is a typical paragraph.");
body.replaceText("/^companyEmail$/", "test");
body.replaceText("%companyName%", "test1");
body.replaceText("%todayDate%", "test1");
doc.saveAndClose();
}
I've tried doc.replaceText and body.replaceText along with several other options.
Any ideas why this isn't working?
Thank in advance
Consider this:
body.replaceText("%companyName%", "test1");
That will look for every instance of "companyName" with "%" on either side of it. The "%" in this case is just that, a piece of punctuation in a strange place. This is a convention used to decrease the likelihood of accidentally replacing real text in the document.
Your template document must have that exact pattern for the replacement to work. (Yours doesn't... instead you have just "companyName". Change it to "%companyName%".) Apply that rule for any other replacement you want to make.
You could benefit from some optimization.
...
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// Next line is hard to maintain - there's a better way.
// var data = sheet.getRange(2, 1, sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
// Read whole spreadsheet, skip headers
var data = sheet.getDataRange().getValues().slice(1);
// Already read in all data, use it instead of reading sheet again.
var firstName = data[data.length-1][2-1]; // (2-1) because array counts from 0
var lastName = data[data.length-1][3-1]; // while spreadsheet columns from 1
var guestEmail = data[data.length-1][7-1]; // Better: put these into variables.
...
While experimenting with your code, I ran into an autocompletion issue with doc.getActiveSection(). It turns out that there has been a recent change, according to the release notes for April 15 2013.
Renamed Document.getActiveSection() to getBody().
You should update your code accordingly.
I want to disable a range of dates which I are fetched using Ajax. I'm doing it as follows -
$("#date_frm").datepicker({
dateFormat: 'yy-mm-dd',
constrainInput: true,
beforeShow:function(input, inst) {
$.ajax({
type: "POST",
url: "/admin/get_time_span",
data: "",
success: function(data) {
disabled_day = data;
},
});
},
beforeShowDay: disableRangeOfDays
});
function disableRangeOfDays(d)
{
//var arr = "2012-04-19 to 2012-04-26,";
var arr = disabled_day.split(",");
var arr = arr.split(",");
var cnt = arr.length-1;
for(i=0; i<cnt; i++) {
arr1 = arr[i].split(" to ");
//create date for from_date
frm_dt = arr1[0].split('-');
//create date for to_date
to_dt = arr1[1].split('-');
if(d >= new Date(frm_dt[0],(frm_dt[1]-1),frm_dt[2]) &&
d <= new Date(to_dt[0],(to_dt[1]-1),to_dt[2])) {
return [false];
}
}
return [true,''];
}
This works but not for the first time. When I open the date picker first time, the date range still selectable. But, after I close and reopen it, the date range is disabled. Also, if I change the month and come back to the current month then also it works. How can I disable the date range for the first time I open the date picker ? Also, for each month, I want to fetch the date ranges and disable them. How can I do this ?
After spending much time in checking possibilities, I fetched all the date ranges only once while loading the page and assigned all to a hidden field. I removed the Ajax call and used the value of the hidden field directly in the function disableRangeOfDays(d) and it worked as expected.