-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetCurrentDate.js
64 lines (49 loc) · 1.7 KB
/
GetCurrentDate.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
const AddLeadingZeros = (n) => {
// Used To ensure single digit numbers have a leading zero
if (n <= 9) {
return "0" + n;
}
return n;
};
export function GetCurrentDate() {
// Gets Current Date And Returns Formatted
let Current = new Date();
// Formats Current Date e.g. 2022-03-27
let CurrentDate = `${AddLeadingZeros(
Current.getFullYear()
)}-${AddLeadingZeros(Current.getMonth() + 1)}-${Current.getDate()}`;
let CurrentMin = 0;
if (Current.getMinutes() > 35) {
CurrentMin = 30;
} else {
CurrentMin = 0;
}
// Formats Current Time e.g. 08:00
let CurrentTime = `${AddLeadingZeros(Current.getHours())}:${AddLeadingZeros(
CurrentMin
)}`;
return `${CurrentDate}T${CurrentTime}`;
}
export function GetSettlementPeriod() {
let Current = new Date();
let CurrentSettlementPeriod
if (Current.toString().includes("British Summer Time")) {
CurrentSettlementPeriod = `${Math.floor((Current.getHours() * 60 + Current.getMinutes()) / 30) + 2}`;
if (CurrentSettlementPeriod == 49) CurrentSettlementPeriod == 1;
if (CurrentSettlementPeriod == 50) CurrentSettlementPeriod == 2;
return CurrentSettlementPeriod;
}
else if (!Current.toString().includes("British Summer Time")){
CurrentSettlementPeriod = `${Math.floor((Current.getHours() * 60 + Current.getMinutes()) / 30)}`;
return CurrentSettlementPeriod;
}
}
export function GetSettlementDate() {
// Gets Current Date And Returns Formatted
let Current = new Date();
// Formats Current Date e.g. 2022-03-27
let CurrentSettlementDate = `${AddLeadingZeros(
Current.getFullYear()
)}-${AddLeadingZeros(Current.getMonth() + 1)}-${Current.getDate()}`;
return CurrentSettlementDate;
}