-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvertionFunctions.js
108 lines (99 loc) · 2.89 KB
/
convertionFunctions.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
function convertToDate(YYMMDD)
{
YYMMDD = YYMMDD.toString();
const YY = YYMMDD.substring(0, 2);
const MM = YYMMDD.substring(2, 4);
const DD = YYMMDD.substring(4, 6);
return DD + '/' + MM + '/20' + YY;
}
function convertToTime(HHMMSSDD)
{
HHMMSSDD = HHMMSSDD.toString();
const HH = HHMMSSDD.substring(0, 2);
const MM = HHMMSSDD.substring(2, 4);
const SS = HHMMSSDD.substring(4, 6);
return HH + ':' + MM + ':' + SS;
}
function getTimezone()
{
let timezone = new Date().getTimezoneOffset();
timezone = timezone / 60;
timezone = timezone * -1;
return timezone;
}
function convertToLocalTimezone(date, time)
{
date = date.split('/');
time = time.split(':');
let currentDate = new Date(date[2], date[1] - 1, date[0], time[0], time[1], time[2], 0);
let timezone = getTimezone();
currentDate.setHours(currentDate.getHours() + timezone);
// Transform currentdate to DD/MM/YYYY HH:MM:SS
let DD = currentDate.getDate();
let MM = currentDate.getMonth() + 1;
let YY = currentDate.getFullYear();
let HH = currentDate.getHours();
let MM2 = currentDate.getMinutes();
let SS = currentDate.getSeconds();
if (DD < 10) {DD = '0' + DD; }
if (MM < 10)
{ MM = '0' + MM; }
if (HH < 10)
{ HH = '0' + HH; }
if (MM2 < 10)
{ MM2 = '0' + MM2; }
if (SS < 10)
{ SS = '0' + SS; }
return DD + '/' + MM + '/' + YY + ' ' + HH + ':' + MM2 + ':' + SS;
}
function convertToUTCTimezone(date, time)
{
date = date.split('/');
time = time.split(':');
let currentDate = new Date(date[2], date[1] - 1, date[0], time[0], time[1], time[2], 0);
let timezone = getTimezone();
currentDate.setHours(currentDate.getHours() - timezone);
// Transform currentdate to DD/MM/YYYY HH:MM:SS
let DD = currentDate.getDate();
let MM = currentDate.getMonth() + 1;
let YY = currentDate.getFullYear();
let HH = currentDate.getHours();
let MM2 = currentDate.getMinutes();
let SS = currentDate.getSeconds();
if (DD < 10) {DD = '0' + DD; }
if (MM < 10)
{ MM = '0' + MM; }
if (HH < 10)
{ HH = '0' + HH; }
if (MM2 < 10)
{ MM2 = '0' + MM2; }
if (SS < 10)
{ SS = '0' + SS; }
return DD + '/' + MM + '/' + YY + ' ' + HH + ':' + MM2 + ':' + SS;
}
function convertToServerDate(inputDate)
{
// Convert date in format YYYY-MM-DD to YYMMDD
if (inputDate.indexOf('-') > -1)
{
let date = inputDate.split('-');
let YY = date[0].substring(2, 4);
let MM = date[1];
let DD = date[2];
return YY + MM + DD;
}
return inputDate;
}
function convertToServerTime(inputTime)
{
// Convert time in format HH:MM:SS to HHMMSS
if (inputTime.indexOf(':') > -1)
{
let time = inputTime.split(':');
let HH = time[0];
let MM = time[1];
let SS = time[2];
return HH + MM + SS;
}
return inputTime;
}