forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
89 lines (80 loc) · 2.23 KB
/
utils.js
File metadata and controls
89 lines (80 loc) · 2.23 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*utils.js*/
const bold = 900;
const days = {};
days.long = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
days.short = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
days.number = ['01','02','03','04','05','06','07'];
// console.log('days: ', days);
const months = {};
months.long = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
months.short = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
months.number = ['01','02','03','04','05','06','07','08','09','10','11','12'];
// console.log('months: ', months);
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
const time = document.querySelectorAll(".time");
time.forEach(function(e){
// console.log('e: ', e);
e.innerHTML = "--"
});
/**
* Lengths of units of time in seconds.
*
* Notes:
*
* - An average year is 365.24225 days (adjusting for leap years/
* days).
*
* - Therefore an average month is (365.24225/12) or 30.4368541667
* days long.
*
* - Using these averages will introduce more margin of error when
* comparing dates in the middles of months than dates at the
* beginnings or ends of months.
*
*/
const units = {
// "years":(31536000),
"yrs":(86400*365.24225),
"mon":(86400*30.4368541667),
"day":86400,
"hrs":3600,
"min":60,
"sec":1
};
const dateFunctions = {
"yrs":"getFullYear",
"mon":"getMonth",
"day":"getDate",
"hrs":"getHours",
"min":"getMinutes",
"sec":"getSeconds"
};
function timezoneOffset (time, el) {
console.log('el: ', el.tagName);
const offset = time.getTimezoneOffset()/60;
// const el = time;
let string = '';
if (offset > 0) {
string = 'UTC+'+offset;
} else if (offset < 0) {
string = 'UTC-'+offset;
} else {
string = 'UTC';
}
if (el.tagName) {
if (el.tagName === 'INPUT') {
el.value = string;
} else {
el.innerHTML = string;
}
} else {
console.log('el.tagName error!');
}
}
function hideZeroes (things) {
things.forEach(thing => {if (thing.innerHTML === '00') {thing.style.display = 'none'} else {thing.style.display = 'inline'}});
}