this is NOT a duplicate
According to its documentation, Utilities.formatDate(date, timeZone, format)
works according to Java SE SimpleDateFormat class specifications.
Which, as you can easily tell, expect the week to start on Monday, that is Day 1.
Why does my week starts on sunday instead, even if it is clearly output as day 7?
function testDate() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('history');
var extension = 2;
var arrayDates = sheet.getRange(3, 2, extension).getValues();
//flattening the array
function flatten(tdArray){return [].concat.apply([], tdArray);}
var arrayDates = flatten(arrayDates);
//"extracting" weeks' numbers from the dates
var arrayWeekNums = arrayDates.map(function(el){return Utilities.formatDate(el, "CET", "uyww");});
// CET = Central Europe Time
// u = day of the week;
// y = year in 4 digits;
// ww = week numbers in 2 digits
Logger.log(arrayWeekNums);
Logger.log(arrayDates);
}
//Logger.log(arrayWeekNums);
// [7201803, 6201802]
// 7-2018-03 week day: 7 ; year: 2018 ; week number: 03;
// 6-2018-02 week day: 6 ; year: 2018 ; week number: 02; ??
//Logger.log(arrayDates);
//[20-01-11 22:21:54:187 CET] [Sun Jan 14 00:00:01 GMT+01:00 2018, Sat Jan 13 23:59:59 GMT+01:00 2018]
I've also switched my project's global settings from US to any european Contry: nothing changes.
How can I change this?
edit, as per request:
1."impostazioni internazionali" aka spreadsheet timezone(File>spreadsheet settings>locale) at the moment "Italia", but even with "United States" it's the same outcome;
2.script timezone(File> project settings): "GMT +01:00 - Paris"
spreadsheet copy: https://docs.google.com/spreadsheets/d/1f8ep3Hczo1jbu7s2PTGsaqog8qkW-dc9MAeYNOEBRbw/edit?usp=sharing