Skip to content

Commit

Permalink
feat(dailyclean): remove client side timeZone shift
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-mesureux committed Nov 26, 2024
1 parent 0c6c08b commit 9f975fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
16 changes: 8 additions & 8 deletions api/web/src/FormConfigurationContainer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const fetch = (status =200, getCallback, postCallback) => async (url, config) =>
};
};

const getUTCHour = (hour) => hour -1;
const getLocalHour = (hour) => hour + 1;
const getUTCHour = (hour) => hour;
const getLocalHour = (hour) => hour;

describe(`FormConfigurationContainer`, () => {

Expand All @@ -34,19 +34,19 @@ describe(`FormConfigurationContainer`, () => {
const utils = render(<FormConfigurationContainer fetch={fetch(200, getCallback, postCallback)} getUTCHour={getUTCHour} getLocalHour={getLocalHour} setConfigurationState={setConfigurationState}/>);

await waitFor(() => expect(getCallback).toHaveBeenCalledTimes(1));

const title = screen.queryByText("Configuration");
expect(title).toBeTruthy();
expect(screen.getByRole('button')).toHaveAttribute('disabled');

const inputStart = utils.getByLabelText('Start hour');
fireEvent.change(inputStart, { target: { value: '3' } })
fireEvent.change(inputStart, { target: { value: '2' } })

const item = screen.queryByText("All days");
fireEvent.click(item);

const inputEnd = utils.getByLabelText('End hour');
fireEvent.change(inputEnd, { target: { value: '19' } });
fireEvent.change(inputEnd, { target: { value: '18' } });
expect(screen.getByRole('button')).not.toHaveAttribute('disabled');

const fireSumbit = () => {
Expand Down Expand Up @@ -74,7 +74,7 @@ describe(`FormConfigurationContainer`, () => {

expect(screen.getByRole('alert')).toHaveTextContent("SuccessSave done succesfully.");
expect(screen.getByRole('button')).toHaveAttribute('disabled');

});

it(`error message should display with success`, async () => {
Expand All @@ -100,11 +100,11 @@ describe(`FormConfigurationContainer`, () => {
fireEvent.change(inputEnd, {target: {value: '20'}});
inputEnd.blur();
});

const endErrorMessage = screen.getByText(messageEndDateShouldBeAfterStartDate);
expect(endErrorMessage).toBeTruthy();

expect(screen.getByRole('button')).toHaveAttribute('disabled');
});

});
4 changes: 2 additions & 2 deletions api/web/src/FormConfigurationContainer.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default {
component: Header,
};

const getUTCHour = (hour) => hour -1;
const getLocalHour = (hour) => hour + 1;
const getUTCHour = (hour) => hour;
const getLocalHour = (hour) => hour;

const fetch = (status =200) => async (url, config) => {
if(config.method === "POST") {
Expand Down
4 changes: 2 additions & 2 deletions api/web/src/FormStateContainer.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default {
component: Header,
};

const getUTCHour = (hour) => hour -1;
const getLocalHour = (hour) => hour + 1;
const getUTCHour = (hour) => hour;
const getLocalHour = (hour) => hour;

const fetch = (status =200) => async (url, config) => {
if(config.method === "POST") {
Expand Down
12 changes: 3 additions & 9 deletions api/web/src/date.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@


const timezoneOffsetHour = () => {
const x = new Date();
return x.getTimezoneOffset() / 60;
}

export const getLocalHour=(hourUTC) => {
const date = new Date();
date.setHours(hourUTC - timezoneOffsetHour());
date.setHours(hourUTC);
const hour = date.getHours();
return hour;
}

export const getUTCHour=(hourLocal) => {
console.log(hourLocal)
const date = new Date();
date.setHours(hourLocal + timezoneOffsetHour());
date.setHours(hourLocal);
return date.getHours()
}

0 comments on commit 9f975fc

Please sign in to comment.