TODAY FUNCTION IN EMEDITOR - emeditor

Please how do i get "today's date function" into a Column on Emeditor? Similar to Excel

You can use a JavaScript macro like this:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
document.write( mm + '/' + dd + '/' + yyyy );

Related

Google appscipt - Exporting multiple PDF with a for loop, using a sheet as a template, unexpected result

I'm trying to automate the pdf export of a sheet ('BL') which is filled depending on a cell value grabbed on a variable list on sheet 'EiBLdata' by 'i' on each loop.
It seems to work... more or less.
Instead of having 1st pdf with 1st value,
2nd pdf with 2nd value,
3rd pdf with 3rd value etc.
I get 1st pdf with 1st value,
2nd pdf with 1st value,
3rd pdf with 2nd value etc.
In the end only the 1st pdf has the right name, there is a shift in all the others and the last value isn't exported.
I'm quite a newbie with JavaScript and I admit there is a lot of copy/paste in my code, adapted to my purpose. I can't find what I'm doing wrong.
function printSelectedRange() {
var nomfeuille = "EiBLData"
var nomBL = "BL"
var cc = SpreadsheetApp.getActiveSpreadsheet();
var feuille = cc.getSheetByName(nomfeuille);
var BL = cc.getSheetByName(nomBL);
var tr = BL.getRange('B2').getValue();
var plage = feuille.getRange('A1:A15').getValues();
var cell0 = feuille.getRange(1,1).getValue();
BL.getRange('B2').setValue(cell0);
for (var i = 1; i <= 16; i++) {
var cell = feuille.getRange(i,1).getValue();
if (cell > 0) {
BL.getRange('B2').setValue(cell)
var sheetName = "BL";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
var ssUrl = ss.getUrl();
var sheetId= sheet.getSheetId();
var url = ssUrl.replace(/\/edit.*$/,'')
+ '/export?exportformat=pdf&format=pdf'
+ '&size=A6'
+ '&portrait=false'
+ '&fitw=false'
+ '&scale=4'
+ '&top_margin=0.35'
+ '&bottom_margin=0.00'
+ '&left_margin=0.35'
+ '&right_margin=0.0'
+ '&sheetnames=false'
+ '&printtitle=false'
+ '&pagenum=false'
+ '&gridlines=false'
+ '&fzr=FALSE'
+ '&gid='+sheetId;
var token = ScriptApp.getOAuthToken();
var docurl = UrlFetchApp.fetch(url, { headers: { 'Authorization': 'Bearer ' + token } });
var pdf = docurl.getAs('application/pdf');
var file = DriveApp.createFile(pdf);
var docId = sheet.getRange('F13').getValue();
var clientName = sheet.getRange('E9').getValue();
var docDate = sheet.getRange('F14').getValue();
var mois = docDate.getMonth()
docDate.setMonth((mois+1) % 12);
var docDateMMYY = docDate.getMonth()+"-"+docDate.getFullYear().toString().substr(-2);
var docName = "BL-"+docId+"-"+clientName+"-"+docDateMMYY ;
var folder = DriveApp.getFolderById("xxxxxxxxxxxxxxxxxxxx");
var finalFile = file.makeCopy(docName,folder);
file.setTrashed(true);
};
};
var cmdes = ss.getSheetByName('cmdes');
var raz = cmdes.getRange('S2:S501').setValue(false);
}
I think I had a good intuition and finally found the reason of my issue:
how-to-pause-app-scripts-until-spreadsheet-finishes-calculation
It looks like the loop runs faster than the spreadsheet calculation.
Sorry for inconvenience...

YouMax video upload date

I've been using the YouMax plugin which enables you to embed your YouTube channel on your website. However, I am having problems as it displays the uploaded date in months and years. I'd like it to display days, weeks, months and years.
You can view the source code here http://jsfiddle.net/wCKKU/
I believe that its this that needs adjusting to make it calculate in day, weeks, months and years.
function getDateDiff(timestamp) {
if (null == timestamp || timestamp == "" || timestamp == "undefined") return "?";
var splitDate = ((timestamp.toString().split('T'))[0]).split('-');
var d1 = new Date();
var d1Y = d1.getFullYear();
var d2Y = parseInt(splitDate[0], 10);
var d1M = d1.getMonth();
var d2M = parseInt(splitDate[1], 10);
var diffInMonths = (d1M + 12 * d1Y) - (d2M + 12 * d2Y);
if (diffInMonths <= 1) return "1 month";
else if (diffInMonths < 12) return diffInMonths + " months";
var diffInYears = Math.floor(diffInMonths / 12);
if (diffInYears <= 1) return "1 year";
else if (diffInYears < 12) return diffInYears + " years"
}
You could modify the plugin by a small block of code in the middle of the function:
var d2M = parseInt(splitDate[1], 10); // this line is already there
var d1D = d1.getDate();
var d2D = parseInt(splitDate[2],10);
var diffInDays = (d1D + 30 *d1M + 12 * d1Y) - (d2D + 30 *d2M + 12 *d2Y);
if (diffInDays < 2) return "1 day";
else if (diffInDays < 7) return diffInDays+" days";
else if (diffInDays > 7 && diffInDays < 14) return "1 week";
else if (diffInDays > 14 && diffInDays < 30) return Math.floor(diffInDays / 7) + " weeks";
var diffInMonths = (d1M + 12 * d1Y) - (d2M + 12 * d2Y); // this line is already there
Note that this isn't a particularly elegant way to handle the issue, but it matches the coding style the plugin is already using, and at least won't break anything else.
Also, as a side comment, if you're modifying the plugin code you'll want to fix a bug in it at the same time. Getting the current month should look like this:
var d1M = d1.getMonth() + 1;
This is because in Javascript, the getMonth() function returns the month on a zero-based index, and your math won't be reliable unless you switch it to a one-based index.

Adding a variable to a Vertical Panel in GAS

I am working on a master sheet which should have a UiApp embedded into the active sheet. I have tried coding the first part with the labels in the first row, but I am stuck with getting the names[i] to appear on the left hand side of the table under the Tasks label.
I intend to make check boxes appear for every name under each task label.
Here is the code below:
function showTable()
{
var ss = SpreadsheetApp.getActive();
var TL = ss.getRange('B3').getValue();
//SetFontWeight("bold") for TL < *This does not work either* >
var startDate = ss.getRange('B2').getValue();
var strStartDate = startDate.getDate() + "/" + (startDate.getMonth() + 1) + "/" + StartDate.getFullYear();
var counta = ss.getRange('B4').getValue();
var app = UiApp.createApplication().setHeight(375).setWidth(620)
.setTitle('This is ' + TL + "'s Team Tasks for " + strStartDate);
var panel = app.createAbsolutePanel().setId('panel').setHeight(355).setWidth(605)
.setStyleAttribute('background', 'lightCyan');
var names = ss.getRange('B11:B').getValues();
for (var i = 0; 0 < names.length; i++) **//This is the part that does not work**
{
var agents = app.createLabel(names[i]);
}
var handler1 = app.createServerHandler('btnCloseWindow');
var btnCloseWindow = app.createButton('Close Window').addClickHandler(handler1).setStyleAttribute('background', 'lightYellow');
handler1.addCallbackElement(panel);
var myLabel0 = app.createLabel('Tasks');
var myLabel1 = app.createLabel('HW');
var myLabel2 = app.createLabel('MU');
var myLabel3 = app.createLabel('MOV');
panel.add(myLabel0, 40, 12)
panel.add(myLabel1, 100, 12)
panel.add(myLabel2, 140, 12)
panel.add(myLabel3, 175, 12)
panel.add(agents, 40, 30)
panel.add(btnCloseWindow, 490, 320)
app.add(panel);
ss.show(app);
return app;
};
function btnCloseWindow(e)
{
var ss = SpreadsheetApp.getActive();
var app = UiApp.getActiveApplication();
app.close();
return app;
};
How do you make a vertical panel with the names?
The names are defined in col B11:B and the tasks are defined in the labels.
This is my first time making a UiApp so any help is very much appreciated!
Try it like this, I don't know how the whole think should look like but the part with the list of names is now right...
function showTable()
{
var ss = SpreadsheetApp.getActive();
var TL = ss.getRange('B3').getValue()
ss.getRange('B3').setFontWeight('bold')
var startDate = ss.getRange('B2').getValue();
var strStartDate = Utilities.formatDate(startDate, ss.getSpreadsheetTimeZone(), 'dd/mm/yyyy');
var counta = ss.getRange('B4').getValue();
var app = UiApp.createApplication().setHeight(375).setWidth(620)
.setTitle('This is ' + TL + "'s Team Tasks for " + strStartDate);
var panel = app.createAbsolutePanel().setId('panel').setHeight(355).setWidth(605)
.setStyleAttribute('background', 'lightCyan');
var handler1 = app.createServerHandler('btnCloseWindow');
var btnCloseWindow = app.createButton('Close Window').addClickHandler(handler1).setStyleAttribute('background', 'lightYellow');
handler1.addCallbackElement(panel);
var myLabel0 = app.createLabel('Tasks');
var myLabel1 = app.createLabel('HW');
var myLabel2 = app.createLabel('MU');
var myLabel3 = app.createLabel('MOV');
panel.add(myLabel0, 40, 12)
panel.add(myLabel1, 100, 12)
panel.add(myLabel2, 140, 12)
panel.add(myLabel3, 175, 12)
var names = ss.getRange('B11:B').getValues();
Logger.log(names)
for(i=0;i<names.length;++i){
Logger.log(names[i][0]);// names is a 2D array, you only want the first and only column
if(names[i][0]!=''){ // don't show if empty
panel.add(app.createLabel(names[i][0])); //add label to the panel
}
}
panel.add(btnCloseWindow, 490, 320)
app.add(panel);
ss.show(app);
};
var names = ss.getRange('B11:B').getValues();
Should be,
var names = ss.getRange('B11:B1').getValues();
How I researched,
var data = ss.getRange("b11:b1").getValues();
data.forEach(function(element,index,array){Logger.log(index + " " + element )});
Logs, "0 dog
1 cat
2 frog
3 fish
4 hamster
5 dog
6 cat
7 frog
8 fish
9 hamster
10 dog"

How to generate random fixed interval within date range in JMeter?

I have StartDate (for instance 2011-01-01) and EndDate (for instance 2011-12-31).
All my data are placed in this range.
In test plan I need to generate random interval with fixed duration
(for 4 cases: 1, 3, 7 days and 1 month long)
which are placed in this date range [2011-01-01; 2011-12-31].
Each of these cases must have defined weights.
How should I do to get fixed interval with random Start Date and random End Date (and put these random dates into 2 variables)?
I have found this variant of java-script
The initial script is here:
var startDate = new Date();
startDate.setDate(1);
startDate.setMonth(0);
startDate.setYear(1991);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(11);
endDate.setYear(2003);
var endDateTime = endDate.getTime();
var randomDate = new Date();
var randomDateTime = startDateTime+Math.random()*(endDateTime-startDateTime);
randomDate.setTime(randomDateTime);
var rndDate = randomDate.getDate();
var rndMonth = randomDate.getMonth() + 1;
var rndYear = randomDate.getFullYear();
if (rndDate.toString().length == 1)
rndDate = "0" + rndDate;
if (rndMonth.toString().length == 1)
rndMonth = "0" + rndMonth;
rndDate + "/" + rndMonth + "/" + rndYear;
But I need generate random start date of the fixed interval (which I called ${RandomStartDate}) and then to add the length of the interval to get the end date of it (this date I called ${RandomEndDate}).
Then I have change the script for 1 day long interval (1 day is 86400 seconds):
var startDate = new Date();
startDate.setDate(01);
startDate.setMonth(01);
startDate.setYear(2011);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(12);
endDate.setYear(2011);
var endDateTime = endDate.getTime();
var randomSDate = new Date();
var randomSDateTime = startDateTime+Math.random()*((endDateTime - 86400) -startDateTime );
randomSDate.setTime(randomSDateTime);
var randomEDate = new Date();
var randomEDateTime = (randomSDateTime + 86400); //add 1 day long interval (86400 s)
randomEDate.setTime(randomEDateTime); //convert number format to string format of date
var rndSDate = randomSDate.getDate();
var rndSMonth = randomSDate.getMonth()+1 ;
var rndSYear = randomSDate.getFullYear();
var rndEDate = randomEDate.getDate();
var rndEMonth = randomEDate.getMonth()+1 ;
var rndEYear = randomEDate.getFullYear();
if (rndSDate.toString().length == 1)
rndSDate = "0" + rndSDate;
if (rndSMonth.toString().length == 1)
rndSMonth = "0" + rndSMonth;
if (rndEDate.toString().length == 1)
rndEDate = "0" + rndEDate;
if (rndEMonth.toString().length == 1)
rndEMonth = "0" + rndEMonth;
var RandomStartDate = rndSYear + "-" + rndSMonth + "-" + rndSDate;
vars.put ("RandomStartDate", RandomStartDate);
var RandomEndDate = rndEYear + "-" + rndEMonth + "-" + rndEDate;
vars.put ("RandomEndDate", RandomEndDate);
But this script generates RandomEndDate which is equal to RandomStartDate.
If I generate RandomStartDate separately (without the parts of code which are connected with RandomEndDate) the script works good.
Could you help me, please? What is wrong?
You can do it in Beanshell with much less amount of code:
import java.text.SimpleDateFormat;
import java.util.Calendar;
calendar = Calendar.getInstance();
calendar.set(2011, 0, 1);
startTime = calendar.getTimeInMillis();
calendar.set(2012, 11, 31);
endTime = calendar.getTimeInMillis();
randomTime1 = startTime + (long)(Math.random()*(endTime-startTime));
randomTime2 = randomTime1 + (long)(Math.random()*(endTime - randomTime1)+86400000);
formatter = new SimpleDateFormat("yyyy-MM-dd");
calendar.setTimeInMillis(randomTime1);
vars.put("start", formatter.format(calendar.getTime()));
calendar.setTimeInMillis(randomTime2);
vars.put("end", formatter.format(calendar.getTime()));
For situations like this I would opt to put the complexity outside of jMeter, and create a perl script to generate 100 pairs of dates according to your requirements and read them into jMeter variables using CSV Data Set Config.
I have found the solution!
This is the correct script, which allow to model the random interval with fixed length (1 day long interval) and get 2 variables fot it start and end - ${RandomStartDate} and ${RandomEndDate}:
var startDate = new Date();
startDate.setDate(01);
startDate.setMonth(01);
startDate.setYear(2011);
var startDateTime = startDate.getTime();
var endDate = new Date();
endDate.setDate(31);
endDate.setMonth(12);
endDate.setYear(2011);
var endDateTime = endDate.getTime();
var randomSDate = new Date();
var randomSDateTime = startDateTime+Math.random()*((endDateTime - 86400000) -startDateTime );
randomSDate.setTime(randomSDateTime);
var randomEDate = new Date();
var randomEDateTime = (randomSDateTime + 86400000); //add 1 day long interval (86400000 ms)
randomEDate.setTime(randomEDateTime); //convert number format to string format of date
var rndSDate = randomSDate.getDate();
var rndSMonth = randomSDate.getMonth()+1 ;
var rndSYear = randomSDate.getFullYear();
var rndEDate = randomEDate.getDate();
var rndEMonth = randomEDate.getMonth()+1 ;
var rndEYear = randomEDate.getFullYear();
if (rndSDate.toString().length == 1)
rndSDate = "0" + rndSDate;
if (rndSMonth.toString().length == 1)
rndSMonth = "0" + rndSMonth;
if (rndEDate.toString().length == 1)
rndEDate = "0" + rndEDate;
if (rndEMonth.toString().length == 1)
rndEMonth = "0" + rndEMonth;
var RandomStartDate = rndSYear + "-" + rndSMonth + "-" + rndSDate;
vars.put ("RandomStartDate", RandomStartDate);
var RandomEndDate = rndEYear + "-" + rndEMonth + "-" + rndEDate;
vars.put ("RandomEndDate", RandomEndDate);
My mistake was I thought that the time is in seconds, but it is in milliseconds!

Ajax/jQuery Timing Issue

I have a click function that does a jQuery/Ajax $.post to get data from a webservice when a span is clicked. When there is a Firebug break point set on the click function, everything works as expected (some new table tr's are appended to a table). When there is no break point set, nothing happens when you click the span. Firebug doesn't show any errors. I assume from other stackoverflow questions that this is a timing problem, but I don't know what to do about it. I have tried changing from a $.post to a $.ajax and setting async to false, but that didn't fix it. Here's the code for the click handler:
$('.rating_config').click(function(event){
event.preventDefault();
event.stopPropagation();
var that = $(this);
// calculate the name of the module based on the classes of the parent <tr>
var mytrclasses = $(this).parents('tr').attr('class');
var modulestart = mytrclasses.indexOf('module-');
var start = mytrclasses.indexOf('-', modulestart) + 1;
var stop = mytrclasses.indexOf(' ', start);
var mymodule = mytrclasses.substring(start, stop);
mymodule = mymodule.replace(/ /g, '+');
mymodule = mymodule.replace(/_/g, '+');
mymodule = encodeURI(mymodule);
// calculate the name of the property based on the classes of the parent <tr>
var propertystart = mytrclasses.indexOf('property-');
var propstart = mytrclasses.indexOf('-', propertystart) + 1;
var propstop = mytrclasses.indexOf(' ', propstart);
var myproperty = mytrclasses.substring(propstart, propstop);
myproperty = myproperty.replace(/ /g, '+');
myproperty = myproperty.replace(/_/g, '+');
myproperty = encodeURI(myproperty);
var parentspanid = $(this).attr('id');
// Remove the comparison rows if they are already present, otherwise generate them
if ($('.comparison_' + parentspanid).length != 0) {
$('.comparison_' + parentspanid).remove();
} else {
$.post('http://localhost/LearnPHP/webservice.php?user=user-0&q=comparison&level=property&module=' + mymodule + '&version_id=1.0&property=' + myproperty + '&format=xml', function(data) {
var data = $.xml2json(data);
for (var propnum in data.configuration.modules.module.properties.property) {
var prop = data.configuration.modules.module.properties.property[propnum];
console.log(JSON.stringify(prop));
prop.mod_or_config = 'config';
var item_id = mymodule + '?' + prop.property_name + '?' + prop.version_id + '?' + prop.value;
item_id = convertId(item_id);
prop.id = item_id;
//alert('prop.conformity = ' + prop.conformity);
// genRow(row, module, comparison, comparison_parentspanid)
var rowstring = genRow(prop, mymodule, true, parentspanid);
console.log('back from genRow. rowstring = ' + rowstring);
$(that).closest('tr').after(rowstring);
//$('tr#node-' + data[row].id + ' span#rating' + row.id).css('background', '-moz-linear-gradient(left, #ff0000 0%, #ff0000 ' + data[row].conformity + '%, #00ff00 ' + 100 - data[row].conformity + '%, #00ff00 100%');
var conformity_color = getConformityColor(prop.conformity);
$('tr#comparison_module_' + mymodule + '_setting_' + prop.id + ' span#module_' + mymodule + '_rating' + prop.id).css({'background':'-moz-linear-gradient(left, ' + conformity_color + ' 0%, ' + conformity_color + ' ' + prop.conformity + '%, #fffff0 ' + prop.conformity + '%, #fffff0 100%)'});
//$('tr#comparison-' + data[row].id + ' span#rating' + data[row].id).css('background','-webkit-linear-gradient(left, #00ff00 0%, #00ff00 ' + data[row].conformity + '%, #ff0000 ' + (100 - (data[row].conformity + 2)) + '%, #ff0000 100%)');
}
});
// Hide the Fix by mod column
hideFixedByModCol();
$('tr.comparison_' + parentspanid).each(function(i){
if (i % 2 == 0) {
$(that).addClass('comparison_even');
} else {
$(that).addClass('comparison_odd');
}
});
}
});
Any help would be greatly appreciated!
I suspect your data is coming back improperly formed. Enclose your code from the break on within try {} catch {} to see the error generated. Also it would be a good idea to add error processing to your ajax request.

Resources