Since Japersoft ireport designer 5.6.0 doesn't support displaying a current date in arabic (as far as i know), i thought why not create a current arabic date in my application and pass it in my url to jasper ireport designer to display it in the report design in a parameter.
But my solution didn't work, maybe i did something wrong, or there is an alternative solution.
Any help on this please?
var months = ["يناير", "فبراير", "مارس", "إبريل", "مايو", "يونيو",
"يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"];
var days =["اﻷحد","اﻷثنين","الثلاثاء","اﻷربعاء","الخميس","الجمعة","السبت"];
var date = new Date();
var monthAR = months[date.getMonth()];
var dayAR = days[date.getDay()];
var yearAR = date.getFullYear();
var numberAR = date.getDate();
var arabicdate = dayAR+" "+numberAR+" "+monthAR+" "+yearAR;
var arDate = arabicdate;
Related
I use momentJS for date conversion but recently ran into a problem that appears only on iOS when calculating the difference between 2 dates.
I have two strings that looks like this:
const startDate = "08-21-2022 10:28 AM";
const endDate = "08-31-2022 10:28 AM";
In a non iOS system this works:
moment(endDate).diff(moment(startDate), "days")
But on iOS it returns NaN with a warning:
Deprecation warning: value provided is not in a recognized RFC2822 or
ISO format. moment construction falls back to js Date(), which is not
reliable across all browsers and versions. Non RFC2822/ISO date
formats are discouraged and will be removed in an upcoming major
release. Please refer to
http://momentjs.com/guides/#/warnings/js-date/ for more info.
...
I tried the following but without success:
var test1 = moment(dateString);
var test2 = moment(dateString2);
console.log(test2.diff(test1, "days"));
var test5 = moment(dateString).toISOString();
var test6 = moment(dateString2).toISOString();
console.log(moment(test6).diff(moment(test5), "days"));
console.log(moment(dateString).valueOf());
They all seem to return NaN. What can I do to calculate the difference? Even console.log(new Date())
What seems to work is this:
var test3 = moment([2007, 0, 29]);
var test4 = moment([2007, 0, 28]);
test4.diff(test3, "days");
But I'm unsure how I could safely extract the year, I tried these:
var test7 = moment(dateString).year();
console.log("5", test7);
var test8 = moment(dateString).toISOString();
console.log("6", moment(test8).year());
But they all returned NaN;
I have a codesandbox to test on iPhone https://codesandbox.io/s/lively-framework-622p7r?file=/src/App.js
Like the title says, is there a way to get the highs and lows of a stock price during the day after a certain time? There's a way to get the days high and low over a period of time:
=GOOGLEFINANCE("AMZN","high","05/01/2020","05/10/2020","DAILY")
=GOOGLEFINANCE("AMZN","low","05/01/2020","05/10/2020","DAILY")
But what about during the day during a specific time period? For example from 9:12AM PST to 11:23AM PST?
Solution#3 : you can use Alpha Vantage by 2 ways, add-on GSheets or a custom function i.e. :
// mike steelson
var apikey = 'xxxxxxxxxxxxxx'
function getAllDataJSONv2(code) {
var url = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol='+code+'&interval=5min&apikey='+apikey
var data = JSON.parse(UrlFetchApp.fetch(url).getContentText())['Time Series (5min)']
var resultat = []
for (var elem in eval(data)){
resultat.push([elem,eval(data[elem]['1. open']),eval(data[elem]['2. high']),eval(data[elem]['3. low']),eval(data[elem]['4. close']),eval(data[elem]['5. volume'])])
}
return resultat
}
the apikey is free for up to 500 requests a day. https://rapidapi.com/alphavantage/api/alpha-vantage
no, not possible with GOOGLEFINANCE. you can get only the daily value which is usually from 16:00:00
your only other option is to find some website (which doesn't use JavaScript) that holds values you wish for and scrape it into google sheets
Solution1 : You can use Yahoo Finance to retrieve the information you want
function getHistoric(url){
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
var data = JSON.parse(jsonString).context.dispatcher.stores.HistoricalPriceStore.prices
var result = []
data.forEach(function(elem){
result.push([elem.date,elem.open,elem.high,elem.low,elem.close])
})
return result
}
https://docs.google.com/spreadsheets/d/1Kly5-Vu5jBfrl6xFljdICFJW369X-OCjB22z3Ouzt4Y/copy
Solution#2 : you can build your own data based on yahoo finance https://docs.google.com/spreadsheets/d/1QlqpPkIMjE8_jT6kNME1cLrMmQZ9cSzG-SR2Jjivvqo/edit?usp=sharing
//Mike Steelson
var histo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('historic')
var code = histo.getRange('B1').getValue()
//put a trigger on historic
function historic(){
if (testDateHour()==true) {histo.appendRow([new Date(),marketPrice(code)])}
}
function marketPrice(code) {
var source = UrlFetchApp.fetch('https://finance.yahoo.com/quote/'+code).getContentText()
var data = JSON.parse(source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}')
return data.context.dispatcher.stores.StreamDataStore.quoteData[code].regularMarketPrice.raw
}
function testDateHour(){
var d = new Date();
// not on sunday and saturday and between 10am and 4pm
if (d.getDay()!=0 && d.getDay()!=6 && d.getHours()>=10 && d.getHours()<=16) {return true}else{return false}
}
Configure your local settings (PST) + update if necessary the period when you want to retrieve the information. Then put the trigger (1min)
New to any form of coding.
I am trying to sync Google calendars to Google sheets to autogenerate events. I found this script online but continue to have errors.
This is my current code:
function scheduleShifts() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarID = spreadsheet.getRange("C4").getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);
var signups = spreadsheet.getRange("A8:C20").getValues();
for (x=0; x<signups.length;x++){
var shift = signups[x];
var startTime = shift[0];
var endTime = shift[1];
var volunteer= shift[2];
eventCal.createEvent(volunteer, startTime, endTime);
}
}
The error code I keep getting is:
ReferenceError: calendarId is not defined
scheduleShifts # Code.gs:4
I can't seem to figure out how to correct it. Any suggestions?
Thanks!
Screenshot of Error
calendarID is not equal to calendarId. Take a look to the d/D.
I'm still SUPER new to Google Sheets, I've mostly just programmed in VBA before this.
The project I'm working on is for a D&D type game, wherein the DM will use Sheet to record damage dealt to the monster. Basically the DM types the damage, clicks the calculate button, then the code sums up the current damage to baddie.
The code works perfectly. The problem I'm having is a human one. There is a tendency to click the "calculate" button before closing the cell.
For instance, the DM types 31 in the cell and immediately clicks "calculate" before hitting enter. This prevents the damage from being recorded properly and I can't figure out the code to make the cell close first.
Here is my current code:
function DamageRecordEnemy1Copy1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1').activate();
var DamageLocation = spreadsheet.getRange('Q4');
var DamageLogLocation = spreadsheet.getRange('Q5');
var DamageLocationValue = DamageLocation.getValue();
var DamageLogLocationValue = DamageLogLocation.getValue();
var NewDamage = DamageLocationValue + DamageLogLocationValue;
DamageLocation.activate();
spreadsheet.getCurrentCell().setValue(NewDamage);
DamageLogLocation.activate();
spreadsheet.getCurrentCell().setValue("");
spreadsheet.getRange('A1').activate();
}
Any idea how to solve the issue? Much appreciated!
Thanks for the help everyone, here is what I ended up doing:
function onEdit(e){
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = e.range;
var DamageLocation = spreadsheet.getRange('Q4');
var DamageLogLocation = spreadsheet.getRange('Q5');
var DamageLocationValue = DamageLocation.getValue()
var DamageLogLocationValue = DamageLogLocation.getValue()
var allRows = [5];
var allColumns = [17, 20, 23, 26, 29, 32];
var EditRow = range.getRow()
var EditColumn = range.getColumn()
if (allColumns.indexOf(EditColumn) > -1)
{
if (allRows.indexOf(EditRow) > -1)
{
var BadDamage = spreadsheet.getRange(EditRow-1,EditColumn)
var BadDamageLog = spreadsheet.getRange(EditRow,EditColumn)
var DamageCalc = BadDamage.getValue() + BadDamageLog.getValue()
BadDamage.setValue(DamageCalc);
BadDamageLog.setValue("");
}
}
};
Replace the "button" with insert->checkbox then use the OnEdit function to check if that cell was set to true, execute your button code and set it back to false. The reason this will work is because Drawings are on it's own layer but the checkbox will force them to have the "hit enter" behavior.
So I am new to Google Sheets. I am making an inspection report for a small company using Sheets. I would like to add a button to the bottom of the sheet which does the following script:
Duplicate original sheet
Rename sheet to a cell value +today's date. i.e Fred01011980
Email the sheet as a PDF to a recipient.
Finally clear the inputted values in the original master template sheet.
I have looked up how to do each of these and a few of them are straightforward, but I don't know how to combine them. Can I just add all of the functions individually together without any additional syntax needed? Any help on this would be really appreciated. Thank you.
I believe you can just create another function that calls your functions, like this:
function doAllStuff() {
doStuff();
doMoreStuff();
}
Here's how I did it:
function AllinOne() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var name = "Inspection";
var sheet = ss.getSheetByName("Inspection").copyTo(ss);
var newname = ss.getSheetByName("Inspection").getRange(2, 2).getValue();
var newnamedate = ss.getSheetByName("Inspection").getRange(3, 2).getValue();
var sheetx = ss.getActiveSheet()
var thisSheet = sheetx.getName();
var actualSheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName()
var sheetfinal = ss.getSheetByName("Inspection")
var old = ss.getSheetByName(newname+newnamedate);
if (old) ss.deleteSheet(old);
sheet.setName(newname+newnamedate); //copies the sheet and renames it to "store+date"
ss.setActiveSheet(sheet)
// below is pdf conversion
var originalSpreadsheet = SpreadsheetApp.getActive();
var sourcesheet = originalSpreadsheet.getActiveSheet();
var sourcerange = sourcesheet.getRange('A1:B176'); // range to get - here I get all of columns which i want
var sourcevalues = sourcerange.getValues();
var data = sourcesheet.getDataRange().getValues();
var newSpreadsheet = SpreadsheetApp.create(thisSheet); // can give any name.
var sheetnow = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var projectname = SpreadsheetApp.getActiveSpreadsheet();
var sheetz = sourcesheet.copyTo(newSpreadsheet);
var destrange = sheetz.getRange('A1:B176');
destrange.setValues(sourcevalues);
newSpreadsheet.getSheetByName('Sheet1').activate();
newSpreadsheet.deleteActiveSheet();
var pdf = DriveApp.getFileById(newSpreadsheet.getId());
var theBlob = pdf.getBlob().getAs('application/pdf').setName(newname+newnamedate);
var folderID = "File_ID"; // Folder id to save in a folder.
var folder = DriveApp.getFolderById(folderID);
var newFile = folder.createFile(theBlob);
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
MailApp.sendEmail("Email","New Manager Inspection: "+newname+newnamedate, "A new Manager Inspection Report has been added to the Drive.");
ss.getSheetByName(name).getRangeList(["B176","B150:B164","B138:B146","B129:B134","B119:B125","B106:B115","B99:B102","B84:B95","B78:B80","B66:B74","B55:B62","B48:B51","B34:B44","B25:B30","B18:B21","B10:B14","B4:B7","B2","B16","B23","B32","B46","B53","B53","B64","B76","B82","B97","B104","B117","B127","B136","B148","B166"]).clearContent();
ss.setActiveSheet(sheetfinal);
SpreadsheetApp.getUi().alert("Report Submitted, Please do NOT Resubmit. Thank You");
}