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

isoDate doesn't recognize correct string #2419

Closed
mzl-md opened this issue Jul 28, 2020 · 4 comments
Closed

isoDate doesn't recognize correct string #2419

mzl-md opened this issue Jul 28, 2020 · 4 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@mzl-md
Copy link
Contributor

mzl-md commented Jul 28, 2020

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: v14.5.0
  • module version with issue: 17.1.1
  • last module version without issue: Unknown
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): aws-sdk
  • any other relevant information:

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

I'm validating an ISO string as seen in productive environment: 2019-01-22T07:16:46+01. While the regex from lib/common.js works fine, I still get a validation error when using isoDate().

// this fails:
console.log(Joi.string().isoDate().validate("2019-01-22T07:16:46+01"));
// but this works:
console.log(Joi.string().isoDate().validate("2019-01-22T07:16:46+01:00"));

What was the result you got?

{
  value: '2019-01-22T07:16:46+01',
  error: [Error [ValidationError]: "value" must be in iso format] {
    _original: '2019-01-22T07:16:46+01',
    details: [ [Object] ]
  }
}

What result did you expect?

{ value: '2019-01-22T06:16:46.000Z' }
@Marsup
Copy link
Collaborator

Marsup commented Jul 28, 2020

It's not a valid ISO 8601 date, the timezone needs both components, with or without the colon, but both.

@mzl-md
Copy link
Contributor Author

mzl-md commented Jul 28, 2020

I could not get the original specification but found some examples:

Wikipedia:
Positive UTC offsets describe a time zone east of UTC±00:00, where the civil time is ahead (or later) than UTC so the zone designator will look like "+02:00","+0200", or "+02".

Extended Date/Time Format:

Date and time with timeshift in hours (only)
Example 3 
‘1985-04-12T23:20:30-04’ refers to the date 1985 April 12th time of day 23:20:30 with time shift of 4 hours behind UTC.

But Chrome console:

new Date(`2019-01-22T07:16:46+01`)
Invalid Date

@Marsup
Copy link
Collaborator

Marsup commented Jul 28, 2020

As I don't really have $200 to spend on the specification, I guess we'll trust wikipedia 🙂 Then we should probably pad it with zeros to make it compatible with javascript's level of support.

@kanongil
Copy link
Contributor

Joi (and JS) only really supports the extended version with separators. With only two digits, it might not conform to this version. Anyway, this is working as expected, given the disclaimer in the docs:

Be aware that this operation uses javascript Date object, which does not support the full ISO format, so a few formats might not pass when using convert.

@hueniverse hueniverse self-assigned this Aug 5, 2020
@hueniverse hueniverse added the bug Bug or defect label Aug 5, 2020
@hueniverse hueniverse added this to the 17.2.0 milestone Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

4 participants