diff --git a/src/components/Calendar/calendarHelper.js b/src/components/Calendar/calendarHelper.js index 73afcb39..3ee0de81 100644 --- a/src/components/Calendar/calendarHelper.js +++ b/src/components/Calendar/calendarHelper.js @@ -1,19 +1,23 @@ -import moment from 'moment'; -import 'moment/locale/ru'; +import moment from "moment"; +import "moment/locale/ru"; export function calendarHelper(value) { - const startDay = value.clone().startOf('month').startOf('week').startOf('day'); - const endDay = value.clone().endOf('month').endOf('week'); + const startDay = value + .clone() + .startOf("month") + .startOf("week") + .startOf("day"); + const endDay = value.clone().endOf("month").endOf("week"); - const day = startDay.clone().subtract(1, 'day'); + const day = startDay.clone().subtract(1, "day"); const calendar = []; - while (day.isBefore(endDay, 'day')) { + while (day.isBefore(endDay, "day")) { calendar.push( Array(1) .fill(0) - .map(() => day.add(1, 'day').clone()) + .map(() => day.add(1, "day").clone()) ); } @@ -21,48 +25,84 @@ export function calendarHelper(value) { } export function getReports(value) { - const startDay = value.clone().startOf('month').startOf('week').startOf('day'); - const reportsStart = `${new Date(startDay).getFullYear()}-${new Date(startDay).getMonth() + 1}-${new Date(startDay).getDate()}` - const endDay = value.clone().endOf('month').endOf('week'); - const reportsEnd = `${new Date(endDay).getFullYear()}-${new Date(endDay).getMonth() + 1}-${new Date(endDay).getDate()}` - const getReports = `fromDate=${reportsStart}&toDate=${reportsEnd}` + const startDay = value + .clone() + .startOf("month") + .startOf("week") + .startOf("day"); + const reportsStart = `${new Date(startDay).getFullYear()}-${ + new Date(startDay).getMonth() + 1 + }-${new Date(startDay).getDate()}`; + const endDay = value.clone().endOf("month").endOf("week"); + const reportsEnd = `${new Date(endDay).getFullYear()}-${ + new Date(endDay).getMonth() + 1 + }-${new Date(endDay).getDate()}`; + const getReports = `fromDate=${reportsStart}&toDate=${reportsEnd}`; return getReports; } export function getCreatedDate(day) { if (day) { - return `${new Date(day).getFullYear()}-${new Date(day).getMonth() + 1}-${new Date(day).getDate()}` + return `${new Date(day).getFullYear()}-${correctDay( + new Date(day).getMonth() + 1 + )}-${correctDay(new Date(day).getDate())}`; } else { const date = new Date(); - const dd = String(date.getDate()).padStart(2, '0'); - const mm = String(date.getMonth() + 1).padStart(2, '0'); + const dd = String(date.getDate()).padStart(2, "0"); + const mm = String(date.getMonth() + 1).padStart(2, "0"); const yyyy = date.getFullYear(); - return `${yyyy}-${mm}-${dd}` + return `${yyyy}-${mm}-${dd}`; } } +export function correctDay(day) { + if (day < 10) { + return `0${day}`; + } + return day; +} + export function currentMonth() { - const currentMonth = moment().format('MMMM'); + const currentMonth = moment().format("MMMM"); return currentMonth.charAt(0).toUpperCase() + currentMonth.slice(1); } export function currentMonthAndDay(day) { - return day.format('D MMMM'); + return day.format("D MMMM"); } export function getCorrectDate(day) { - const months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'] - return `${new Date(day).getDate()} ${months[new Date(day).getMonth()]} ${new Date(day).getFullYear()} года` -}; + const months = [ + "января", + "февраля", + "марта", + "апреля", + "мая", + "июня", + "июля", + "августа", + "сентября", + "октября", + "ноября", + "декабря", + ]; + return `${new Date(day).getDate()} ${ + months[new Date(day).getMonth()] + } ${new Date(day).getFullYear()} года`; +} export function currentMonthAndDayReportPage() { - return moment().format('D MMMM'); + return moment().format("D MMMM"); } export function hourOfNum(number) { - const hours = [' час', ' часа', ' часов']; + const hours = [" час", " часа", " часов"]; const cases = [2, 0, 1, 1, 1, 2]; - return hours[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]]; + return hours[ + number % 100 > 4 && number % 100 < 20 + ? 2 + : cases[number % 10 < 5 ? number % 10 : 5] + ]; } diff --git a/src/components/ShortReport/ShortReport.jsx b/src/components/ShortReport/ShortReport.jsx index 8aafcc65..d8bcc3fd 100644 --- a/src/components/ShortReport/ShortReport.jsx +++ b/src/components/ShortReport/ShortReport.jsx @@ -27,7 +27,7 @@ export const ShortReport = ({}) => { const [tomorrowTask, setTomorrowTask] = useState([]); const [totalHours, setTotalHours] = useState(0); const [loader, setLoader] = useState(false); - const [dateTest, setDateTest] = useState(""); + const [dateCreate, setDateCreate] = useState(""); function getReportFromDate(day) { setLoader(true); @@ -41,7 +41,7 @@ export const ShortReport = ({}) => { ).then((res) => { let spendTime = 0; for (const item of res) { - setDateTest(item.created_at); + setDateCreate(item.created_at); if (item.difficulties) { setDifficulties((prevArray) => [...prevArray, item.difficulties]); } @@ -78,7 +78,9 @@ export const ShortReport = ({}) => {
Вами потрачено на работу :{" "} @@ -114,30 +121,36 @@ export const ViewReport = () => { {totalHours} {hourOfNum(totalHours)}
- {/*122 часа из 160
*/}{getCorrectDate(reportDay)}
-{getCorrectDate(dateReport.id)}
+ +