Skip to content

Commit e137054

Browse files
committed
- Fix convertions on some data points.
1 parent 9e4bfeb commit e137054

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/utils/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export const getLastDateCheckedAmerican = () => {
5959
return date;
6060
}
6161

62+
export const truncateToOneDecimal = (value: number) => {
63+
return Math.floor(value * 10) / 10;
64+
}
65+
6266
const firstLowerToLowercase = (string: string): string =>
6367
string.replace(/(?:^|\s)\S/g, (a: string) => a.toLowerCase());
6468

src/utils/openWeatherMapInterfaceWrapper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ClimateType, StorageKey, Units } from 'enums/index';
22
import { AirPollution, Weather } from 'interfaces/index';
33

4-
import { getLastDateChecked, getLastDateCheckedAmerican, getLastTimeChecked, getLastTimeChecked12HoursFormat, getWindDirection } from './helpers';
4+
import { getLastDateChecked, getLastDateCheckedAmerican, getLastTimeChecked, getLastTimeChecked12HoursFormat, getWindDirection, truncateToOneDecimal } from './helpers';
55

66
export const convertOpenWeatherMapResponseToInterface = (climateType: ClimateType, unit: Units, object: any) => {
77
switch (climateType) {
@@ -16,15 +16,15 @@ export const convertOpenWeatherMapResponseToInterface = (climateType: ClimateTyp
1616

1717
const convertToWeather = (object: any, unit: Units) => {
1818
return {
19-
realFeel: Math.trunc(object.main.temp),
20-
feelsLike: Math.trunc(object.main.feels_like),
19+
realFeel: Math.round(object.main.temp),
20+
feelsLike: Math.round(object.main.feels_like),
2121
description: object.weather[0].description.charAt(0).toUpperCase() + object.weather[0].description.substring(1),
2222
icon: "",
2323
humidity: object.main.humidity,
2424
pressure: object.main.pressure,
25-
windSpeed: Units.Imperial === unit ? Math.trunc(object.wind.speed) : Math.trunc(object.wind.speed * 3.6),
25+
windSpeed: Units.Imperial === unit ? truncateToOneDecimal(object.wind.speed) : truncateToOneDecimal(object.wind.speed * 3.6),
2626
windDirection: getWindDirection(object),
27-
visibility: Units.Imperial === unit ? Math.trunc(object.visibility / 1609.344) : object.visibility,
27+
visibility: Units.Imperial === unit ? truncateToOneDecimal(object.visibility / 1609.344) : object.visibility,
2828
sunrise: object.sys.sunrise,
2929
sunset: object.sys.sunset,
3030
lastTimeChecked: localStorage.getItem(StorageKey.Language) === 'en' ? getLastTimeChecked12HoursFormat() : getLastTimeChecked(),

0 commit comments

Comments
 (0)