add getweekday fx

This commit is contained in:
madarsbiss 2021-09-22 19:15:02 +03:00
parent 92d22cd650
commit 2af4c0c5e2
2 changed files with 19 additions and 19 deletions

View File

@ -1,29 +1,12 @@
import { convertTime, timeToAMPM } from "../services/converters"; import { convertTime, timeToAMPM } from "../services/converters";
import { isPM } from "../services/utils"; import { getWeekDay, isPM } from "../services/utils";
import styles from "./DateAndTime.module.css"; import styles from "./DateAndTime.module.css";
const DateAndTime = ({ weatherData, systemUsed }) => { const DateAndTime = ({ weatherData, systemUsed }) => {
var weekday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
return ( return (
<h2 className={styles.title}> <h2 className={styles.title}>
{ {getWeekDay(weatherData)},{" "}
weekday[
new Date(
convertTime(weatherData.dt, weatherData.timezone).input
).getUTCDay()
]
}
,{" "}
{systemUsed == "metric" {systemUsed == "metric"
? parseInt( ? parseInt(
convertTime(weatherData.dt, weatherData.timezone)[0].split(":")[0] convertTime(weatherData.dt, weatherData.timezone)[0].split(":")[0]

View File

@ -1,5 +1,22 @@
import { convertTime, kmToM, mpsToMph, timeToAMPM } from "./converters"; import { convertTime, kmToM, mpsToMph, timeToAMPM } from "./converters";
export const getWeekDay = (weatherData) => {
const weekday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
return weekday[
new Date(
convertTime(weatherData.dt, weatherData.timezone).input
).getUTCDay()
];
};
export const isPM = (time) => { export const isPM = (time) => {
let hours = time.split(":")[0]; let hours = time.split(":")[0];
if (hours >= 12) { if (hours >= 12) {