Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Test failing for toDate from string extension test (no-changelog) #5142

Merged
merged 2 commits into from
Jan 12, 2023

Conversation

valya
Copy link
Contributor

@valya valya commented Jan 12, 2023

No description provided.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jan 12, 2023
Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we create a general utility function like this, that can be also used in the app (if needed):

const getLocalISOString = (date: Date) => {
	const offset = date.getTimezoneOffset();
	const offsetAbs = Math.abs(offset);
	const isoString = new Date(date.getTime() - offset * 60 * 1000).toISOString();
	const hours = String(Math.floor(offsetAbs / 60)).padStart(2, '0');
	const minutes = String(offsetAbs % 60).padStart(2, '0');
	return `${isoString.slice(0, -1)}${offset > 0 ? '-' : '+'}${hours}:${minutes}`;
};

Then this test could be written as

test('.toDate() should work on a string', () => {
	const date = new Date(2022, 0, 3);
	expect(evaluate(`={{ "${getLocalISOString(date)}".toDate() }}`)).toEqual(date);
});

@valya
Copy link
Contributor Author

valya commented Jan 12, 2023

Happy to do that. Any idea where it'd live? If not, I'll just throw it in the test utils for workflow.

@netroy
Copy link
Member

netroy commented Jan 12, 2023

Happy to do that. Any idea where it'd live? If not, I'll just throw it in the test utils for workflow.

For now packages/workflow/test/ExpressionExtensions/Helpers.ts could be a good place to put this in. We can move it elsewhere when we need to.

Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍🏽

@netroy netroy changed the title fix: Test failing for toDate from string extension test fix: Test failing for toDate from string extension test (no-changelog) Jan 12, 2023
@netroy netroy merged commit 94be3b6 into master Jan 12, 2023
@netroy netroy deleted the fix-todate-string-test branch January 12, 2023 15:06
@n8n-assistant n8n-assistant bot added the Upcoming Release Will be part of the upcoming release label Jan 12, 2023
@janober
Copy link
Member

janober commented Jan 13, 2023

Got released with [email protected]

@janober janober removed the Upcoming Release Will be part of the upcoming release label Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants