-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.js
52 lines (49 loc) · 1.54 KB
/
Util.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
module.exports.errorAlertContext = {
invalidField: {
title: "Empty field",
message: "Please enter all information and try again",
},
invalidUrl: {
title: "Unable to complete",
message:
"Please try again later. If this continues, please contact the developer",
},
invalidLogin: {
title: "Incorrect info",
message: "Your username or password is incorrect. Please try again",
},
invalidData: {
title: "No data",
message:
"We are unable to retrive the data. If this continues, please contact the developer",
},
};
module.exports.persistLocalData = (data, name) => {
const iFm = FileManager.iCloud();
const dataString = JSON.stringify(data);
iFm.writeString(`${iFm.documentsDirectory()}/${name}`, dataString);
};
module.exports.parseLocalData = name => {
const iFm = FileManager.iCloud();
const filePath = `${iFm.documentsDirectory()}/${name}`;
if (!iFm.fileExists(filePath)) {
return [];
} else {
const dataString = iFm.readString(`${filePath}`);
const data = JSON.parse(dataString);
return data;
}
};
module.exports.getDateRange = () => {
const today = new Date();
const curYear = today.getFullYear();
const curMonthIndex = today.getMonth();
const startDate = new Date();
startDate.setDate(1);
startDate.setHours(0, 0, 0, 0);
let endDate = new Date(curYear, curMonthIndex + 1, 0);
return {
startDate: startDate,
endDate: endDate,
};
};