Skip to content

Commit

Permalink
- Fix convertions on some data points.
Browse files Browse the repository at this point in the history
  • Loading branch information
RodoAgusSM committed Sep 5, 2023
1 parent 9e4bfeb commit e137054
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export const getLastDateCheckedAmerican = () => {
return date;
}

export const truncateToOneDecimal = (value: number) => {
return Math.floor(value * 10) / 10;
}

const firstLowerToLowercase = (string: string): string =>
string.replace(/(?:^|\s)\S/g, (a: string) => a.toLowerCase());

Expand Down
10 changes: 5 additions & 5 deletions src/utils/openWeatherMapInterfaceWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ClimateType, StorageKey, Units } from 'enums/index';
import { AirPollution, Weather } from 'interfaces/index';

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

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

const convertToWeather = (object: any, unit: Units) => {
return {
realFeel: Math.trunc(object.main.temp),
feelsLike: Math.trunc(object.main.feels_like),
realFeel: Math.round(object.main.temp),
feelsLike: Math.round(object.main.feels_like),
description: object.weather[0].description.charAt(0).toUpperCase() + object.weather[0].description.substring(1),
icon: "",
humidity: object.main.humidity,
pressure: object.main.pressure,
windSpeed: Units.Imperial === unit ? Math.trunc(object.wind.speed) : Math.trunc(object.wind.speed * 3.6),
windSpeed: Units.Imperial === unit ? truncateToOneDecimal(object.wind.speed) : truncateToOneDecimal(object.wind.speed * 3.6),
windDirection: getWindDirection(object),
visibility: Units.Imperial === unit ? Math.trunc(object.visibility / 1609.344) : object.visibility,
visibility: Units.Imperial === unit ? truncateToOneDecimal(object.visibility / 1609.344) : object.visibility,
sunrise: object.sys.sunrise,
sunset: object.sys.sunset,
lastTimeChecked: localStorage.getItem(StorageKey.Language) === 'en' ? getLastTimeChecked12HoursFormat() : getLastTimeChecked(),
Expand Down

0 comments on commit e137054

Please sign in to comment.