joi-date icon indicating copy to clipboard operation
joi-date copied to clipboard

UTC parsing mode is ignored when a time part is included in the string

Open ighunter opened this issue 1 year ago • 0 comments

Runtime

node.js

Runtime version

18.17.1

Module version

2.1.0

Last module version without issue

No response

Used with

standalone

Any other relevant information

#9 added the .utc() option to parse a date string as UTC, regardless of the local machine's timezone. This has been present since module version 1.2.0, according to the changelog.

What are you trying to achieve or the steps to reproduce?

I'm trying to parse a string that has more than just the date, but still have .utc() treat it as UTC, regardless of the machine's timezone.

const schema = Joi.date().utc().format('iso');

schema.validate('2025-01-01');
schema.validate('2025-01-01T00:00:00');

What was the result you got?

2025-01-01T00:00:00.000Z 2024-12-31T22:00:00.000Z (my local timezone is UTC+2)

What result did you expect?

2025-01-01T00:00:00.000Z 2025-01-01T00:00:00.000Z (since I expect .utc() to mean it parses as if Z were included at the end of the input string)

ighunter avatar Jan 27 '25 10:01 ighunter