Last active
January 28, 2025 09:02
-
-
Save phillypb/5ef76867610e34952697b8d04532db6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFormData(e) { | |
// get Spreadsheet TimeZone | |
var timeZone = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone(); | |
// get Form data | |
var formValues = e.namedValues; | |
// get specific values from Form ****************** | |
var submissionDate = formValues["The Date"][0]; | |
console.log('submissionDate is: ' + submissionDate); | |
// get specific values from Form ****************** | |
// get todays date | |
var todaysDate = new Date(); | |
// fix date format from Form so workable and look nice *********************** | |
var splitDate = submissionDate.split("/"); | |
console.log("splitDate is: " + splitDate); | |
var day = splitDate[0]; | |
var month = splitDate[1]; | |
var year = splitDate[2]; | |
// subtract '1' from month as JavaScript starts at '0' for 'January' | |
var newSubmissionDate = new Date(year, month - 1, day, todaysDate.getHours(), todaysDate.getMinutes()); | |
console.log('newSubmissionDate is: ' + newSubmissionDate); | |
// fix date format from Form so workable and look nice *********************** | |
// create array of days of the week and use 'getDay()' method to determine which one | |
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; | |
var dayOfTheWeek = newSubmissionDate.getDay(); | |
var day = weekday[dayOfTheWeek]; | |
console.log("Submission day is: " + day); | |
// create a nicely formatted date which could be communicated with an end user | |
var niceSubmissionDate = Utilities.formatDate(newSubmissionDate, timeZone, 'EEEE d MMMMM yyyy'); | |
console.log("niceSubmissionDate is: " + niceSubmissionDate); | |
todaysDate.setHours(0, 0, 0, 0); | |
console.log("todaysDate with hours is: " + todaysDate); | |
if ((newSubmissionDate < todaysDate) && (day != "Wednesday")) { | |
console.log("Form date is in the past and not a Wednesday."); | |
} else if (newSubmissionDate < todaysDate) { | |
console.log("Form date is in the past."); | |
} else if (day != "Wednesday") { | |
console.log("Form date not a Wednesday."); | |
} else { | |
console.log("All is good."); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment