-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.js
48 lines (38 loc) · 1.22 KB
/
common.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
37
38
39
40
41
42
43
44
45
46
47
48
window.onhashchange = startup
function generate_hash(object) {
return encodeURIComponent(JSON.stringify(object))
}
function offset_date_by_weeks(date, weeks, days = 0) {
return new Date((new Date(date)).getTime() + 24 * 60 * 60 * 1000 * (weeks * 7 + days))
}
function date_to_str(date) {
return date.toISOString().substring(0, 10)
}
const duty_length_not_allowed = (object) => {
return object.length < 1 || object.length > 2
}
function default_data() {
const defaultd = {
"v": 2,
"workers": [["Hans", "Peter", "Gunter"], ["Julia", "Anne", "Lina"]],
"start_date": (new Date()).toISOString(),
"duties": ["Kitchen", "Trash"],
"offsets": [0, 2]
}
return JSON.parse(JSON.stringify(defaultd))
}
function load_hash_data() {
hash = window.location.hash.substring(1);
if (hash.length === 0) {
console.log("no data in fragment, use default")
current_plan = default_data()
} else {
try {
current_plan = JSON.parse(decodeURIComponent(hash))
} catch (e) {
alert("The data in the uri was corrupted. loading default data")
current_plan = default_data()
}
console.log("loaded data")
}
}