When I try to get time form table it plus 29 mins and 43 secs constantly
function onEdit(e){
var cal = CalendarApp.getCalendarById("h8ueab6ooel3iv8c7v4nd6bkvg#group.calendar.google.com");
Logger.log(cal)
// var arrayDate, arrayTimeStart, arrayTimeEnd;
var DateStart = new Date();
var DateEnd = new Date();
var table = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var dlinna = table.getLastRow();
var data = table.getRange("A2:E"+dlinna).getValues();
for (var i=data.length-1; i<data.length;i++){
Logger.log(data[i][2]);
}
}
[the given row]
[the weird time]
Related
I am including the script ( below), the trigger, the sample of the spreadsheet, image of the start and end time formatting and the error(below)...
When I run the createCalendarEvent script manually...no issues..it is when i try to automate the script by creating an event trigger for on form submit that I get the following error:
Error Exception: Event start time must be before event end time.
at createCalendarEvent(create event:26:16)
function createCalendarEvent() {
var sheet = SpreadsheetApp.getActiveSheet();
var calendar =
CalendarApp.getCalendarById("c_71lju3i096qeqsg69bd7togo9g#group.calendar.google.com");
var startRow = 2; // First row of data to process - 2 exempts my header row
var numRows = sheet.getLastRow(); // Number of rows to process
var numColumns = sheet.getLastColumn();
var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns);
var data = dataRange.getValues();
var complete = "Done";
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var startTime = new Date(row[0]); //start Time
var endTime = new Date(row[1]); //end Time
var title = row[2]; //Item Title
var option = row[3]; //event option
var location = row[4]; //location
var eventID = row[6]; //event marked Done
if (eventID != complete) {
var currentCell = sheet.getRange(startRow + i, numColumns);
calendar.createEvent(title, startTime, endTime, {description: option + '\r' , location:
location});
currentCell.setValue(complete);
}
}
}
I have edited the original script and included the trigger just in the script itself ( By passing the automated trigger creation)...this way worked....1 time!..now i get the following error.
Exception: Action not allowed setUpTrigger # create event.gs5
function setUpTrigger() {
ScriptApp.newTrigger('createCalendarEvent')
.forForm('1FAIpQLScQvxc8EUSjGvrrVc6-QE3LwNZOytetIrfOVX-RKrJwS8_ALw')
.onFormSubmit()
.create();
}
function createCalendarEvent() {
var sheet = SpreadsheetApp.getActiveSheet();
var calendar = CalendarApp.getCalendarById("c_71lju3i096qeqsg69bd7togo9g#group.calendar.google.com");
var startRow = 2; // First row of data to process - 2 exempts my
header row
var numRows = sheet.getLastRow(); // Number of rows to process
var numColumns = sheet.getLastColumn();
var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns);
var data = dataRange.getValues();
var complete = "Done";
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var startTime = new Date(row[0]); //start Time
var endTime = new Date(row[1]); //end Time
var title = row[2]; //Item Title
var option = row[3]; //event option
var location = row[4]; //location
var eventID = row[6]; //event marked Done
if (eventID != complete) {
var currentCell = sheet.getRange(startRow + i, numColumns);
calendar.createEvent(title, startTime, endTime, {description:
option + '\r' , location: location});
currentCell.setValue(complete);
}
}
}
The error message is pretty self explanatory.
Error Exception: Event start time must be before event end time
Check the values you are sending for start and end time. Make sure that the event does not end before it starts.
var startTime = new Date(row[0]); //start Time
var endTime = new Date(row[1]); //end Time
I want to add time/duration in HH:mm(eg 00:10) to a Date time in format MM-DD-YYYY HH:MM
I have date and time in 2 separate objects so am trying the below
var plannedStartDate = document.getElementById("date1"); //eg 02-12-2020
var plannedStartTime = document.getElementById("plannedStart1"); //eg 09:00
var plannedStartDateTime = moment(plannedStartDate.value + " " + plannedStartTime.value);
var minutes = $("#duration1").text().split(':')[1];
var hours = $("#duration1").text().split(':')[0];
var date = plannedStartDateTime.add(hours, 'hours').add(minutes, 'minutes').format("MM-DD-YYYY HH:mm");
console.log("Final:"+date); //gives invalid date
What am I doing wrong
Check this working sandbox: https://codesandbox.io/s/compassionate-bas-fg1c2
It adds the hours and minutes to the input date and then prints in a given format
var moment = require("moment");
var input = "2020-02-12";
var hoursMinutes = "9:10";
var hours = hoursMinutes.split(":")[0];
var minutes = hoursMinutes.split(":")[1];
var momentInTime = moment(input)
.add(hours, "hours")
.add(minutes, "minutes");
var converted = moment(momentInTime).format("DD-MM-YYYY HH:mm:ss");
console.log(converted);
I am trying to get a spreadsheet to update a calendar on my Google account, but I am struggling to get the if condition on the code below to work. When I run inseritoNelCal the debug says that it is unspecified even though the spreadsheet has actually data in each row/column.
var IN_CAL = new String('INSERITO');
function dallaTabellaAlCalendario() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 3);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var title = row[0]; // First column
var startTime = new Date(row[1]); // 2nd column
var endTime = new Date(row[02]); // 3rd column
var description = row[3]; // 4th column
var location = row[4]; // 5th column
var guests = row[5]; // 6th column
var inseritoNelCal = row[6]; // 7th column
}
if (inseritoNelCal != IN_CAL){
var calendar CalendarApp.getCalendarById("mycalendarID").createEvent(title, startTime, endTime, {Descrizione: description, Luogo: location, Allievi: guests, Inserito: inseritoNelCal });
sheet.getRange(startRow, 7).setValue(IN_CAL);
}
}
I want to create an array of 10 minutes span for 1 hour using moment.js but it fails on first step.
var startTime = moment().unix();
var endTime = moment().add(1,'h').unix();
getTimeSheet(startTime,endTime);
var getTimeSheet = function(st, et) {
console.log(arguments);
var timeSheet = [];
var duration = moment.duration({'minutes' : 10});
var ct = st;
console.log(ct);
while (ct <= et ){
var n10 = moment.unix(st).add(duration).unix();
timeSheet.push(n10);
console.log(n10);
ct = n10;
}
console.log(timeSheet);
};
But this is Unable to create array
In each iteration of while loop you are adding 10 minutes to st variable. So n10 and ct still contain the same value. That's why this loop never ends.
You need to change:
var n10 = moment.unix(st).add(duration).unix();
to
var n10 = moment.unix(ct).add(duration).unix();
You can also check working example with some minor improvements here:
https://jsfiddle.net/65gL9tgr/2/
I'm trying to get the current date time in Flex/AIR?
To get the current date time, just create a new Date object with no values into the constructor, like this:
var CurrentDateTime:Date = new Date();
Formatting it depends on how you want to format it; here is one option:
private function CurrentDateTimeString():String
{
var CurrentDateTime:Date = new Date();
var CurrentDF:DateFormatter = new DateFormatter();
CurrentDF.formatString = "MM/DD/YY LL:NN:SS A"
var DateTimeString:String = CurrentDF.format(CurrentDateTime);
return DateTimeString;
}
currentTime = new Date();
From : http://livedocs.adobe.com/flex/3/html/help.html?content=08_Dates_and_times_5.html
and
http://docs.huihoo.com/flex/4/Date.html
private function CurrentDateTimeString():String
{
var CurrentDateTime:Date = new Date();
var DateString:String = CurrentDateTime.getMonth().toString()+ "/"+CurrentDateTime.getDate().toString() +"/"+CurrentDateTime.getFullYear().toString();
var TimeString:String = CurrentDateTime.getHours().toString()+ ":"+ doubleDigitFormat(CurrentDateTime.getMinutes());
var DateTimeString:String = DateString + " " + TimeString;
return DateTimeString;
}
function doubleDigitFormat(num:uint):String
{
if(num < 10) {
return ("0" + num);
}
return num.toString();
}