Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Slice dates give double digit mm & dd
- function sliceit(x) {
- thing = ("0" + (x)).slice(-2);
- return thing
- }
- // Get Monday
- function dateDiff() {
- var day = d.getDay(),
- diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
- return diff
- }
- // Get date & create name of document
- function setName() {
- d = new Date();
- diff = dateDiff(d);
- thatmonday = new Date(d.setDate(diff));
- thatfriday = new Date(d.setDate(thatmonday.getDate() + 4));
- newformat = 'Completed ' + thatmonday.getFullYear() + '_' + sliceit(thatmonday.getMonth() + 1) + '/' +
- sliceit(thatmonday.getDate()) + ' - ' + sliceit(thatfriday.getMonth() + 1) + '/' + sliceit(thatfriday.getDate())
- return newformat
- }
- // Write each day of the week in document
- function writeDays(step) {
- d = new Date();
- var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
- eachday = new Date(d.setDate(diff + step));
- eachdayformat = days[eachday.getDay()] + ' ' + sliceit((eachday.getMonth() + 1)) + '/' + sliceit(eachday.getDate()) + ':';
- return eachdayformat
- }
- // Move from root to work folder
- function moveFile(file, folder) {
- folder.addFile(file);
- DriveApp.getRootFolder().removeFile(file);
- }
- function myFunction() {
- // Create document
- var folder = DriveApp.getFolderById("EnterYourFolderIDNumberHere");
- var doc = DocumentApp.create(setName());
- var file = DriveApp.getFileById(doc.getId());
- var body = doc.getBody();
- // For loop write days of the week and assign bullet points
- for (step = 0; step < 5; step++){
- body.appendParagraph(writeDays(step));
- body.appendListItem("\n").setGlyphType(DocumentApp.GlyphType.BULLET);
- }
- moveFile(file, folder);
- }
Add Comment
Please, Sign In to add comment