og-tools 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +22 -18
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -84,23 +84,27 @@ function scoreRatio(calificacion) {
|
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
function DaysBetween(
|
|
88
|
-
|
|
89
|
-
if(parseInt(timestamp1) === 0 || parseInt(timestamp1) === 0) return 0;
|
|
90
|
-
const ms1 = parseInt(timestamp1) * 1000;
|
|
91
|
-
const ms2 = parseInt(timestamp2) * 1000;
|
|
87
|
+
function DaysBetween(ts1, ts2) {
|
|
88
|
+
if (ts1 == null || ts2 == null) return 0;
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
const n1 = Number(ts1);
|
|
91
|
+
const n2 = Number(ts2);
|
|
95
92
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
if (isNaN(n1) || isNaN(n2)) return 0;
|
|
94
|
+
if (n1 === 0 || n2 === 0) return 0;
|
|
95
|
+
|
|
96
|
+
const diferencia = Math.abs(n2 - n1);
|
|
97
|
+
return Math.floor(diferencia / (60 * 60 * 24));
|
|
100
98
|
}
|
|
101
99
|
|
|
102
|
-
function Distance(
|
|
100
|
+
function Distance(ts1, ts2, unit = 'km') {
|
|
103
101
|
try {
|
|
102
|
+
if (ts1 == null || ts2 == null) return 0;
|
|
103
|
+
|
|
104
|
+
const n1 = Number(ts1);
|
|
105
|
+
const n2 = Number(ts2);
|
|
106
|
+
|
|
107
|
+
if (isNaN(n1) || isNaN(n2)) return 0;
|
|
104
108
|
const RADIO_TIERRA = { km: 6371, mi: 3958.8, m: 6371000 };
|
|
105
109
|
|
|
106
110
|
if (!RADIO_TIERRA[unit]) {
|
|
@@ -109,13 +113,13 @@ function Distance(location1, location2, unit = 'km') {
|
|
|
109
113
|
|
|
110
114
|
const toRad = (deg) => (deg * Math.PI) / 180;
|
|
111
115
|
|
|
112
|
-
const dLat = toRad(
|
|
113
|
-
const dLon = toRad(
|
|
116
|
+
const dLat = toRad(ts2.lat - ts1.lat);
|
|
117
|
+
const dLon = toRad(ts2.lon - ts1.lon);
|
|
114
118
|
|
|
115
119
|
const a =
|
|
116
120
|
Math.sin(dLat / 2) ** 2 +
|
|
117
|
-
Math.cos(toRad(
|
|
118
|
-
Math.cos(toRad(
|
|
121
|
+
Math.cos(toRad(ts1.lat)) *
|
|
122
|
+
Math.cos(toRad(ts2.lat)) *
|
|
119
123
|
Math.sin(dLon / 2) ** 2;
|
|
120
124
|
|
|
121
125
|
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
@@ -130,10 +134,10 @@ function Distance(location1, location2, unit = 'km') {
|
|
|
130
134
|
|
|
131
135
|
|
|
132
136
|
module.exports = {
|
|
133
|
-
comillas,
|
|
137
|
+
comillas, // Reemplaza ' por spaces en string
|
|
134
138
|
correlateTournaments,
|
|
135
139
|
singleTournamentCorrelate,
|
|
136
|
-
scoreRatio,
|
|
140
|
+
scoreRatio, // Recibe una calificacion (6.62) y lo convierte en patrón emoji 🟡
|
|
137
141
|
Distance, // Calcula la distancia entre dos ubicaciones
|
|
138
142
|
DaysBetween, // Calcula el numero de días entre dos fechas
|
|
139
143
|
};
|