-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripts.js
110 lines (93 loc) · 3.21 KB
/
scripts.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function initCalendar()
{
$(".long.years").text(new Number(parseInt((0x7FFFFFFFFFFFFFFF - (new Date())/1000)/60/60/24/365)).toLocaleString());
$(".ulong.years").text(new Number(parseInt((0xFFFFFFFFFFFFFFFF - (new Date())/1000)/60/60/24/365)).toLocaleString());
setDateTime();
setInterval(setDateTime, 1000);
}
function setDateTime()
{
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var d = date.getDate();
var M = date.toLocaleString(navigator.language, { month: "long" });
var N = date.getMonth() + 1;
var Y = Math.abs(date.getFullYear() - 1970) + 1;
var W = date.toLocaleString(navigator.language, { weekday: "long" });
var ampm = h >= 12 ? 'pm' : 'am';
var ampm_h = h % 12;
ampm_h = ampm_h ? ampm_h : 12;
var time_offset = -date.getTimezoneOffset() / 60;
$("#hour").text(zerofil(h));
// $("#hour_ampm").text((ampm_h < 10 ? "0" + ampm_h : ampm_h) + " " + ampm);
$("#timezone").text((time_offset > 0 ? "+" + zerofil(time_offset) : zerofil(time_offset)) + " UTC");
$("#min").text(zerofil(m));
$("#sec").text(zerofil(s));
$("#date").text(zerofil(d));
$("#weekday").text(W);
$("#month").text(M);
$("#month-no").text(zerofil(N));
$("#year").text(zerofil(Y));
$("#timestamp").text(parseInt(date.getTime()/1000));
updateCounters(".int", new Date(0x7FFFFFFF * 1000));
updateCounters(".uint", new Date(0xFFFFFFFF * 1000));
// var int_limit = new Date(new Date(0x7FFFFFFF * 1000) - date);
//
//
// if (int_limit > 0) {
// $(".int.years").text(int_limit.getUTCFullYear() - 1970);
// $(".int.days").text(getCountDays(int_limit));
// $(".int.clock").text(zerofil(int_limit.getUTCHours())
// + ":" + zerofil(int_limit.getUTCMinutes())
// + ":" + zerofil(int_limit.getUTCSeconds()))
// }
}
function zerofil(num) {
if (num >= 0) {
return num < 10 ? "0" + num : num;
} else {
return num > -10 ? "-0" + Math.abs(num) : num;
}
}
function getCountDays(date)
{
var days = 0;
for (var month = 1; month < date.getMonth(); month++) {
days += (new Date(date.getUTCFullYear(), month, 0)).getDate();
}
days += date.getUTCDate();
return days;
}
function updateCounters(cls, date)
{
var diff = new Date(date - new Date());
if (diff > 0) {
$(cls + ".years").text(diff.getUTCFullYear() - 1970);
$(cls + ".days").text(getCountDays(diff));
$(cls + ".clock").text(zerofil(diff.getUTCHours())
+ ":" + zerofil(diff.getUTCMinutes())
+ ":" + zerofil(diff.getUTCSeconds()))
}
}
$(document)
.ready(function() {
// fix menu when passed
$('.calendar')
.visibility({
once: false,
onBottomPassed: function() {
$('.fixed.menu').transition('fade in');
},
onBottomPassedReverse: function() {
$('.fixed.menu').transition('fade out');
}
})
;
// create sidebar and attach to menu open
$('.ui.sidebar')
.sidebar('attach events', '.toc.item')
;
})
;