-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
36 lines (29 loc) · 1.12 KB
/
functions.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
function fetchData() {
return fetch('https://cdn.jsdelivr.net/gh/SamadiPour/rial-exchange-rates-archive@data/jalali_all.min.json')
.then(response => response.json())
.then(data => {
this.data = data;
})
.catch(error => {
console.error('Error fetching data:', error);
});
};
function calculateSum(value, year, month, day) {
const rawData = this.data;
usdOnDate = rawData[CreateDate(year, month, day)]["azadi1"]["sell"];
const keys = Object.keys(rawData);
const lastKey = keys[keys.length - 1];
const lastValue = rawData[lastKey];
latestUsdValue = lastValue["azadi1"]["sell"];
usdAtDate = value / usdOnDate;
rialAtLastDate = usdAtDate * latestUsdValue;
const rounded = Math.round(rialAtLastDate * 100) / 100;
return { value: rounded.toLocaleString(), lastUsdValue: latestUsdValue.toLocaleString(), usdValueOnDate: usdOnDate.toLocaleString() }
function CreateDate(year, month, day) {
date = `${year}/${month.padStart(2, '0')}/${day.padStart(2, '0')}`;
return date;
}
};
function showData() {
return this.data;
}