Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions src/components/Home/TodayListModal/TodayListModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
Label,
PreviousInfo,
} from './TodayListModal.styled';
import { formatCustomTime } from '../../../helpers/utils/dateUtils';
import { formatCustomTime, formatDate } from '../../../helpers/utils/dateUtils';

export const TodayListModal = ({
initialAmount,
Expand Down Expand Up @@ -87,31 +87,15 @@ export const TodayListModal = ({
// Якщо створюємо новий запис і час вибрано користувачем
const currentDate = new Date();
const [hours, minutes] = time.split(':');
// console.log('time: 1-й if', time); //14:40
currentDate.setHours(hours, minutes); // Wed Jan 10 2024 14:41:34 GMT+0200 (Восточная Европа, стандартное время)
// console.log('time: 1-й if', time); //18:57
currentDate.setHours(hours, minutes); // Fri Jan 12 2024 18:57:37 GMT+0200 (Восточная Европа, стандартное время)
// console.log(currentDate);
isoDate = currentDate.toISOString().slice(0, 16); // 2024-01-10T12:41
// console.log('Исходная дата: 1-й if', isoDate);

const currentDate2 = new Date(isoDate);

// Создаем новую дату на основе текущей
const newDate = new Date(currentDate2);
newDate.setHours(currentDate2.getHours() + 2);

const formattedNewDate =
newDate.getFullYear() +
'-' +
('0' + (newDate.getMonth() + 1)).slice(-2) +
'-' +
('0' + newDate.getDate()).slice(-2) +
'T' +
('0' + newDate.getHours()).slice(-2) +
':' +
('0' + newDate.getMinutes()).slice(-2);
// console.log('Исходная дата: финальный', isoDate);
// console.log('Новая дата: финальный', formattedNewDate);
isoDate = formattedNewDate;
isoDate = currentDate.toISOString(); // 2024-01-12T16:57:37.834Z
// console.log(isoDate);
const formattedDate = isoDate.replace(/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}).*/, '$1Z'); // 2024-01-12T16:57:37Z

// console.log('Новая дата: финальный', formattedDate);
isoDate = formattedDate;
}

const waterData = {
Expand Down Expand Up @@ -213,3 +197,33 @@ export const TodayListModal = ({
</BaseModalWindow>
);
};


// // Якщо створюємо новий запис і час вибрано користувачем
// const currentDate = new Date();
// const [hours, minutes] = time.split(':');
// // console.log('time: 1-й if', time); //14:40
// currentDate.setHours(hours, minutes); // Wed Jan 10 2024 14:41:34 GMT+0200 (Восточная Европа, стандартное время)
// // console.log(currentDate);
// isoDate = currentDate.toISOString().slice(0, 16); // 2024-01-10T12:41
// // console.log('Исходная дата: 1-й if', isoDate);

// const currentDate2 = new Date(isoDate);

// // Создаем новую дату на основе текущей
// const newDate = new Date(currentDate2);
// newDate.setHours(currentDate2.getHours() + 2);

// const formattedNewDate =
// newDate.getFullYear() +
// '-' +
// ('0' + (newDate.getMonth() + 1)).slice(-2) +
// '-' +
// ('0' + newDate.getDate()).slice(-2) +
// 'T' +
// ('0' + newDate.getHours()).slice(-2) +
// ':' +
// ('0' + newDate.getMinutes()).slice(-2);
// // console.log('Исходная дата: финальный', isoDate);
// // console.log('Новая дата: финальный', formattedNewDate);
// isoDate = formattedNewDate;