forked from tpowell/jsadvent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.js
50 lines (43 loc) · 1.23 KB
/
time.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
// Copyright 2011 Thomas Oberndörfer ([email protected])
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
exports.getLocalDate = getLocalDate;
exports.getTargetDate = getTargetDate;
exports.getCheatDate = getCheatDate;
var TZ_CET = +1;
var TARGET_YEAR = 2011;
var TARGET_MONTH = 11; // december
function getLocalDate() {
// create Date object for system
var d = new Date();
return convertToLocal(d, TZ_CET);
}
function convertToLocal(date, offset) {
// convert to UTC
var utc = convertToUTC(date);
// create new Date object for different city
// using supplied offset
var nd = new Date(utc.getTime() + (3600000*offset));
// return time
return nd;
}
function convertToUTC(date) {
return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
}
function getTargetDate(day) {
var d = getLocalDate(TZ_CET);
d.setDate(day);
d.setMonth(TARGET_MONTH);
d.setFullYear(TARGET_YEAR);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
return d;
}
function getCheatDate(day) {
var d = new Date();
d.setDate(day);
d.setMonth(TARGET_MONTH);
d.setFullYear(TARGET_YEAR);
return d;
}