Google script inverses day and month from the google form - forms

I am creating a google calendar will contain birthdays in it. To make it automatically, I created a form and a script that would automatically create the vent and repeat it every year.
I get a problem that I just can't understand: the day and the month get inversed in the calendar.
The code is made by 2 files, one that contains the function that creates the event and the other is triggered when the form is submitted. The dates are also saved in a google spreadsheet. Here is the code:
Create the event:
function createBirthdays_ ( namedValues ) {
var cEvent = CalendarApp.getCalendarsByName( "Anniversaires CA" )[0].createAllDayEventSeries(namedValues.Nom, new Date ( namedValues.Date ), CalendarApp.newRecurrence().addYearlyRule());
}
The function that gets triggered when the form is submitted:
function onFormSubmit(e) {
createBirthdays_ ( e.namedValues );
}
I am sure it is something really simple, but I can't find it.

Might it be that in one of them you get European date format and in the other the US? There the month and day are in different order. So you might want to try to process namedValues.

Related

Shutdown Google Forms at given dates of the month and Open the form again at given dates of the month

Sorry for the newbie question. I have a google form that I open on the first day of each month and then shutdown on the 21st of the month. So basically users can only use the form the first 21 days of the month. I was wondering if there is a way to programmatically do this via a script. I know that this could be done via an add-on to the form but, I don't want to use an add-on as I don't what the code is doing in these and I want to make sure that the data is kept secure within the form sheet. Sorry for not having any code to demonstrate but have been doing a bit of research and can not seem to find anything remotely close this. Is it not possible to do this via Appscript? Thank you all in advance for your help.
I was able to do this us using a trigger and a script, named my form "Play"
Here is the script:
function limitDays() {
var form = FormApp.getActiveForm();
var lastDay = 21;
var currDate = new Date();
var dayOfMonth = currDate.getDate();
if (dayOfMonth > lastDay) {
form.setAcceptingResponses(false);
} else {
form.setAcceptingResponses(true);
}
}

How to extract year only from email date

I'm reading an entire Gmail emails (inbox/sent/trash...), and try to create folders in google drive according to dates.
So folders should be categorized like (...,2019,2020, 2021). Each folder contains all emails in this year in my Gmail.
I managed to create the folders, getting messages through using Threads, all these things works fine, but I couldn't extract the year of the message only.
As when I use Threads[0].getMessages()[0].getDate() what is returned is date and time of this message. which I can't extract the year only from it.
I tried to split the date, but this is not string.
I tried to make smth like Threads[0].getMessages()[0].getDate().getYear() it returned 120!!!
I tried to see if I can access it as an array, [index], it returned null
I tried to parse it to Date(), but I couldn't get use of it too.
Is there is anyway that allows me to extract only the year from this format.
This is part of the script where i'm trying to fetch the date I'm using.
function GetAttachmentsWithTime() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheetByName('Sheet1'));
var start = 0;
var end = 10;
var filter = "has:attachment";
var threads = GmailApp.search(filter,start,end);
Logger.log(threads[0].getMessages()[0].getDate())
}
Are you using the V8 runtime?
If so, see this migration guide. It says:
In the V8 runtime, Date.prototype.getYear() returns the year minus
1900 instead as required by ECMAScript standards.
So emails from the year 2020 would return 120 (i.e. 2020 - 1900 = 120).
To fix this, use .getFullYear():
When migrating your script to V8, always use
Date.prototype.getFullYear(), which returns a four-digit year
regardless of the date.

Ember.js and Dates - showing as one day earlier than actual

This has been giving me trouble for a long time now, and I wouldn't think this would be so hard. I have a model with some dates, and date data coming from the API like so:
{
...
tollgate1: '2016-04-15',
tollgate2: '2017-01-01',
projectClose: '2016-10-21',
}
I created a format-date helper (which uses moment.js) to format the dates in view mode, like so:
And that's shows it correctly. However, when I switch to edit mode, the input elements are still referencing the same values, but now they all go one day earlier!
This has been maddening for some time. I've thought it might be due to a like of time zone information in the data, but since I can't change the data that's fed to my app, how can I get it to just display the date in the data, regardless of timezone? For example, with the Tollgate 1 date, I would want it to show April 15 no matter where the user is in the world.
Okay, so as with many things, this isn't an Ember thing so much as just a JavaScript thing. It's really hard learning both at once!
Since my dates coming down from the API don't have a time zone, they're assumed to be GMT, and so my EST timezone of -4 hours makes it show as the day before. Apparently moment.js has some built-in handling so that's why the format-date helper works fine.
What I did to solve is to just add computed properties on my model for each date, and create a new Date object by pulling out the parts from the input date, like so:
function convertDateToUtc(d) {
if(d) {
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
} else {
return null;
}
}
export default DS.Model.extend({
...
tollgate1Date: Ember.computed('tollgate1', function() {
return convertDateToUtc(this.get('tollgate1'));
})
});

Using Google Forms, need script to turn form off and on daily, and to clear weekly

I need to:
Set the form to "Not accepting responses" every weekday at 7:16 am
Then set the form to “Accepting responses” every weekday at 5:30 am
Clear all responses from the form and the form spreadsheet on Friday at 2:00 pm
I have no experience with writing scripts. This is for a teacher sign-in sheet for a public high school.
Any help is greatly appreciated!
Unfortunately, StackOverflow isn't here to write your code for you, so you won't receive an answer that you can copy/paste and get to work. The community will instead assist you with any specific roadblocks that you encounter with your code (If they can).
However, you'll be able to achieve this with the Form Service, specifically, the '.setAcceptingResponses()' method. You'll also need the Spreadsheet service with the '.clear()' method to empty the sheet.
You'll find the time triggers are the easiest way to set when the form becomes active and inactive again, however, you've mention very specific times that this needs to go offline and online again (7:16 am and 5:30 am, but only on weekdays, and 2PM to clear the sheet on Fridays), but Google Apps script time triggers can't be set down to the minute (Note the triggers explanation about the time being randomized).
An alternative would be to write a function that checks the time, have that function run every minute, and if the time = 2PM on a Friday then clear the sheet etc.
have you checked out formLimiter by New Visions Cloud Lab?
http://cloudlab.newvisions.org/add-ons/formlimiter
The description is:
formLimiter automatically sets Google Forms to stop accepting responses after a maximum number of responses, at a specific date and time, or when a spreadsheet cell contains a specified value.
Great for time-bound assignments, event registrations with limited seats, or other first-come, first-served signup scenarios.
I was able to write a short script and set a trigger, I named my form "Play"
Here is the script:
function limitDays() {
var form = FormApp.getActiveForm();
var lastDay = 21;
var currDate = new Date();
var dayOfMonth = currDate.getDate();
if (dayOfMonth > lastDay) {
form.setAcceptingResponses(false);
} else {
form.setAcceptingResponses(true);
}
}

Get users current date

I need to check what’s the current date where the user is in.
I don’t need the time, just the current date.
How can i do it?
I'm using codeigniter.
Thanks.
I've managed to get the date on the client side.
My problem is that i get an error (0) when trying to parse it using strtotime.
I know that means the string is not ok but when i do an echo it displays ok(07/11/2010).
Here's the code:
javascript:
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year
HTML:
$curdate="";
$newdate = strtotime ( '-0 year' , strtotime ( $curdate ) ) ;
$curdate=date ( 'Y-m-d' , $newdate );
echo form_hidden('curdate','',$curdate);
The web server and, by extension, your application do not have this information. You have to get that input from the client side somehow. A couple of ideas come to mind:
Ask the user what time zone they're in (e.g., with a form), then calculate their date based on that.
Use some JavaScript that finds the information automatically (e.g., getTimezoneOffset()). Optionally, submit this information to your app via Ajax.