GSuite services - Calendar - bug with timezone and years? - javascript

I'm playing with the GSuite services Calendar (https://developers.google.com/apps-script/reference/calendar/calendar) to retrieve events from my Google Calendar.
I'm french (this is important for timezone).
I noticed something strange :
On my Google Calendar, I create an event, for exemple: 2017-11-17 from 10am to 18pm (notice the year 2017).
With Javascript and calendar service API, I retrieve this event and print start and end date:
function runMe() {
var calendar = CalendarApp.getDefaultCalendar();
Logger.log('My default calendar is set to the time zone "%s".', calendar.getTimeZone());
const events = calendar.getEvents(new Date(2017, 10, 17), new Date(2017, 10, 18));
events.forEach(event => Logger.log (event.getStartTime()+" - "+event.getEndTime()));
}
// logs:
// My default calendar is set to the time zone "Europe/Paris".
// Fri Nov 17 2017 09:00:00 GMT+0100 (heure normale d’Europe centrale) - Fri Nov 17 2017 17:00:00 GMT+0100 (heure normale d’Europe centrale)
The date is not correct, I expect Fri Nov 17 2017 10:00:00 GMT+0100 (heure normale d’Europe centrale) - Fri Nov 17 2017 18:00:00 GMT+0100 (heure normale d’Europe centrale)
Now, on my Google Calendar, I create another event at the same date, but on year 2018.
With Javascript and calendar service API, I retrieve this event and print start and end date:
...
function runMe() {
var calendar = CalendarApp.getDefaultCalendar();
Logger.log('My default calendar is set to the time zone "%s".', calendar.getTimeZone());
const events = calendar.getEvents(new Date(2018, 10, 17), new Date(2018, 10, 18));
events.forEach(event => Logger.log (event.getStartTime()+" - "+event.getEndTime()));
}
// logs:
// My default calendar is set to the time zone "Europe/Paris".
// Sat Nov 17 2018 10:00:00 GMT+0100 (heure normale d’Europe centrale) - Sat Nov 17 2018 18:00:00 GMT+0100 (heure normale d’Europe centrale)
The date is correct.
What happened?

This appears to be a bug!
I've done a lot of testing regarding this and it appears that the Calendar API returns the time incorrectly between the period between when DST ended in 2017, and when it began again in 2018.
I have taken the liberty of reporting this on Google's Issue Tracker for you, detailing the behaviour:
Calendar API returns incorrect event start and end time for events between end of DST 2017 and beginning of DST 2018
You can hit the ☆ next to the issue number in the top left on the page which lets Google know more people are encountering this and so it is more likely to be seen to faster.

Related

The Brasilia Summer Time 2019 at JavaScript

I have my datacenter in Brazil and all my JS applications have a Timezone problem because at 2019 the daylight save hour is not enable and the JS Server (NodeJS) understand the Brasil with -2 timezone but I need -3 .
I tried :
console.log(new Date()); // Sun Nov 10 2019 11:09:35 GMT-0200 (Brasilia Summer Time)
console.log(new Date().toISOString()); //2019-11-10T13:09:35.653Z
I believe you'll get the correct timezone offset if you upgrade your version of Node.js, it has been updated to reflect the timezone changes: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#12.13.1.
I believe Node 12.13.1 will show the correct UTC offset (-3 hours), e.g. in node 12.13.1 if I do:
console.log(new Date().toString());
I get
'Mon Dec 02 2019 11:28:26 GMT-0300 (Brasilia Standard Time)'

GSheets GS Dates are one day off for 3/9/2020 - 4/5/2020 all other days are correct

GS code comes back one day off when getting date from 3/9/2020 - 4/5/2020
All dates between 3/9/2020 - 4/5/2020 comeback incorrect.
Google sheet add date column with date 3/9/2020
Add code to gs below
Comes back: Sun Mar 08 2020 23:00:00 GMT-0600 (CST)
3/9/2020
Sun Mar 08 2020 23:00:00 GMT-0600 (CST)
4/5/2020
Sat Apr 04 2020 23:00:00 GMT-0600 (CST)
var data = SpreadsheetApp.getActiveSpreadsheet().getDataRange().getValues();
SpreadsheetApp.getUi().alert(data[0][0]);
Here is the google sheet: link
The dates come back correctly if I format it using GMT.
var formattedDate = Utilities.formatDate(data[0][0], "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
UTC, GMT and Daylight Saving Time
Neither UTC nor GMT ever change for Daylight Saving Time (DST). However, some of the countries that use GMT switch to different time zones during their DST period.
For example, the United Kingdom is not on GMT all year, it uses British Summer Time (BST), which is one hour ahead of GMT, during the summer months.

Why isn't Date(2015, 11, 1) the first of December? [duplicate]

This question already has answers here:
Incorrect date shown in new Date() in JavaScript
(3 answers)
Closed 5 years ago.
When I convert that date to ISO string I get the 30th of november 2015. Why wouldn't it be first of december? I have googled and I know that month is 0-indexed and that overflows lead to the next day/month/year. But I cannot explain myself that behaviour and when I google it I find unrelated topics.
Thing is if You type:
var date = new Date(2015, 11, 1);
console.log(date);
You will get output based on your timezone, for me it's:
Tue Dec 01 2015 00:00:00 GMT+0100 (Central Europe Standard Time)
Function toISOString will always output time in UTC. So in this case you will get this date minus one hour.
2015-11-30T23:00:00.000Z
If you check the MDN page you'll see that:
Note: Where Date is called as a constructor with more than one argument, the specifed arguments represent local time. If UTC is desired, use new Date(Date.UTC(...)) with the same arguments.
Your users have different local timezones.
For me new Date(2015, 11, 1) gives Tue Dec 01 2015 00:00:00 GMT+0100 (Romance Standard Time) (I'm in the timezone Central European Time which is GMT+1).
Hence you can follow the MDN hint and use Date.UTC inside of your date call instead:
var date = new Date(2015, 11, 1);
console.log(date.toString());
// "Tue Dec 01 2015 00:00:00 GMT+0100 (Romance Standard Time)"
// 00:00:00 in GMT+1 but 23:00:00 in GMT+0
console.log(date.toISOString());
// "2015-11-30T23:00:00.000Z"
// ^^ 30th of november - that's a nogo!
var utcDate = new Date(Date.UTC(2015, 11, 1));
console.log(utcDate.toString());
// "Tue Dec 01 2015 01:00:00 GMT+0100 (Romance Standard Time) 15:49:26.146"
// 01:00:00 in GMT+1 but 00:00:00 in GMT+0
console.log(utcDate.toISOString());
// "2015-12-01T00:00:00.000Z"
// ^^ The first! Not the 30th!
var date = new Date(Date.UTC(2015, 11, 1));
console.log(date.toISOString());
Output:
2015-12-01T02:00:00.000Z

Javascript Date() timezone incosistency

I get inconsistent timezone based on params to Date():
new Date()
Sun Oct 25 2015 18:10:42 GMT+0200 (IST)
new Date(1445720400)
Sat Jan 17 1970 19:35:20 GMT+0200 (IST)
new Date(144572040000)
Thu Aug 01 1974 09:54:00 GMT+0300 (IDT)
new Date(14457204000000)
Thu Feb 17 2428 20:00:00 GMT+0200 (IST)
I tried reading the docs or finding an explanation to this weirdness, but couldn't.
I've checked on both Chrome 46 and Safari 7.1.8,
Any ideas?
Isn't this just daylight savings? One of the dates happened to be in the summer?
The problem in then you set different time in ms as param for 'new Date()'. And you have different time zones because the Date has been generated in different seasons (Summer's time and Winter's time). It is normal.

D3 time range drops the first month

In the library D3. I find the set of functions to handle dates a bit inconsistent. For example, doing the following 4 steps in a console of a page loading D3 I get:
> start = new Date(2010, 11, 30)
Thu Dec 30 2010 00:00:00 GMT+0000 (GMT Standard Time)
> end = new Date(2011, 0, 2)
Sun Jan 02 2011 00:00:00 GMT+0000 (GMT Standard Time)
> d3.time.months(start, end, 1)
[Sat Jan 01 2011 00:00:00 GMT+0000 (GMT Standard Time)]
> d3.time.days(start, end, 1)
[Thu Dec 30 2010 00:00:00 GMT+0000 (GMT Standard Time), Fri Dec 31 2010 00:00:00 GMT+0000 (GMT Standard Time), Sat Jan 01 2011 00:00:00 GMT+0000 (GMT Standard Time)]
the above indicates that day.range starts from the first item and ends just before the second, while month.range seems to do the opposite.
In the documentation it's stated:
# d3.time.months(start, stop[, step])
Alias for d3.time.month.range. Returns the month boundaries (e.g., January 01)
after or equal to start and before stop. If step is specified, then every step'th
month will be returned, based on the month of the year. For example, a step of 3
will return January, April, July, etc.
after or equal to start and before stop is also mentioned for time.days but the result appears to be different. Also, when these functions return after and when equal to the start? What makes the difference?
NB: my wish would be having these functions returning arrays of days, months, years including both start and end parameters.
As clearly explained in here the behaviour is in fact consistent. Both day.range and month.range aim to return each daily and monthly boundaries between the start and end parameter.

Categories

Resources