-
Notifications
You must be signed in to change notification settings - Fork 1
/
apps_script.js
36 lines (29 loc) · 1.08 KB
/
apps_script.js
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
/**
* Created by hakonhanesand on 2/18/17.
*/
function copyFormatting (fromRange, toRange) {
'use strict'
fromRange.copyFormatToRange(toRange.getSheet(),
toRange.getColumn(),
toRange.getLastColumn(),
toRange.getRow(),
toRange.getLastRow())
}
function onOpen () {
updateTime()
}
function updateTime () {
var response = UrlFetchApp.fetch('https://morning-dusk-92308.herokuapp.com/hours')
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
if (response.getResponseCode() != 200) {
spreadsheet.toast('Could not fetch hours from timely...')
Logger.log('Error : Could not fetch hours from timely...')
return
}
var monthOffset = spreadsheet.getRangeByName('monthOffsetHoursWorked').getValue()
var startHoursWorkedRange = spreadsheet.getRangeByName('startHoursWorked')
var currentMonthHoursWorked = startHoursWorkedRange.offset(monthOffset, 0)
var responseJSON = JSON.parse(response.getContentText())
currentMonthHoursWorked.setValue(responseJSON.minutes * 0.000694444444444)
copyFormatting(startHoursWorkedRange, currentMonthHoursWorked)
}