Zde naleznete knihovnu užitečných funkcí, které používáme v našich skriptech. Knihovnu průběžně aktualizujeme.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
//Version: 1.1 //Correct timezone offet if inserted date is in daylight saving time function lynt_DST(datum, offset){ var yr = datum.getFullYear(); var dst_start = new Date("March 14, " + yr +" 02:00:00"); var dst_end = new Date("November 07, " + yr +" 02:00:00"); var day = dst_start.getDay(); dst_start.setDate(14-day); day = dst_end.getDay(); dst_end.setDate(7-day); if (datum >= dst_start && datum < dst_end){ return offset+1; } else { return offset; } } //Creating or returning selected sheet function createOrGetSheet(reportSpreadsheet, name, position) { var sheet = reportSpreadsheet.getSheetByName(name); if(sheet == null) { return reportSpreadsheet.insertSheet(name,position); } else { return sheet; } } //Getting data for x days back in right format for AWQL query function lynt_get_date(pocet_dni) { var minule = new Date(); //kdyz je letni cas, tak o hodinu dele (GMT+1) var offset = lynt_DST(minule,1); minule.setTime(minule.getTime() - (1000 * 60 * 60 * (24) * pocet_dni) + offset); return lynt_format_awql_date(minule); } //Getting always last sunday with right formats for AWQL function lynt_get_sunday() { var minule = new Date(); //kdyz je letni cas, tak o hodinu dele (GMT+1) var offset = lynt_DST(minule,1); minule.setTime(minule.getTime() - (1000 * 60 * 60 * (24) * (minule.getDay())) + offset); return lynt_format_awql_date(minule); } //Getting x days from last sunday right formated for AWQL function lynt_get_xdays_back_from_sunday(pocet_dni) { var minule = new Date(); //kdyz je letni cas, tak o hodinu dele (GMT+1) var offset = lynt_DST(minule,1); minule.setTime(minule.getTime() - (1000 * 60 * 60 * (24) * pocet_dni) - (1000 * 60 * 60 * 24 * (minule.getDay()))+ offset); return lynt_format_awql_date(minule); } //Format date for AWQL function lynt_format_awql_date(datum){ return datum.getUTCFullYear()+("0"+(datum.getUTCMonth()+1)).slice(-2)+("0"+datum.getUTCDate()).slice(-2); } |
Napsat komentář