简体   繁体   中英

Google Script looping through days issue

My first post here so go easy.

I am trying to create a Google script on a spreadsheet which uses a form to get information about events which are then added to a calendar. The script creates a createEventSeries for selected weekdays between two dates. It also checks how many events there are on valid days for every hour between those the events times.

I am having issues with one line of code which should add a day on each loop:

var floatdate = new Date(floatdate.setDate(starttime.getDate()+d)) ;

Where floatdate is the date which it is currently being checked, d is in a number days after starttime.

my issues is that when d = 4 the day and month changes, see this example:

 var floatdate = new Date(floatdate.setDate(starttime.getDate()+0))
 Logger.log(floatdate)
 var floatdate = new Date(floatdate.setDate(starttime.getDate()+1))
 Logger.log(floatdate)
 var floatdate = new Date(floatdate.setDate(starttime.getDate()+2))
 Logger.log(floatdate)
 var floatdate = new Date(floatdate.setDate(starttime.getDate()+3))
 Logger.log(floatdate)
 var floatdate = new Date(floatdate.setDate(starttime.getDate()+4))
 Logger.log(floatdate)

Gives the following:

[17-06-02 05:06:47:933 PDT] Mon May 29 08:00:00 GMT+08:00 2017

[17-06-02 05:06:47:933 PDT] Tue May 30 08:00:00 GMT+08:00 2017

[17-06-02 05:06:47:934 PDT] Wed May 31 08:00:00 GMT+08:00 2017

[17-06-02 05:06:47:935 PDT] Thu Jun 01 08:00:00 GMT+08:00 2017

[17-06-02 05:06:47:935 PDT] Mon Jul 03 08:00:00 GMT+08:00 2017

Please help!

I had the same issue with nonsence date iteration in log view:

[20-06-25 20:42:05:887 CEST] Month 2020-06-26T18:42:05+0000
[20-06-25 20:42:05:889 CEST] Month 2020-06-27T18:42:05+0000
[20-06-25 20:42:05:893 CEST] Month 2020-06-29T18:42:05+0000
[20-06-25 20:42:05:900 CEST] Month 2020-07-03T18:42:05+0000

At the end, I found it is just some weird sample and whole output can be found in "Apps Script Dashboard" (View -> Logs -> link Apps Script Dashboard). This whole output is correct with all dates.

Another option how to get to whole Log outputs is https://script.google.com/home/my -> select your project -> project details menu -> select Executions -> open your execution and observe results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM